change the while loop to a do/while loop to fix async startup

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3879b2c0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3879b2c0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3879b2c0

Branch: refs/heads/master
Commit: 3879b2c0b018a6449766aa6662d1e2cc4c2593a1
Parents: 9449648
Author: Bryan Love <bryan.l...@iovation.com>
Authored: Fri Mar 24 13:07:28 2017 -0700
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Mar 28 10:03:54 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/component/sjms/batch/SjmsBatchConsumer.java | 8 +++++---
 .../sjms/batch/SjmsBatchConsumerAsyncStartTest.java          | 3 ++-
 .../camel/component/sjms/batch/SjmsBatchConsumerTest.java    | 4 ++++
 3 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3879b2c0/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumer.java
 
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumer.java
index a32cc3d..5a28dc2 100644
--- 
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumer.java
+++ 
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumer.java
@@ -305,8 +305,10 @@ public class SjmsBatchConsumer extends DefaultConsumer {
         @Override
         public void run() {
             try {
-                // this loop is intended to keep the consumer up and running 
as long as it's supposed to be, but allow it to bail if signaled
-                while (running.get() || isStarting()) {
+                // This loop is intended to keep the consumer up and running 
as long as it's supposed to be, but allow it to bail if signaled.
+                // I'm using a do/while loop because the first time through we 
want to attempt it regardless of any other conditions... we
+                // only want to try AGAIN if the keepAlive is set.
+                do {
                     // a batch corresponds to a single session that will be 
committed or rolled back by a background thread
                     final Session session = 
connection.createSession(TRANSACTED, Session.CLIENT_ACKNOWLEDGE);
                     try {
@@ -331,7 +333,7 @@ public class SjmsBatchConsumer extends DefaultConsumer {
                     } finally {
                         closeJmsSession(session);
                     }
-                }
+                }while (running.get() || isStarting());
             } catch (Throwable ex) {
                 // from consumeBatchesOnLoop
                 // catch anything besides the IllegalStateException and exit 
the application

http://git-wip-us.apache.org/repos/asf/camel/blob/3879b2c0/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerAsyncStartTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerAsyncStartTest.java
 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerAsyncStartTest.java
index fc0a46e..bb30840 100644
--- 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerAsyncStartTest.java
+++ 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerAsyncStartTest.java
@@ -21,6 +21,7 @@ import javax.jms.ConnectionFactory;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.sjms.SjmsComponent;
+import org.apache.camel.component.sjms.support.MockConnectionFactory;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.SimpleRegistry;
 
@@ -32,7 +33,7 @@ public class SjmsBatchConsumerAsyncStartTest extends 
SjmsBatchConsumerTest {
     public CamelContext createCamelContext() throws Exception {
         SimpleRegistry registry = new SimpleRegistry();
         registry.put("testStrategy", new ListAggregationStrategy());
-        ConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory(broker.getTcpConnectorUri());
+        ConnectionFactory connectionFactory = new 
MockConnectionFactory(broker.getTcpConnectorUri());
 
         SjmsComponent sjmsComponent = new SjmsComponent();
         sjmsComponent.setConnectionFactory(connectionFactory);

http://git-wip-us.apache.org/repos/asf/camel/blob/3879b2c0/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerTest.java
 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerTest.java
index 72610de..04746f2 100644
--- 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerTest.java
+++ 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/batch/SjmsBatchConsumerTest.java
@@ -33,6 +33,7 @@ import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.SimpleRegistry;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.StopWatch;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -48,6 +49,9 @@ public class SjmsBatchConsumerTest extends CamelTestSupport {
     public CamelContext createCamelContext() throws Exception {
         SimpleRegistry registry = new SimpleRegistry();
         registry.put("testStrategy", new ListAggregationStrategy());
+        // the only thing special about this MockConnectionFactor is it allows 
us to call returnBadSessionNTimes(int)
+        // which will cause the MockSession to throw an IllegalStateException 
<int> times before returning a valid one.
+        // This gives us the ability to test bad sessions
         ConnectionFactory connectionFactory = new 
MockConnectionFactory(broker.getTcpConnectorUri());
 
         SjmsComponent sjmsComponent = new SjmsComponent();

Reply via email to