This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch CAMEL-23194-fix-blocked-jms-tests in repository https://gitbox.apache.org/repos/asf/camel.git
commit a0cda7e9cd753e20a44a76651d621c23778906de Author: Guillaume Nodet <[email protected]> AuthorDate: Tue Mar 17 17:39:51 2026 +0100 CAMEL-23194: Fix blocked JMS tests in camel-itest Stop sharing a singleton JmsComponent across tests. The shared component could get stopped/stuck when one test's CamelContext shuts down, blocking subsequent tests. Now only the broker and ConnectionFactory are shared, while each test gets a fresh JmsComponent instance. Also add @Timeout(60) to 13 JMS-related test classes that lacked it, preventing indefinite hangs on CI. Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../itest/customerrelations/CustomerServicesTest.java | 2 ++ .../org/apache/camel/itest/greeter/JmsToCxfInOutTest.java | 2 ++ .../apache/camel/itest/issues/RemoveEndpointsTest.java | 2 ++ .../apache/camel/itest/jetty/JettyJmsShutdownTest.java | 2 ++ .../camel/itest/jetty/JettyMulticastJmsFileTest.java | 2 ++ .../camel/itest/netty/NettyAsyncRequestReplyTest.java | 2 ++ .../org/apache/camel/itest/shiro/ShiroOverJmsTest.java | 2 ++ .../sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java | 2 ++ .../sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java | 2 ++ .../java/org/apache/camel/itest/tx/JmsToHttpTXTest.java | 2 ++ ...ceptionAndNoTransactionErrorHandlerConfiguredTest.java | 2 ++ .../camel/itest/tx/JmsToHttpTXWithOnExceptionTest.java | 2 ++ .../camel/itest/tx/JmsToHttpTXWithRollbackTest.java | 2 ++ .../camel/itest/utils/extensions/JmsServiceExtension.java | 15 +++++++++------ 14 files changed, 35 insertions(+), 6 deletions(-) diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java index accc49f7a1ca..5c360461b4bb 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java @@ -28,12 +28,14 @@ import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +@Timeout(60) public class CustomerServicesTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/JmsToCxfInOutTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/JmsToCxfInOutTest.java index 2e088b195182..ac4fc23771c9 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/JmsToCxfInOutTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/JmsToCxfInOutTest.java @@ -22,6 +22,7 @@ import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -31,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JmsToCxfInOutTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/RemoveEndpointsTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/RemoveEndpointsTest.java index c6317922be05..d603cb1d4a79 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/RemoveEndpointsTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/RemoveEndpointsTest.java @@ -26,10 +26,12 @@ import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.spi.Registry; import org.apache.camel.test.junit6.CamelTestSupport; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import static org.junit.jupiter.api.Assertions.assertEquals; +@Timeout(60) public class RemoveEndpointsTest extends CamelTestSupport { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); 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 4bd195a35d9e..11144e1d6125 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 @@ -25,6 +25,7 @@ import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JettyJmsShutdownTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyMulticastJmsFileTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyMulticastJmsFileTest.java index be72953eb7d2..f21126a7e8b0 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyMulticastJmsFileTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyMulticastJmsFileTest.java @@ -24,6 +24,7 @@ import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.TestSupport; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -32,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JettyMulticastJmsFileTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java index d7716126066a..b0a06f9eacdb 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java @@ -33,6 +33,7 @@ import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Doing request/reply over Netty with async processing. */ +@Timeout(60) public class NettyAsyncRequestReplyTest extends CamelTestSupport { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/shiro/ShiroOverJmsTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/shiro/ShiroOverJmsTest.java index b11714686303..65f4db919560 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/shiro/ShiroOverJmsTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/shiro/ShiroOverJmsTest.java @@ -28,8 +28,10 @@ import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.spi.Registry; import org.apache.camel.test.junit6.CamelTestSupport; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; +@Timeout(60) public class ShiroOverJmsTest extends CamelTestSupport { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java index 7bcb5812016d..f975933de466 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java @@ -30,6 +30,7 @@ import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.spring.junit6.CamelSpringTestSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,6 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * JMS with JDBC idempotent consumer test. */ +@Timeout(60) public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSupport { @RegisterExtension diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java index 2e2207b2bda6..4255867e277a 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java @@ -22,6 +22,7 @@ import java.sql.SQLException; import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail; /** * JMS with JDBC idempotent consumer test using XA. */ +@Timeout(60) public class FromJmsToJdbcIdempotentConsumerToJmsXaTest extends FromJmsToJdbcIdempotentConsumerToJmsTest { @RegisterExtension diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java index bdc26886264d..f6d29921fc9a 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java @@ -22,6 +22,7 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.test.context.ContextConfiguration; @@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JmsToHttpTXTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionAndNoTransactionErrorHandlerConfiguredTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionAndNoTransactionErrorHandlerConfiguredTest.java index bdaa5d80cecf..b881cabf381c 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionAndNoTransactionErrorHandlerConfiguredTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionAndNoTransactionErrorHandlerConfiguredTest.java @@ -25,6 +25,7 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -39,6 +40,7 @@ import static org.junit.jupiter.api.Assertions.fail; */ @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JmsToHttpTXWithOnExceptionAndNoTransactionErrorHandlerConfiguredTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionTest.java index 4d3257b7c108..6a01b1cf9116 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithOnExceptionTest.java @@ -25,6 +25,7 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -39,6 +40,7 @@ import static org.junit.jupiter.api.Assertions.fail; */ @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JmsToHttpTXWithOnExceptionTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java index 338a43a35fd7..2c987d29a577 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java @@ -22,6 +22,7 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.itest.utils.extensions.JmsServiceExtension; import org.apache.camel.test.spring.junit6.CamelSpringTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.test.context.ContextConfiguration; @@ -34,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ @CamelSpringTest @ContextConfiguration +@Timeout(60) public class JmsToHttpTXWithRollbackTest { @RegisterExtension public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/utils/extensions/JmsServiceExtension.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/utils/extensions/JmsServiceExtension.java index dc97c9251e6f..76debc895b40 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/utils/extensions/JmsServiceExtension.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/utils/extensions/JmsServiceExtension.java @@ -44,7 +44,7 @@ public final class JmsServiceExtension implements Extension { private static final Lock LOCK = new ReentrantLock(); private static JmsServiceExtension instance; - private final JmsComponent amq; + private final ConnectionFactory connectionFactory; private JmsServiceExtension() throws JMSException { EmbeddedActiveMQ embeddedBrokerService = new EmbeddedActiveMQ(); @@ -74,16 +74,19 @@ public final class JmsServiceExtension implements Extension { } catch (Exception e) { throw new RuntimeException(e); } - LOG.info("Creating a new reusable AMQ component"); - ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(brokerURL); - - amq = jmsComponentAutoAcknowledge(connectionFactory); + LOG.info("Creating a shared ConnectionFactory for the embedded broker"); + connectionFactory = CamelJmsTestHelper.createConnectionFactory(brokerURL); connectionFactory.createConnection(); } + /** + * Returns a new {@link JmsComponent} wrapping the shared {@link ConnectionFactory} each time. This avoids sharing a + * single component instance across tests, which can cause blocking when one test's CamelContext shuts down and stops + * the shared component. + */ public JmsComponent getComponent() { - return amq; + return jmsComponentAutoAcknowledge(connectionFactory); } public static JmsServiceExtension createExtension() {
