You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2026/07/12 06:34:09 UTC

(camel) branch main updated: CAMEL-24005: Fix flaky JmsTransactedDeadLetterChannel*RollbackOnExceptionIT (#24611)

This is an automated email from the ASF dual-hosted git repository.

gnodet 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 af2f28e0f847 CAMEL-24005: Fix flaky JmsTransactedDeadLetterChannel*RollbackOnExceptionIT (#24611)
af2f28e0f847 is described below

commit af2f28e0f8479e3d37aaa1cbca4b0e308ade02a2
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sun Jul 12 08:34:02 2026 +0200

    CAMEL-24005: Fix flaky JmsTransactedDeadLetterChannel*RollbackOnExceptionIT (#24611)
    
    CAMEL-24005: Fix flaky JmsTransactedDeadLetterChannel*RollbackOnExceptionIT
    
    Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
 ...nsactedDeadLetterChannelHandlerRollbackOnExceptionIT.java | 12 +++++++++++-
 ...ctedDeadLetterChannelNotHandlerRollbackOnExceptionIT.java | 12 +++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionIT.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionIT.java
index ee99afecb2a8..362b17e04628 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionIT.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.jms.integration.tx;
 
+import java.util.concurrent.TimeUnit;
+
 import jakarta.jms.ConnectionFactory;
 
 import org.apache.activemq.artemis.api.core.SimpleString;
@@ -23,6 +25,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Handler;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.jms.JmsComponent;
 import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper;
@@ -36,6 +39,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentTransacted;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @Tags({ @Tag("not-parallel"), @Tag("transaction") })
 public class JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionIT extends CamelTestSupport {
@@ -86,11 +90,17 @@ public class JmsTransactedDeadLetterChannelHandlerRollbackOnExceptionIT extends
 
     @Test
     public void shouldNotLoseMessagesOnExceptionInErrorHandler() {
+        // wait for the exchange to be fully done (processed + transaction committed/rolled back)
+        // before checking the DLQ, to avoid a race between route processing and the assertion
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+
         template.sendBody(testingEndpoint, "Hello World");
 
+        assertTrue(notify.matches(30, TimeUnit.SECONDS), "Exchange should be done");
+
         // as we handle new exception, then the exception is ignored
         // and causes the transaction to commit, so there is no message in the DLQ queue
-        Object dlqBody = consumer.receiveBody("activemq:" + DLQ_NAME, 10000);
+        Object dlqBody = consumer.receiveBody("activemq:" + DLQ_NAME, 2000);
         assertNull(dlqBody, "Should not rollback the transaction");
     }
 
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelNotHandlerRollbackOnExceptionIT.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelNotHandlerRollbackOnExceptionIT.java
index e48d5b895534..9124193b5f06 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelNotHandlerRollbackOnExceptionIT.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/tx/JmsTransactedDeadLetterChannelNotHandlerRollbackOnExceptionIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.jms.integration.tx;
 
+import java.util.concurrent.TimeUnit;
+
 import jakarta.jms.ConnectionFactory;
 
 import org.apache.activemq.artemis.api.core.QueueConfiguration;
@@ -25,6 +27,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Handler;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.jms.JmsComponent;
 import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper;
@@ -38,6 +41,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentTransacted;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @Tags({ @Tag("not-parallel"), @Tag("transaction") })
 public class JmsTransactedDeadLetterChannelNotHandlerRollbackOnExceptionIT extends CamelTestSupport {
@@ -91,11 +95,17 @@ public class JmsTransactedDeadLetterChannelNotHandlerRollbackOnExceptionIT exten
 
     @Test
     public void shouldNotLoseMessagesOnExceptionInErrorHandler() {
+        // wait for the exchange to be fully done (processed + transaction rolled back)
+        // before checking the DLQ, to avoid a race between route processing and the assertion
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+
         template.sendBody(testingEndpoint, "Hello World");
 
+        assertTrue(notify.matches(30, TimeUnit.SECONDS), "Exchange should be done");
+
         // as we do not handle new exception, then the exception propagates back
         // and causes the transaction to rollback, and we can find the message in the DLQ
-        Object dlqBody = consumer.receiveBody("activemq:" + DLQ_NAME, 30000);
+        Object dlqBody = consumer.receiveBody("activemq:" + DLQ_NAME, 10000);
         assertEquals("Hello World", dlqBody);
     }