You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/06/08 15:56:21 UTC

[camel] branch CAMEL-18608/fix-FromJmsToJdbcIdempotentConsumerToJmsTest created (now fd7a95d4cb9)

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

nfilotto pushed a change to branch CAMEL-18608/fix-FromJmsToJdbcIdempotentConsumerToJmsTest
in repository https://gitbox.apache.org/repos/asf/camel.git


      at fd7a95d4cb9 CAMEL-18608: camel-itest - Avoid client and server resources mix-up

This branch includes the following new commits:

     new fd7a95d4cb9 CAMEL-18608: camel-itest - Avoid client and server resources mix-up

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/01: CAMEL-18608: camel-itest - Avoid client and server resources mix-up

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-18608/fix-FromJmsToJdbcIdempotentConsumerToJmsTest
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fd7a95d4cb9a35e47f054ae4114f0422e024336f
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Thu Jun 8 17:55:48 2023 +0200

    CAMEL-18608: camel-itest - Avoid client and server resources mix-up
---
 .../FromJmsToJdbcIdempotentConsumerToJmsTest.java  | 36 ++++++++++------------
 ...FromJmsToJdbcIdempotentConsumerToJmsXaTest.java |  2 --
 .../utils/extensions/JmsServiceExtension.java      | 28 ++++-------------
 .../FromJmsToJdbcIdempotentConsumerToJmsTest.xml   |  4 +--
 .../FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml |  4 +--
 5 files changed, 25 insertions(+), 49 deletions(-)

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 9ffa799cd78..cde02d59868 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
@@ -26,9 +26,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.itest.ITestSupport;
 import org.apache.camel.itest.utils.extensions.JmsServiceExtension;
-import org.apache.camel.spi.IdempotentRepository;
 import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -51,7 +49,6 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     @RegisterExtension
     public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension();
 
-    // this logger is used both by this class as well as FromJmsToJdbcIdempotentConsumerToJmsXaTest, so why not static
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     private JdbcTemplate jdbcTemplate;
@@ -64,7 +61,6 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
 
     @Override
     protected AbstractApplicationContext createApplicationContext() {
-        ITestSupport.getPort2();
         return new ClassPathXmlApplicationContext("org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml");
     }
 
@@ -83,7 +79,7 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     }
 
     @Test
