gnodet commented on code in PR #24421:
URL: https://github.com/apache/camel/pull/24421#discussion_r3526839192
##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/ws/UndertowWsConsumerRouteTest.java:
##########
@@ -168,11 +169,15 @@ public void echo() throws Exception {
wsclient1.connect();
wsclient1.sendTextMessage("Test1");
- wsclient1.sendTextMessage("Test2");
-
- assertTrue(wsclient1.await(10));
+ // Wait for the first echo before sending the next message to avoid
+ // IllegalStateException from JDK WebSocket when a send is still
pending
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() ->
assertTrue(wsclient1.getReceived(String.class).contains("Test1")));
Review Comment:
Addressed in commit 01d5f72. Changed the Awaitility polling from
`untilAsserted()` with `getReceived(String.class).contains()` (which iterates
via for-each/iterator) to `until(() -> getReceived().size() >= 1)` which uses
index-based `size()` — no iterator, safe under concurrent modification. The
`getReceived(String.class)` call is now only made after the size gate confirms
all expected messages have arrived and the listener thread is done mutating the
list.
##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/ws/UndertowWsConsumerRouteTest.java:
##########
@@ -187,11 +192,11 @@ public void echoMulti() throws Exception {
wsclient1.sendTextMessage("Gambas");
wsclient2.sendTextMessage("Calamares");
- assertTrue(wsclient1.await(10));
- assertTrue(wsclient2.await(10));
-
- assertEquals(List.of("Gambas"), wsclient1.getReceived(String.class));
- assertEquals(List.of("Calamares"),
wsclient2.getReceived(String.class));
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> {
+ assertEquals(List.of("Gambas"),
wsclient1.getReceived(String.class));
+ assertEquals(List.of("Calamares"),
wsclient2.getReceived(String.class));
+ });
Review Comment:
Addressed in commit 01d5f72. Replaced `untilAsserted()` with iterator-based
`getReceived(String.class)` by `until(() -> getReceived().size() >= 1)` for
both clients. The `getReceived(String.class)` assertions now execute only after
the size gate confirms delivery is complete — no concurrent iteration.
##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/ws/UndertowWsConsumerRouteTest.java:
##########
@@ -207,19 +212,18 @@ public void sendToAll() throws Exception {
wsclient1.sendTextMessage("Gambas");
wsclient2.sendTextMessage("Calamares");
- assertTrue(wsclient1.await(10));
- assertTrue(wsclient2.await(10));
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> {
+ List<String> received1 =
wsclient1.getReceived(String.class);
+ assertEquals(2, received1.size());
+ assertTrue(received1.contains("Gambas"));
+ assertTrue(received1.contains("Calamares"));
Review Comment:
Addressed in commit 01d5f72. The Awaitility polling now uses `until(() ->
getReceived().size() >= 2)` for both clients (no iterator). The
`getReceived(String.class)` list and `contains()` checks are only called after
the size gate confirms both messages have arrived, so no concurrent
modification risk.
##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/ws/UndertowWsConsumerRouteTest.java:
##########
@@ -292,27 +296,34 @@ public void connectionKeyList() throws Exception {
wsclient2.connect();
wsclient3.connect();
- wsclient1.await(10);
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertConnected(wsclient1));
final String connectionKey1 = assertConnected(wsclient1);
assertNotNull(connectionKey1);
- wsclient2.await(10);
+ await().atMost(10, TimeUnit.SECONDS)
Review Comment:
Addressed in commit 01d5f72. The Awaitility polling now uses `until(() ->
getReceived().size() >= 1)` — no iterator. `assertConnected()` (which calls
`getReceived(String.class).get(0)`) is only invoked after the size gate
confirms the CONNECTED message has been received, so the listener thread is
done mutating the list at that point.
##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/ws/UndertowWsConsumerRouteTest.java:
##########
@@ -292,27 +296,34 @@ public void connectionKeyList() throws Exception {
wsclient2.connect();
wsclient3.connect();
- wsclient1.await(10);
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertConnected(wsclient1));
final String connectionKey1 = assertConnected(wsclient1);
assertNotNull(connectionKey1);
- wsclient2.await(10);
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertConnected(wsclient2));
final String connectionKey2 = assertConnected(wsclient2);
- wsclient3.await(10);
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertConnected(wsclient3));
final String connectionKey3 = assertConnected(wsclient3);
wsclient1.reset(1);
wsclient2.reset(1);
wsclient3.reset(1);
final String broadcastMsg = BROADCAST_MESSAGE_PREFIX + connectionKey2
+ " " + connectionKey3;
wsclient1.sendTextMessage(broadcastMsg); // this one should go to
wsclient2 and wsclient3
- wsclient1.sendTextMessage("private"); // this one should go to
wsclient1 only
+ // Wait for broadcast delivery before sending the next message to avoid
+ // IllegalStateException from JDK WebSocket when a send is still
pending
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> {
+ assertEquals(broadcastMsg,
wsclient2.getReceived(String.class).get(0));
+ assertEquals(broadcastMsg,
wsclient3.getReceived(String.class).get(0));
+ });
Review Comment:
Addressed in commit 01d5f72. Both the broadcast and private message waits
now use `until(() -> getReceived().size() >= 1)` for polling. The
`getReceived(String.class).get(0)` content assertion is only made after the
size gate confirms delivery — safe from both `ConcurrentModificationException`
and `IndexOutOfBoundsException`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]