This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 3a770bd86ca3 CAMEL-27643: camel-box - fix flaky BoxEventsConsumerTest
(#31017)
3a770bd86ca3 is described below
commit 3a770bd86ca3e72a1592fb822a97f68ed3c5dbf0
Author: Aurélien Pupier <[email protected]>
AuthorDate: Sat Nov 28 09:35:37 2026 +0100
CAMEL-27643: camel-box - fix flaky BoxEventsConsumerTest (#31017)
The fake Box connection of the test threw the simulated network error
at once, on the first request for events. That request is sent by the
poller thread of the Box SDK EventStream, which EventStream.start()
starts before it sets started = true. When the poller thread failed
before the flag was set, EventStream.notifyException() could not stop
the stream (it throws IllegalStateException when not started) and never
called onException of the listener. BoxConsumer was then not notified,
did not schedule a restart, and the mock endpoint received fewer
messages than expected (listensAgainWhenTheEventStreamFails and
continuesAfterTheLastEventsReceived).
The simulated network error now happens after a delay, as a real one
does, so the stream is started when it fails. The wait of the long poll
and of the network error share a pause() helper.
Introduced by CAMEL-27210.
_IBM Bob (AI-generated) on behalf of @apupier_
Co-authored-by: IBM Bob <[email protected]>
---
.../camel/component/box/BoxEventsConsumerTest.java | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git
a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsConsumerTest.java
b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsConsumerTest.java
index 73998cffa6ef..b1460c4c539b 100644
---
a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsConsumerTest.java
+++
b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxEventsConsumerTest.java
@@ -59,6 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class BoxEventsConsumerTest {
private static final String REALTIME_URL =
"https://realtime.box.test/subscribe?channel=1";
+ private static final long NETWORK_ERROR_DELAY = 500;
/** The events of the account, in order: the stream position is the index
in this list. */
private final List<String> events = Collections.synchronizedList(new
ArrayList<>());
@@ -192,15 +193,15 @@ class BoxEventsConsumerTest {
return json(request, new JsonObject().add("message",
"new_change"));
}
// a long poll waits for a change: answer after a while that there
was none
- try {
- new CountDownLatch(1).await(50, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
+ pause(50);
return json(request, new JsonObject().add("message", "reconnect"));
}
eventRequestPositions.add(String.valueOf(position));
if (failingEventRequests.getAndUpdate(n -> Math.max(0, n - 1)) > 0) {
+ // A network error takes a while to happen. The Box SDK
EventStream marks itself as started after it has
+ // started its poller thread: a failure that happens before, as it
does when the connection answers at
+ // once, cannot stop the stream and is never notified to the
listener.
+ pause(NETWORK_ERROR_DELAY);
throw new BoxAPIException(
"Couldn't connect to the Box API due to a network error.
Request\n" + url,
new IOException("Connection refused"));
@@ -218,6 +219,14 @@ class BoxEventsConsumerTest {
.add("next_stream_position", next).add("entries", entries));
}
+ private static void pause(long millis) {
+ try {
+ new CountDownLatch(1).await(millis, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
private static BoxJSONResponse json(BoxAPIRequest request, JsonObject
body) {
return new BoxJSONResponse(200, request.getMethod(),
request.getUrl().toString(), Map.of(), body);
}