You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2022/12/18 08:32:09 UTC

[camel] branch main updated (e5899213a4c -> 6dcb9bf169b)

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

bvahdat pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from e5899213a4c enable tests by FromJmsToJdbcIdempotentConsumerToJms(Xa)Test and observe them on jenkins
     new 11e7b57926d cleanup tests after enabling by the previous commit
     new c7e09490a86 polish tests
     new 6dcb9bf169b polish logger

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


Summary of changes:
 .../FromJmsToJdbcIdempotentConsumerToJmsTest.java  | 141 +++++++++------------
 ...FromJmsToJdbcIdempotentConsumerToJmsXaTest.java |   2 +-
 2 files changed, 64 insertions(+), 79 deletions(-)


[camel] 01/03: cleanup tests after enabling by the previous commit

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

bvahdat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 11e7b57926db5d09063b1fbacc4aa5315ef6ffd5
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Sat Dec 17 22:01:31 2022 +0100

    cleanup tests after enabling by the previous commit
---
 .../FromJmsToJdbcIdempotentConsumerToJmsTest.java  | 132 +++++++++------------
 ...FromJmsToJdbcIdempotentConsumerToJmsXaTest.java |   2 +-
 2 files changed, 56 insertions(+), 78 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 37ee580a563..7d87cacee30 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
@@ -17,10 +17,10 @@
 package org.apache.camel.itest.sql;
 
 import java.net.ConnectException;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.sql.DataSource;
 
