Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/camel-undertow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>jetty-http2-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -168,9 +169,15 @@ public void echo() throws Exception {
wsclient1.connect();

wsclient1.sendTextMessage("Test1");
wsclient1.sendTextMessage("Test2");
// Wait for the first echo before sending the next message to avoid
// IllegalStateException from JDK WebSocket when a send is still pending.
// Poll using size() to avoid iterating the non-thread-safe received list.
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient1.getReceived().size() >= 1);

assertTrue(wsclient1.await(10));
wsclient1.sendTextMessage("Test2");
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient1.getReceived().size() >= 2);

assertEquals(Arrays.asList("Test1", "Test2"), wsclient1.getReceived(String.class));

Expand All @@ -187,8 +194,9 @@ public void echoMulti() throws Exception {
wsclient1.sendTextMessage("Gambas");
wsclient2.sendTextMessage("Calamares");

assertTrue(wsclient1.await(10));
assertTrue(wsclient2.await(10));
// Poll using size() to avoid iterating the non-thread-safe received list
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient1.getReceived().size() >= 1 && wsclient2.getReceived().size() >= 1);

assertEquals(List.of("Gambas"), wsclient1.getReceived(String.class));
assertEquals(List.of("Calamares"), wsclient2.getReceived(String.class));
Expand All @@ -207,12 +215,12 @@ public void sendToAll() throws Exception {
wsclient1.sendTextMessage("Gambas");
wsclient2.sendTextMessage("Calamares");

assertTrue(wsclient1.await(10));
assertTrue(wsclient2.await(10));
// Poll using size() to avoid iterating the non-thread-safe received list
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient1.getReceived().size() >= 2 && wsclient2.getReceived().size() >= 2);

List<String> received1 = wsclient1.getReceived(String.class);
assertEquals(2, received1.size());

assertTrue(received1.contains("Gambas"));
assertTrue(received1.contains("Calamares"));

Expand Down Expand Up @@ -292,26 +300,33 @@ public void connectionKeyList() throws Exception {
wsclient2.connect();
wsclient3.connect();

wsclient1.await(10);
// Poll using size() to avoid iterating the non-thread-safe received list
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient1.getReceived().size() >= 1);
final String connectionKey1 = assertConnected(wsclient1);
assertNotNull(connectionKey1);
wsclient2.await(10);
await().atMost(10, TimeUnit.SECONDS)
Comment on lines +304 to +308

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

.until(() -> wsclient2.getReceived().size() >= 1);
final String connectionKey2 = assertConnected(wsclient2);
wsclient3.await(10);
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient3.getReceived().size() >= 1);
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

wsclient2.await(10);
// 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)
.until(() -> wsclient2.getReceived().size() >= 1 && wsclient3.getReceived().size() >= 1);
assertEquals(broadcastMsg, wsclient2.getReceived(String.class).get(0));
wsclient3.await(10);
assertEquals(broadcastMsg, wsclient3.getReceived(String.class).get(0));
wsclient1.await(10);

wsclient1.sendTextMessage("private"); // this one should go to wsclient1 only
await().atMost(10, TimeUnit.SECONDS)
.until(() -> wsclient1.getReceived().size() >= 1);
assertEquals("private", wsclient1.getReceived(String.class).get(0));

wsclient1.close();
Expand Down