camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: Fix for CAMEL-7694 Eliminated race condition which caused intermittent test failures
Date Thu, 14 Aug 2014 02:13:36 GMT
Repository: camel
Updated Branches:
  refs/heads/master 343dd7733 -> b2c3b31bb


Fix for CAMEL-7694 Eliminated race condition which caused intermittent test failures


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

Branch: refs/heads/master
Commit: b2c3b31bba3191aa193cbb672b5d353fd2818ed2
Parents: 343dd77
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Wed Aug 13 19:42:00 2014 +0200
Committer: Kevin Earls <kevin@kevinearls.com>
Committed: Wed Aug 13 19:42:34 2014 +0200

----------------------------------------------------------------------
 .../restlet/example/RestletGroovyIssueTest.java | 23 ++++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b2c3b31b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
index 2803ac9..68f68f4 100644
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/restlet/example/RestletGroovyIssueTest.java
@@ -16,39 +16,48 @@
  */
 package org.apache.camel.itest.restlet.example;
 
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version 
  */
 public class RestletGroovyIssueTest extends CamelTestSupport {
-
+    protected static final Logger LOG = LoggerFactory.getLogger(RestletGroovyIssueTest.class);
     private long port = AvailablePortFinder.getNextAvailable(16000);
     private ExecutorService executorService = Executors.newFixedThreadPool(5);
 
     @Test
     public void testRestletGroovy() throws Exception {
-        getMockEndpoint("mock:input").expectedMessageCount(10);
-        getMockEndpoint("mock:output").expectedBodiesReceivedInAnyOrder("0", "1", "2", "3",
"4", "5", "6", "7", "8", "9");
-        
-        for (int i = 0; i < 10; i++) {
-            final Integer num = i;
+        String[] bodies = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
+        List<String> expectedBodies = Arrays.asList(bodies);
+        final CountDownLatch responsesToReceive = new CountDownLatch(expectedBodies.size());
+        getMockEndpoint("mock:input").expectedMessageCount(expectedBodies.size());
+        getMockEndpoint("mock:output").expectedBodiesReceivedInAnyOrder(expectedBodies);
+
+        for (final String s : expectedBodies) {
             executorService.submit(new Runnable() {
                 @Override
                 public void run() {
-                    String s = "" + num;
                     Object response = template.requestBody("restlet:http://localhost:" +
port + "/foo/" + s + "?restletMethod=GET", "");
                     assertEquals(s, response);
+                    responsesToReceive.countDown();
                 };
             });
         }
 
+        responsesToReceive.await(5, TimeUnit.SECONDS);
         assertMockEndpointsSatisfied();
 
         executorService.shutdownNow();


Mime
View raw message