+import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.NotifyBuilder;
@@ -40,12 +40,17 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
- * Jms with JDBC idempotent consumer test.
+ * JMS with JDBC idempotent consumer test.
  */
 public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSupport {
 
-    protected JdbcTemplate jdbcTemplate;
-    protected DataSource dataSource;
+    private JdbcTemplate jdbcTemplate;
+
+    @EndpointInject("mock:a")
+    private MockEndpoint mockA;
+
+    @EndpointInject("mock:b")
+    private MockEndpoint mockB;
 
     @Override
     protected AbstractApplicationContext createApplicationContext() {
@@ -58,13 +63,9 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     public void setUp() throws Exception {
         super.setUp();
 
-        dataSource = context.getRegistry().lookupByNameAndType(getDatasourceName(), DataSource.class);
+        DataSource dataSource = context.getRegistry().lookupByNameAndType(getDatasourceName(), DataSource.class);
         jdbcTemplate = new JdbcTemplate(dataSource);
         jdbcTemplate.afterPropertiesSet();
-
-        // cater for slow servers
-        getMockEndpoint("mock:a").setResultWaitTime(40000);
-        getMockEndpoint("mock:b").setResultWaitTime(40000);
     }
 
     protected String getDatasourceName() {
@@ -75,22 +76,19 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     void testJmsToJdbcJmsCommit() throws Exception {
         checkInitialState();
 
-        // use a notify to know when the message is done
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+        mockA.expectedMessageCount(1);
+        mockB.expectedMessageCount(1);
 
-        // use mock during testing as well
-        getMockEndpoint("mock:a").expectedMessageCount(1);
-        getMockEndpoint("mock:b").expectedMessageCount(1);
+        // use NotifyBuilder to know when the message is done
+        NotifyBuilder notify
+                = new NotifyBuilder(context).whenExactlyCompleted(1).whenDoneSatisfied(mockA).whenDoneSatisfied(mockB).create();
 
         template.sendBodyAndHeader("activemq2:queue:inbox", "A", "uid", 123);
 
-        // assert mock and wait for the message to be done
-        MockEndpoint.assertIsSatisfied(context);
         assertTrue(notify.matchesWaitTime(), "Should complete 1 message");
 
         // check that there is a message in the database and JMS queue
-        assertEquals(Integer.valueOf(1),
-                jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
+        assertEquals(1, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
         Object out = consumer.receiveBody("activemq2:queue:outbox", 3000);
         assertEquals("DONE-A", out);
     }
@@ -99,28 +97,22 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     void testJmsToJdbcJmsRollbackAtA() throws Exception {
         checkInitialState();
 
-        // use a notify to know that after 1+6 (1 original + 6 redelivery) attempts from AcitveMQ
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(7).create();
-
-        getMockEndpoint("mock:a").expectedMessageCount(7);
-        // force exception to occur at mock a
-        getMockEndpoint("mock:a").whenAnyExchangeReceived(new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                throw new ConnectException("Forced cannot connect to database");
-            }
+        mockA.expectedMessageCount(7);
+        mockB.expectedMessageCount(0);
+        mockB.whenAnyExchangeReceived(exchange -> {
+            throw new ConnectException("Forced cannot connect to database");
         });
-        getMockEndpoint("mock:b").expectedMessageCount(0);
+
+        // use NotifyBuilder to know that after 1+6 (1 original + 6 redelivery) attempts from ActiveMQ
+        NotifyBuilder notify
+                = new NotifyBuilder(context).whenExactlyDone(7).whenDoneSatisfied(mockA).whenDoneSatisfied(mockB).create();
 
         template.sendBodyAndHeader("activemq2:queue:inbox", "A", "uid", 123);
 
-        // assert mock and wait for the message to be done
-        MockEndpoint.assertIsSatisfied(context);
         assertTrue(notify.matchesWaitTime(), "Should complete 7 message");
 
-        // check that there is a message in the database and JMS queue
-        assertEquals(Integer.valueOf(0),
-                jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
+        // check that there is no message in the database and JMS queue
+        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
         assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
 
         // the message should have been moved to the AMQ DLQ queue
@@ -131,28 +123,22 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     void testJmsToJdbcJmsRollbackAtB() throws Exception {
         checkInitialState();
 
-        // use a notify to know that after 1+6 (1 original + 6 redelivery) attempts from AcitveMQ
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(7).create();
-
-        getMockEndpoint("mock:a").expectedMessageCount(7);
-        getMockEndpoint("mock:b").expectedMessageCount(7);
-        // force exception to occur at mock b
-        getMockEndpoint("mock:b").whenAnyExchangeReceived(new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                throw new ConnectException("Forced cannot send to AMQ queue");
-            }
+        mockA.expectedMessageCount(7);
+        mockB.expectedMessageCount(7);
+        mockB.whenAnyExchangeReceived(exchange -> {
+            throw new ConnectException("Forced cannot send to AMQ queue");
         });
 
+        // use NotifyBuilder to know that after 1+6 (1 original + 6 redelivery) attempts from ActiveMQ
+        NotifyBuilder notify
+                = new NotifyBuilder(context).whenExactlyDone(7).whenDoneSatisfied(mockA).whenDoneSatisfied(mockB).create();
+
         template.sendBodyAndHeader("activemq2:queue:inbox", "B", "uid", 456);
 
-        // assert mock and wait for the message to be done
-        MockEndpoint.assertIsSatisfied(context);
         assertTrue(notify.matchesWaitTime(), "Should complete 7 messages");
 
-        // check that there is a message in the database and JMS queue
-        assertEquals(Integer.valueOf(0),
-                jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
+        // check that there is no message in the database and JMS queue
+        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
         assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
 
         // the message should have been moved to the AMQ DLQ queue
@@ -163,25 +149,21 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     void testFilterIdempotent() throws Exception {
         checkInitialState();
 
-        // use a notify to know when the message is done
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(3).create();
+        mockA.expectedMessageCount(3);
+        mockB.expectedMessageCount(2);
 
-        // use mock during testing as well
-        getMockEndpoint("mock:a").expectedMessageCount(3);
-        // there should be 1 duplicate
-        getMockEndpoint("mock:b").expectedMessageCount(2);
+        // use NotifyBuilder to know when the message is done
+        NotifyBuilder notify
+                = new NotifyBuilder(context).whenExactlyDone(3).whenDoneSatisfied(mockA).whenDoneSatisfied(mockB).create();
 
         template.sendBodyAndHeader("activemq2:queue:inbox", "D", "uid", 111);
         template.sendBodyAndHeader("activemq2:queue:inbox", "E", "uid", 222);
         template.sendBodyAndHeader("activemq2:queue:inbox", "D", "uid", 111);
 
-        // assert mock and wait for the message to be done
-        MockEndpoint.assertIsSatisfied(context);
         assertTrue(notify.matchesWaitTime(), "Should complete 3 messages");
 
         // check that there is two messages in the database and JMS queue
-        assertEquals(Integer.valueOf(2),
-                jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
+        assertEquals(2, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
         assertEquals("DONE-D", consumer.receiveBody("activemq2:queue:outbox", 3000));
         assertEquals("DONE-E", consumer.receiveBody("activemq2:queue:outbox", 3000));
     }
@@ -190,35 +172,32 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
     void testRetryAfterException() throws Exception {
         checkInitialState();
 
-        final AtomicInteger counter = new AtomicInteger();
-
-        // use a notify to know when the message is done
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(4).create();
+        mockA.expectedMessageCount(4);
+        mockB.expectedMessageCount(4);
+        mockB.whenAnyExchangeReceived(new Processor() {
+            private boolean errorThrown;
 
-        // use mock during testing as well
-        getMockEndpoint("mock:a").expectedMessageCount(4);
-        // there should be 1 duplicate
-        getMockEndpoint("mock:b").expectedMessageCount(4);
-        getMockEndpoint("mock:b").whenAnyExchangeReceived(new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
-                if (counter.getAndIncrement() == 1) {
+                if (!errorThrown) {
+                    errorThrown = true;
                     throw new ConnectException("Forced cannot send to AMQ queue");
                 }
             }
         });
 
+        // use NotifyBuilder to know when the message is done
+        NotifyBuilder notify
+                = new NotifyBuilder(context).whenExactlyDone(4).whenDoneSatisfied(mockA).whenDoneSatisfied(mockB).create();
+
         template.sendBodyAndHeader("activemq2:queue:inbox", "D", "uid", 111);
         template.sendBodyAndHeader("activemq2:queue:inbox", "E", "uid", 222);
         template.sendBodyAndHeader("activemq2:queue:inbox", "F", "uid", 333);
 
-        // assert mock and wait for the message to be done
-        MockEndpoint.assertIsSatisfied(context);
         assertTrue(notify.matchesWaitTime(), "Should complete 4 messages");
 
-        // check that there is two messages in the database and JMS queue
-        assertEquals(Integer.valueOf(3),
-                jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
+        // check that there is three messages in the database and JMS queue
+        assertEquals(3, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
         assertEquals("DONE-D", consumer.receiveBody("activemq2:queue:outbox", 3000));
         assertEquals("DONE-E", consumer.receiveBody("activemq2:queue:outbox", 3000));
         assertEquals("DONE-F", consumer.receiveBody("activemq2:queue:outbox", 3000));
@@ -226,8 +205,7 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
 
     protected void checkInitialState() {
         // check there are no messages in the database and JMS queue
-        assertEquals(Integer.valueOf(0),
-                jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
+        assertEquals(0, jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
         assertNull(consumer.receiveBody("activemq2:queue:outbox", 2000));
     }
 
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 e808cc185e5..c2d29030afb 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
@@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.fail;
 
 /**
- * Jms with JDBC idempotent consumer test using XA.
+ * JMS with JDBC idempotent consumer test using XA.
  */
 public class FromJmsToJdbcIdempotentConsumerToJmsXaTest extends FromJmsToJdbcIdempotentConsumerToJmsTest {
 


[camel] 03/03: polish logger

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

bvahdat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6dcb9bf169b0997334fbe922e291a7db35d35822
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Sun Dec 18 09:30:49 2022 +0100

    polish logger
---
 .../camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java      | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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 00fffc66f12..92333d86f47 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
@@ -46,7 +46,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
  */
 public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSupport {
 
-    private static final Logger LOG = LoggerFactory.getLogger(FromJmsToJdbcIdempotentConsumerToJmsTest.class);
+    // this logger is used both by this class as well as FromJmsToJdbcIdempotentConsumerToJmsXaTest, so why not static
+    private final Logger LOG = LoggerFactory.getLogger(this.getClass());
 
     private JdbcTemplate jdbcTemplate;
 


[camel] 02/03: polish tests

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

bvahdat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c7e09490a86b4af39f1165eb1601528d9dfec835
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Sun Dec 18 08:58:16 2022 +0100

    polish tests
---
 .../sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java  | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 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 7d87cacee30..00fffc66f12 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
@@ -31,6 +31,8 @@ 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -44,6 +46,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
  */
 public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSupport {
 
+    private static final Logger LOG = LoggerFactory.getLogger(FromJmsToJdbcIdempotentConsumerToJmsTest.class);
+
     private JdbcTemplate jdbcTemplate;
 
     @EndpointInject("mock:a")
@@ -98,10 +102,10 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
         checkInitialState();
 
         mockA.expectedMessageCount(7);
-        mockB.expectedMessageCount(0);
-        mockB.whenAnyExchangeReceived(exchange -> {
+        mockA.whenAnyExchangeReceived(exchange -> {
             throw new ConnectException("Forced cannot connect to database");
         });
+        mockB.expectedMessageCount(0);
 
         // use NotifyBuilder to know that after 1+6 (1 original + 6 redelivery) attempts from ActiveMQ
         NotifyBuilder notify
@@ -109,7 +113,7 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
 
         template.sendBodyAndHeader("activemq2:queue:inbox", "A", "uid", 123);
 
-        assertTrue(notify.matchesWaitTime(), "Should complete 7 message");
+        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", Integer.class));
@@ -175,13 +179,15 @@ public class FromJmsToJdbcIdempotentConsumerToJmsTest extends CamelSpringTestSup
         mockA.expectedMessageCount(4);
         mockB.expectedMessageCount(4);
         mockB.whenAnyExchangeReceived(new Processor() {
-            private boolean errorThrown;
+            private boolean alreadyErrorThrown;
 
             @Override
             public void process(Exchange exchange) throws Exception {
-                if (!errorThrown) {
-                    errorThrown = true;
+                if (!alreadyErrorThrown) {
+                    alreadyErrorThrown = true;
                     throw new ConnectException("Forced cannot send to AMQ queue");
+                } else {
+                    LOG.info("Now successfully recovered from the error and can connect to AMQ queue");
                 }
             }
         });