camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-11446: Use awaitility in camel-core for testing where we otherwise use thred sleep which can be speeded up.
Date Sat, 08 Jul 2017 08:40:39 GMT
Repository: camel
Updated Branches:
  refs/heads/master 47f8aafde -> dcb001f0d


CAMEL-11446: Use awaitility in camel-core for testing where we otherwise use thred sleep which
can be speeded up.


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

Branch: refs/heads/master
Commit: b2a3e4b1d9bf9027568147e176bb0997aa84105f
Parents: 47f8aaf
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jul 8 10:16:24 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jul 8 10:16:24 2017 +0200

----------------------------------------------------------------------
 .../component/seda/SedaConsumerSuspendResumeTest.java   | 12 +++++++++---
 .../camel/component/seda/SedaPurgeWhenStoppingTest.java |  8 +++++---
 ...ShutdownStrategyNotSuppressLoggingOnTimeoutTest.java |  2 ++
 .../ShutdownStrategySuppressLoggingOnTimeoutTest.java   |  2 +-
 .../camel/impl/StopRouteAbortAfterTimeoutTest.java      | 11 ++++++-----
 .../apache/camel/impl/TwoRouteSuspendResumeTest.java    |  9 ++++++++-
 .../org/apache/camel/issues/StopRouteFromRouteTest.java | 10 +++++++++-
 .../apache/camel/language/XPathRouteConcurrentTest.java |  2 +-
 .../processor/ShutdownSedaAndDirectEndpointTest.java    |  2 --
 9 files changed, 41 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerSuspendResumeTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerSuspendResumeTest.java
index 85c20b7..162b9bc 100644
--- a/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerSuspendResumeTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerSuspendResumeTest.java
@@ -16,11 +16,15 @@
  */
 package org.apache.camel.component.seda;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.util.ServiceHelper;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  *
  */
@@ -50,11 +54,13 @@ public class SedaConsumerSuspendResumeTest extends ContextTestSupport
{
 
         // wait a bit to ensure consumer is suspended, as it could be in a poll mode where
         // it would poll and route (there is a little slack (up till 1 sec) before suspension
is empowered)
-        Thread.sleep(2000);
+        await().atMost(1, TimeUnit.SECONDS).until(() ->
+            context.getEndpoint("seda:foo", SedaEndpoint.class).getQueue().size() == 0
+            && context.getEndpoint("seda:bar", SedaEndpoint.class).getQueue().size()
== 0);
 
         template.sendBody("seda:foo", "B");
-        // wait 2 sec to ensure seda consumer thread would have tried to poll otherwise
-        mock.assertIsSatisfied(2000);
+        // wait a little to ensure seda consumer thread would have tried to poll otherwise
+        mock.assertIsSatisfied(50);
 
         // resume consumer
         resetMocks();

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/component/seda/SedaPurgeWhenStoppingTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/seda/SedaPurgeWhenStoppingTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaPurgeWhenStoppingTest.java
index 36a7f32..1c8a3f2 100644
--- a/camel-core/src/test/java/org/apache/camel/component/seda/SedaPurgeWhenStoppingTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/seda/SedaPurgeWhenStoppingTest.java
@@ -31,6 +31,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 public class SedaPurgeWhenStoppingTest extends ContextTestSupport {
 
     private final CountDownLatch latch = new CountDownLatch(1);
+    private final CountDownLatch latch2 = new CountDownLatch(1);
 
     public void testPurgeWhenStopping() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -41,10 +42,11 @@ public class SedaPurgeWhenStoppingTest extends ContextTestSupport {
         }
 
         context.startRoute("myRoute");
-        latch.await(5, TimeUnit.SECONDS);
+        latch.await(2, TimeUnit.SECONDS);
         context.stopRoute("myRoute");
+        latch2.countDown();
 
-        mock.setAssertPeriod(2000);
+        mock.setAssertPeriod(500);
         mock.assertIsSatisfied();
     }
 
@@ -58,7 +60,7 @@ public class SedaPurgeWhenStoppingTest extends ContextTestSupport {
                         @Override
                         public void process(Exchange exchange) throws Exception {
                             latch.countDown();
-                            Thread.sleep(500);
+                            latch2.await(2, TimeUnit.SECONDS);
                         }
                     })
                     .to("mock:result");

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategyNotSuppressLoggingOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategyNotSuppressLoggingOnTimeoutTest.java
b/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategyNotSuppressLoggingOnTimeoutTest.java
index e7fafae..c094135 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategyNotSuppressLoggingOnTimeoutTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategyNotSuppressLoggingOnTimeoutTest.java
@@ -18,7 +18,9 @@ package org.apache.camel.impl;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
+import org.junit.Ignore;
 
