This is an automated email from the ASF dual-hosted git repository.
apupier 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 d91f5453cf18 CAMEL-26368: Fix flaky JettyJmsShutdownTest
d91f5453cf18 is described below
commit d91f5453cf18ac77fd3182df91347dfd8f819c46
Author: Aurélien Pupier <[email protected]>
AuthorDate: Wed Nov 18 10:44:10 2026 +0100
CAMEL-26368: Fix flaky JettyJmsShutdownTest
The test slept for 1 second before stopping the CamelContext, assuming
all three HTTP requests had reached the JMS consumer route by then. On
a slow machine this is not guaranteed, and the shutdown could happen
while requests were still being processed, leading to HTTP 500 errors.
Replace the Thread.sleep with a NotifyBuilder waiting until the consumer
route has received the three messages, and give that route a specific id.
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java | 8 +++++++-
.../org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git
a/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
b/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
index b0ee747ae494..447fe4b306b5 100644
---
a/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
+++
b/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.itest.utils.extensions.JmsServiceExtension;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.spring.junit6.CamelSpringTest;
@@ -31,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
@CamelSpringTest
@ContextConfiguration
@@ -59,11 +61,15 @@ public class JettyJmsShutdownTest {
@Test
void testShutdown() throws Exception {
+ // wait until all 3 messages are in progress in the consumer route
+ NotifyBuilder notify
+ = new
NotifyBuilder(camelContext).fromRoute("JettyJmsShutdownTest-consumer").whenReceived(3).create();
+
Future<String> reply1 = template.asyncRequestBody(URL, "World",
String.class);
Future<String> reply2 = template.asyncRequestBody(URL, "Camel",
String.class);
Future<String> reply3 = template.asyncRequestBody(URL, "Tiger",
String.class);
- Thread.sleep(1000);
+ assertTrue(notify.matches(30, TimeUnit.SECONDS), "All messages should
be received by the consumer route");
// shutdown while in progress
camelContext.stop();
diff --git
a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
b/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
index c87cdb8ef150..ca894402082c 100644
---
a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
+++
b/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
@@ -39,7 +39,7 @@
</route>
<!-- also defer this as we defer the other route -->
- <route shutdownRoute="Defer">
+ <route id="JettyJmsShutdownTest-consumer" shutdownRoute="Defer">
<from uri="jms:queue:JettyJmsShutdownTest?concurrentConsumers=5"/>
<delay>
<constant>5000</constant>