You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2013/11/13 08:39:06 UTC

git commit: more timing protection in camel tests

Updated Branches:
  refs/heads/master e3166a29d -> 45d049d52


more timing protection in camel tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/45d049d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/45d049d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/45d049d5

Branch: refs/heads/master
Commit: 45d049d526afb6107e3e0d7429426125ec056706
Parents: e3166a2
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Nov 13 08:38:43 2013 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Nov 13 08:38:43 2013 +0100

----------------------------------------------------------------------
 .../java/org/apache/batchee/camel/CamelWriterTest.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/45d049d5/extensions/camel/src/test/java/org/apache/batchee/camel/CamelWriterTest.java
----------------------------------------------------------------------
diff --git a/extensions/camel/src/test/java/org/apache/batchee/camel/CamelWriterTest.java b/extensions/camel/src/test/java/org/apache/batchee/camel/CamelWriterTest.java
index 46ae090..530fc21 100644
--- a/extensions/camel/src/test/java/org/apache/batchee/camel/CamelWriterTest.java
+++ b/extensions/camel/src/test/java/org/apache/batchee/camel/CamelWriterTest.java
@@ -18,6 +18,7 @@ package org.apache.batchee.camel;
 
 import org.apache.batchee.util.Batches;
 import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.component.direct.DirectEndpoint;
 import org.testng.annotations.Test;
 
 import javax.batch.api.chunk.ItemReader;
@@ -38,19 +39,22 @@ public class CamelWriterTest extends CamelBridge {
     public void write() throws Exception {
         final ConsumerTemplate tpl = CONTEXT.createConsumerTemplate();
         final Collection<Object> received = new ArrayList<Object>(2);
-        final ExecutorService thread = Executors.newFixedThreadPool(1);
+
+        final ExecutorService thread = Executors.newSingleThreadExecutor();
         thread.submit(new Runnable() {
             @Override
             public void run() {
-                Object o;
                 do {
-                    o = tpl.receiveBody("direct:writer");
-                    received.add(o);
+                    received.add(tpl.receiveBody("direct:writer"));
                 } while (received.size() < 2);
             }
         });
         thread.shutdown();
 
+        do { // starting the listener in another thread w can get timing issues so ensuring we are in the right state
+            Thread.sleep(20);
+        } while (DirectEndpoint.class.cast(CONTEXT.getEndpoint("direct:writer")).getConsumer() == null);
+
         final JobOperator jobOperator = BatchRuntime.getJobOperator();
         Batches.waitForEnd(jobOperator, jobOperator.start("camel-writer", new Properties()));