+@Ignore("Test manually by inspecting logs")
 public class ShutdownStrategyNotSuppressLoggingOnTimeoutTest extends ContextTestSupport {
 
     public void testSuppressLogging() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategySuppressLoggingOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategySuppressLoggingOnTimeoutTest.java
b/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategySuppressLoggingOnTimeoutTest.java
index 1e5f239..715a2a8 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategySuppressLoggingOnTimeoutTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/ShutdownStrategySuppressLoggingOnTimeoutTest.java
@@ -20,7 +20,7 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Ignore;
 
-@Ignore("Test manually")
+@Ignore("Test manually by inspecting logs")
 public class ShutdownStrategySuppressLoggingOnTimeoutTest extends ContextTestSupport {
 
     public void testSuppressLogging() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/impl/StopRouteAbortAfterTimeoutTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/StopRouteAbortAfterTimeoutTest.java
b/camel-core/src/test/java/org/apache/camel/impl/StopRouteAbortAfterTimeoutTest.java
index 211e229..70df458 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/StopRouteAbortAfterTimeoutTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/StopRouteAbortAfterTimeoutTest.java
@@ -72,15 +72,16 @@ public class StopRouteAbortAfterTimeoutTest extends ContextTestSupport
{
         // the route should have been forced stopped
         assertTrue("stopRoute response should be True", stopRouteResponse);
         assertEquals("route should be stopped", true, context.getRouteStatus("start").isStopped());
-        
+
+        int before = mockEP.getExchanges().size();
+
         // send some more messages through the route
         for (int i = 5; i < 10; i++) {
             template.sendBody("seda:start", "message-" + i);
         }
-        
-        Thread.sleep(3000);
-        
-        assertTrue("Should not have received more than 5 messages", mockEP.getExchanges().size()
<= 5);
+
+        int after = mockEP.getExchanges().size();
+        assertEquals("Should not route messages", before, after);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/impl/TwoRouteSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/TwoRouteSuspendResumeTest.java
b/camel-core/src/test/java/org/apache/camel/impl/TwoRouteSuspendResumeTest.java
index 5f9f4ea..96b665a 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/TwoRouteSuspendResumeTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/TwoRouteSuspendResumeTest.java
@@ -16,9 +16,14 @@
  */
 package org.apache.camel.impl;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.seda.SedaEndpoint;
+
+import static org.awaitility.Awaitility.await;
 
 /**
  * @version 
@@ -45,7 +50,9 @@ public class TwoRouteSuspendResumeTest extends ContextTestSupport {
         context.suspendRoute("foo");
 
         // need to give seda consumer thread time to idle
-        Thread.sleep(500);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            return context.getEndpoint("seda:bar", SedaEndpoint.class).getQueue().size()
== 0;
+        });
 
         template.sendBody("seda:foo", "B");
         template.sendBody("direct:bar", "C");

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/issues/StopRouteFromRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/StopRouteFromRouteTest.java
b/camel-core/src/test/java/org/apache/camel/issues/StopRouteFromRouteTest.java
index 56e18db..1087398 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/StopRouteFromRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/StopRouteFromRouteTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.issues;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
@@ -30,6 +33,8 @@ import org.apache.camel.impl.DefaultCamelContext;
  */
 public class StopRouteFromRouteTest extends TestCase {
 
+    final CountDownLatch latch = new CountDownLatch(1);
+
     // START SNIPPET: e1
     public void testStopRouteFromRoute() throws Exception {
         // create camel, add routes, and start camel
@@ -51,7 +56,7 @@ public class StopRouteFromRouteTest extends TestCase {
         template.sendBody("direct:start", "Hello Camel");
 
         // just wait a bit for the thread to stop the route
-        Thread.sleep(1500);
+        latch.await(5, TimeUnit.SECONDS);
 
         // the route should now be stopped
         assertTrue("Route myRoute should be stopped", context.getRouteStatus("myRoute").isStopped());
@@ -88,6 +93,9 @@ public class StopRouteFromRouteTest extends TestCase {
                                             exchange.getContext().stopRoute("myRoute");
                                         } catch (Exception e) {
                                             // ignore
+                                        } finally {
+                                            // signal we stopped the route
+                                            latch.countDown();
                                         }
                                     }
                                 };

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/language/XPathRouteConcurrentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/XPathRouteConcurrentTest.java
b/camel-core/src/test/java/org/apache/camel/language/XPathRouteConcurrentTest.java
index 19b0aed..b4cf86c 100644
--- a/camel-core/src/test/java/org/apache/camel/language/XPathRouteConcurrentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/XPathRouteConcurrentTest.java
@@ -49,7 +49,7 @@ public class XPathRouteConcurrentTest extends ContextTestSupport {
 
         template.sendBody("seda:foo", "<person><name>Claus</name></person>");
 
-        Thread.sleep(100);
+        Thread.sleep(10);
 
         template.sendBody("seda:foo", "<person><name>James</name></person>");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b2a3e4b1/camel-core/src/test/java/org/apache/camel/processor/ShutdownSedaAndDirectEndpointTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ShutdownSedaAndDirectEndpointTest.java
b/camel-core/src/test/java/org/apache/camel/processor/ShutdownSedaAndDirectEndpointTest.java
index f159f8a..54533b6 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ShutdownSedaAndDirectEndpointTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ShutdownSedaAndDirectEndpointTest.java
@@ -35,8 +35,6 @@ public class ShutdownSedaAndDirectEndpointTest extends ContextTestSupport
{
         template.sendBody("seda:foo", "D");
         template.sendBody("seda:foo", "E");
 
-        Thread.sleep(10);
-
         context.stop();
 
         assertMockEndpointsSatisfied();


Mime
View raw message