Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,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")));

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. 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.


assertEquals(Arrays.asList("Test1", "Test2"), wsclient1.getReceived(String.class));
wsclient1.sendTextMessage("Test2");
await().atMost(10, TimeUnit.SECONDS)
.untilAsserted(
() -> assertEquals(Arrays.asList("Test1", "Test2"), wsclient1.getReceived(String.class)));

wsclient1.close();
}
Expand All @@ -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));
});

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. 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.


wsclient1.close();
wsclient2.close();
Expand All @@ -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"));

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() >= 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.


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

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

List<String> received2 = wsclient2.getReceived(String.class);
assertEquals(2, received2.size());
assertTrue(received2.contains("Gambas"));
assertTrue(received2.contains("Calamares"));
List<String> received2 = wsclient2.getReceived(String.class);
assertEquals(2, received2.size());
assertTrue(received2.contains("Gambas"));
assertTrue(received2.contains("Calamares"));
});

wsclient1.close();
wsclient2.close();
Expand Down Expand Up @@ -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)
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.

.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));
});

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. 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.


wsclient2.await(10);
assertEquals(broadcastMsg, wsclient2.getReceived(String.class).get(0));
wsclient3.await(10);
assertEquals(broadcastMsg, wsclient3.getReceived(String.class).get(0));
wsclient1.await(10);
assertEquals("private", wsclient1.getReceived(String.class).get(0));
wsclient1.sendTextMessage("private"); // this one should go to wsclient1 only
await().atMost(10, TimeUnit.SECONDS)
.untilAsserted(
() -> assertEquals("private", wsclient1.getReceived(String.class).get(0)));

wsclient1.close();
wsclient2.close();
Expand Down