-    void testJmsToJdbcJmsCommit() throws Exception {
+    void testJmsToJdbcJmsCommit() {
         checkInitialState();
 
         mockA.expectedMessageCount(1);
@@ -104,7 +100,7 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     }
 
     @Test
-    void testJmsToJdbcJmsRollbackAtA() throws Exception {
+    void testJmsToJdbcJmsRollbackAtA() {
         checkInitialState();
 
         mockA.expectedMessageCount(7);
@@ -121,16 +117,18 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
 
         assertTrue(notify.matchesWaitTime(), "Should complete 7 messages");
 
-        // check that there is no message in the database and JMS queue
-        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", int.class));
-        assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
+        // Start by checking the DLQ queue to prevent a mix-up between client and server resources being part of the same transaction
 
         // the message should have been moved to the AMQ DLQ queue
         assertEquals("A", consumer.receiveBody("activemq2:queue:DLQ", 3000));
+
+        // check that there is no message in the database and JMS queue
+        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", int.class));
+        assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
     }
 
     @Test
-    void testJmsToJdbcJmsRollbackAtB() throws Exception {
+    void testJmsToJdbcJmsRollbackAtB() {
         checkInitialState();
 
         mockA.expectedMessageCount(7);
@@ -147,16 +145,18 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
 
         assertTrue(notify.matchesWaitTime(), "Should complete 7 messages");
 
-        // check that there is no message in the database and JMS queue
-        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", int.class));
-        assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
+        // Start by checking the DLQ queue to prevent a mix-up between client and server resources being part of the same transaction
 
         // the message should have been moved to the AMQ DLQ queue
         assertEquals("B", consumer.receiveBody("activemq2:queue:DLQ", 3000));
+
+        // check that there is no message in the database and JMS queue
+        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", int.class));
+        assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
     }
 
     @Test
-    void testFilterIdempotent() throws Exception {
+    void testFilterIdempotent() {
         checkInitialState();
 
         mockA.expectedMessageCount(3);
@@ -179,7 +179,7 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     }
 
     @Test
-    void testRetryAfterException() throws Exception {
+    void testRetryAfterException() {
         checkInitialState();
 
         mockA.expectedMessageCount(4);
@@ -226,13 +226,11 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
         return new RouteBuilder() {
             @Override
             public void configure() {
-                IdempotentRepository repository
-                        = context.getRegistry().lookupByNameAndType("messageIdRepository", IdempotentRepository.class);
-
                 from("activemq2:queue:inbox")
                         .transacted("required")
                         .to(mockA)
-                        .idempotentConsumer(header("uid"), repository)
+                        .idempotentConsumer(header("uid"))
+                        .idempotentRepository("messageIdRepository")
                         .to(mockB)
                         .transform(simple("DONE-${body}"))
                         .to("activemq2:queue:outbox");
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 1beae85a84e..aacd8e93710 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
@@ -19,7 +19,6 @@ package org.apache.camel.itest.sql;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 
-import org.apache.camel.itest.ITestSupport;
 import org.apache.camel.itest.utils.extensions.JmsServiceExtension;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -69,7 +68,6 @@ public class FromJmsToJdbcIdempotentConsumerToJmsXaTest extends FromJmsToJdbcIde
 
     @Override
     protected AbstractApplicationContext createApplicationContext() {
-        ITestSupport.getPort1();
         return new ClassPathXmlApplicationContext("org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml");
     }
 }
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 7a02c12672d..f4b5f035002 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
@@ -29,37 +29,30 @@ import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.camel.component.jms.JmsComponent;
 import org.apache.camel.itest.CamelJmsTestHelper;
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.Extension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
 import static org.junit.jupiter.api.Assertions.fail;
 
-public final class JmsServiceExtension implements BeforeAllCallback, AfterAllCallback {
+public final class JmsServiceExtension implements Extension {
 
     private static final Logger LOG = LoggerFactory.getLogger(JmsServiceExtension.class);
 
     private static JmsServiceExtension instance;
 
-    private JmsComponent amq;
-
-    private EmbeddedActiveMQ embeddedBrokerService;
-
-    private Configuration artemisConfiguration;
-    private String brokerURL;
+    private final JmsComponent amq;
 
     private JmsServiceExtension() throws JMSException {
-        embeddedBrokerService = new EmbeddedActiveMQ();
+        EmbeddedActiveMQ embeddedBrokerService = new EmbeddedActiveMQ();
 
-        artemisConfiguration = new ConfigurationImpl();
+        Configuration artemisConfiguration = new ConfigurationImpl();
         artemisConfiguration.setSecurityEnabled(false);
         artemisConfiguration.setBrokerInstance(new File("target", "artemis-itest-jms"));
         artemisConfiguration.setJMXManagementEnabled(false);
         artemisConfiguration.setPersistenceEnabled(false);
-        brokerURL = "vm://itest-jms";
+        String brokerURL = "vm://itest-jms";
         try {
             artemisConfiguration.addAcceptorConfiguration("in-vm", brokerURL);
         } catch (Exception e) {
@@ -87,15 +80,6 @@ public final class JmsServiceExtension implements BeforeAllCallback, AfterAllCal
         connectionFactory.createConnection();
     }
 
-    @Override
-    public void afterAll(ExtensionContext extensionContext) throws Exception {
-    }
-
-    @Override
-    public void beforeAll(ExtensionContext extensionContext) throws Exception {
-
-    }
-
     public JmsComponent getComponent() {
         return amq;
     }
diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml b/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
index 63901ec9c6b..a49f0f24cb7 100644
--- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
+++ b/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
@@ -19,11 +19,9 @@
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:jdbc="http://www.springframework.org/schema/jdbc"
-       xmlns:broker="http://activemq.apache.org/schema/core"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-           http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
-           http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
+           http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
 
     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
 
diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml b/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml
index 45b915e913c..be36cdc7927 100644
--- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml
+++ b/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml
@@ -18,10 +18,8 @@
 
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:broker="http://activemq.apache.org/schema/core"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-           http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 
     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>