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 Thu, 06 Jul 2017 14:45:54 GMT
Repository: camel
Updated Branches:
  refs/heads/master 183abd872 -> 144020608


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/1e51f29b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1e51f29b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1e51f29b

Branch: refs/heads/master
Commit: 1e51f29b72b684569bbabbd5eaba31ab60abbbef
Parents: 183abd8
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jul 6 16:38:35 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jul 6 16:38:35 2017 +0200

----------------------------------------------------------------------
 .../component/mock/MockEndpointTimeClauseTest.java |  4 ++--
 .../org/apache/camel/management/LoadTimerTest.java | 13 ++++++++-----
 .../management/ManagedInflightStatisticsTest.java  | 15 ++++++++++++---
 .../ManagedRouteStopAndStartCleanupTest.java       | 17 +++++++++++++----
 .../aggregator/AggregateDiscardOnTimeoutTest.java  | 10 +++++-----
 5 files changed, 40 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1e51f29b/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
b/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
index 90293b3..d172cd7 100644
--- a/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
@@ -48,7 +48,7 @@ public class MockEndpointTimeClauseTest extends ContextTestSupport {
     public void testAssertPeriod() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.setAssertPeriod(1000);
+        mock.setAssertPeriod(500);
 
         template.sendBody("direct:a", "A");
 
@@ -58,7 +58,7 @@ public class MockEndpointTimeClauseTest extends ContextTestSupport {
     public void testAssertPeriodNot() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.setAssertPeriod(1000);
+        mock.setAssertPeriod(500);
 
         template.sendBody("direct:a", "A");
         template.sendBody("direct:a", "B");

http://git-wip-us.apache.org/repos/asf/camel/blob/1e51f29b/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java b/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
index 8ff51a7..4afc197 100644
--- a/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
@@ -16,14 +16,18 @@
  */
 package org.apache.camel.management;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.TimerListener;
 import org.apache.camel.management.mbean.LoadTriplet;
 import org.apache.camel.support.TimerListenerManager;
 
+import static org.awaitility.Awaitility.await;
+
 public class LoadTimerTest extends ContextTestSupport {
 
-    private static final int SAMPLES = 3;
+    private static final int SAMPLES = 2;
 
     @Override
     public boolean isUseRouteBuilder() {
@@ -38,7 +42,7 @@ public class LoadTimerTest extends ContextTestSupport {
         TestLoadAware test = new TestLoadAware();
         myTimer.addTimerListener(test);
         try {
-            Thread.sleep(1000 * (SAMPLES + 1));
+            await().atMost(5, TimeUnit.SECONDS).until(() -> test.counter >= SAMPLES);
             assertTrue(test.counter >= SAMPLES);
             assertFalse(Double.isNaN(test.load.getLoad1()));
             assertTrue(test.load.getLoad1() > 0.0d);
@@ -52,13 +56,12 @@ public class LoadTimerTest extends ContextTestSupport {
 
     private class TestLoadAware implements TimerListener {
 
-        int counter;
+        volatile int counter;
         LoadTriplet load = new LoadTriplet();
 
         @Override
         public void onTimer() {
-            counter++;
-            load.update(counter);
+            load.update(++counter);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1e51f29b/camel-core/src/test/java/org/apache/camel/management/ManagedInflightStatisticsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedInflightStatisticsTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedInflightStatisticsTest.java
index c8fd5ca..929f24c 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedInflightStatisticsTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedInflightStatisticsTest.java
@@ -28,6 +28,8 @@ import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * @version
  */
@@ -61,9 +63,13 @@ public class ManagedInflightStatisticsTest extends ManagementTestSupport
{
 
         // start some exchanges.
         template.asyncSendBody("direct:start", latch1);
-        Thread.sleep(500);
+        Thread.sleep(250);
         template.asyncSendBody("direct:start", latch2);
-        Thread.sleep(100);
+
+        await().atMost(2, TimeUnit.SECONDS).until(() -> {
+            Long num = (Long) mbeanServer.getAttribute(on, "ExchangesInflight");
+            return num != null && num == 2;
+        });
 
         inflight = (Long) mbeanServer.getAttribute(on, "ExchangesInflight");
         assertEquals(2, inflight.longValue());
@@ -95,7 +101,10 @@ public class ManagedInflightStatisticsTest extends ManagementTestSupport
{
         latch2.countDown();
 
         // Lets wait for all the exchanges to complete.
-        Thread.sleep(500);
+        await().atMost(2, TimeUnit.SECONDS).until(() -> {
+            Long num = (Long) mbeanServer.getAttribute(on, "ExchangesInflight");
+            return num != null && num == 0;
+        });
 
         assertMockEndpointsSatisfied();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1e51f29b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopAndStartCleanupTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopAndStartCleanupTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopAndStartCleanupTest.java
index b6b13ef..f130762 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopAndStartCleanupTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopAndStartCleanupTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.management;
 
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
@@ -24,6 +25,8 @@ import org.apache.camel.Exchange;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.component.mock.MockEndpoint;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * Extended test to see if mbeans is removed and stats are correct
  *
@@ -52,7 +55,10 @@ public class ManagedRouteStopAndStartCleanupTest extends ManagedRouteStopAndStar
         assertEquals("Should be started", ServiceStatus.Started.name(), state);
 
         // need a bit time to let JMX update
-        Thread.sleep(1000);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            Long num = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+            return num == 1;
+        });
 
         // should have 1 completed exchange
         Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
@@ -82,8 +88,8 @@ public class ManagedRouteStopAndStartCleanupTest extends ManagedRouteStopAndStar
 
         mock.reset();
         mock.expectedBodiesReceived("Bye World");
-        // wait 3 seconds while route is stopped to verify that file was not consumed
-        mock.setResultWaitTime(3000);
+        // wait 2 seconds while route is stopped to verify that file was not consumed
+        mock.setResultWaitTime(2000);
 
         template.sendBodyAndHeader("file://target/managed", "Bye World", Exchange.FILE_NAME,
"bye.txt");
 
@@ -113,7 +119,10 @@ public class ManagedRouteStopAndStartCleanupTest extends ManagedRouteStopAndStar
         mock.assertIsSatisfied();
 
         // need a bit time to let JMX update
-        Thread.sleep(1000);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            Long num = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+            return num == 2;
+        });
 
         // should have 2 completed exchange
         completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");

http://git-wip-us.apache.org/repos/asf/camel/blob/1e51f29b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateDiscardOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateDiscardOnTimeoutTest.java
b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateDiscardOnTimeoutTest.java
index d5525db..872adab 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateDiscardOnTimeoutTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateDiscardOnTimeoutTest.java
@@ -35,8 +35,8 @@ public class AggregateDiscardOnTimeoutTest extends ContextTestSupport {
         template.sendBodyAndHeader("direct:start", "A", "id", 123);
         template.sendBodyAndHeader("direct:start", "B", "id", 123);
 
-        // wait 4 seconds
-        Thread.sleep(4000);
+        // wait 1 seconds
+        Thread.sleep(1000);
 
         mock.assertIsSatisfied();
 
@@ -49,7 +49,7 @@ public class AggregateDiscardOnTimeoutTest extends ContextTestSupport {
         template.sendBodyAndHeader("direct:start", "C", "id", 123);
 
         // should complete before timeout
-        mock.await(1500, TimeUnit.MILLISECONDS);
+        assertTrue(mock.await(1000, TimeUnit.MILLISECONDS));
     }
 
     @Override
@@ -61,8 +61,8 @@ public class AggregateDiscardOnTimeoutTest extends ContextTestSupport {
                 from("direct:start")
                     .aggregate(header("id"), new BodyInAggregatingStrategy())
                         .completionSize(3)
-                        // use a 2 second timeout
-                        .completionTimeout(2000)
+                        // use a 0.5 second timeout
+                        .completionTimeout(500)
                         // and if timeout occurred then just discard the aggregated message
                         .discardOnCompletionTimeout()
                         .to("mock:aggregated");


Mime
View raw message