camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-11446: Use awaitility in camel-core for testing where we otherwise use thred sleep which can be speeded up.
Date Wed, 05 Jul 2017 20:10:00 GMT
Repository: camel
Updated Branches:
  refs/heads/master 869d3edf5 -> 7c3064460


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

Branch: refs/heads/master
Commit: 7c30644608c1737e73668da85ab40b32a5ec9d68
Parents: 869d3ed
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jul 5 22:09:54 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jul 5 22:09:54 2017 +0200

----------------------------------------------------------------------
 .../component/file/NewFileConsumerTest.java     |  5 +-
 .../camel/impl/DefaultConsumerTemplateTest.java | 75 ++++++++++++--------
 ...ownStrategySuppressLoggingOnTimeoutTest.java |  2 +
 3 files changed, 51 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7c306446/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumerTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumerTest.java
index 9cb1332..63f9864 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumerTest.java
@@ -17,12 +17,15 @@
 package org.apache.camel.component.file;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  *
  */
@@ -44,7 +47,7 @@ public class NewFileConsumerTest extends ContextTestSupport {
         assertMockEndpointsSatisfied();
         oneExchangeDone.matchesMockWaitTime();
 
-        Thread.sleep(250);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> myFile.isPost());
 
         assertTrue("Should have invoked postPollCheck", myFile.isPost());
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7c306446/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
b/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
index 63a0550..a277c12 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.impl;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.ContextTestSupport;
@@ -24,6 +25,8 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.RuntimeCamelException;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * @version 
  */
@@ -74,11 +77,13 @@ public class DefaultConsumerTemplateTest extends ContextTestSupport {
 
         template.sendBody("seda:foo", "Hello");
 
-        // a little delay to let the consumer see it
-        Thread.sleep(500);
-
-        out = consumer.receiveNoWait("seda:foo");
-        assertEquals("Hello", out.getIn().getBody());
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            Exchange foo = consumer.receiveNoWait("seda:foo");
+            if (foo != null) {
+                assertEquals("Hello", foo.getIn().getBody());
+            }
+            return foo != null;
+        });
     }
 
     public void testConsumeReceiveTimeout() throws Exception {
@@ -119,11 +124,13 @@ public class DefaultConsumerTemplateTest extends ContextTestSupport
{
 
         template.sendBody("seda:foo", "Hello");
 
-        // a little delay to let the consumer see it
-        Thread.sleep(500);
-
-        body = consumer.receiveBodyNoWait("seda:foo");
-        assertEquals("Hello", body);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            Object foo = consumer.receiveBodyNoWait("seda:foo");
+            if (foo != null) {
+                assertEquals("Hello", foo);
+            }
+            return foo != null;
+        });
     }
 
     public void testConsumeReceiveBodyString() throws Exception {
@@ -151,11 +158,13 @@ public class DefaultConsumerTemplateTest extends ContextTestSupport
{
 
         template.sendBody("seda:foo", "Hello");
 
-        // a little delay to let the consumer see it
-        Thread.sleep(400);
-
-        body = consumer.receiveBodyNoWait("seda:foo", String.class);
-        assertEquals("Hello", body);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            String foo = consumer.receiveBodyNoWait("seda:foo", String.class);
+            if (foo != null) {
+                assertEquals("Hello", foo);
+            }
+            return foo != null;
+        });
     }
 
     public void testConsumeReceiveEndpoint() throws Exception {
@@ -187,11 +196,13 @@ public class DefaultConsumerTemplateTest extends ContextTestSupport
{
 
         template.sendBody("seda:foo", "Hello");
 
-        // a little delay to let the consumer see it
-        Thread.sleep(400);
-
-        out = consumer.receiveNoWait(endpoint);
-        assertEquals("Hello", out.getIn().getBody());
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            Exchange foo = consumer.receiveNoWait(endpoint);
+            if (foo != null) {
+                assertEquals("Hello", foo.getIn().getBody());
+            }
+            return foo != null;
+        });
     }
 
     public void testConsumeReceiveEndpointBody() throws Exception {
@@ -250,11 +261,13 @@ public class DefaultConsumerTemplateTest extends ContextTestSupport
{
 
         template.sendBody("seda:foo", "Hello");
 
-        // a little delay to let the consumer see it
-        Thread.sleep(400);
-
-        out = consumer.receiveBodyNoWait(endpoint, String.class);
-        assertEquals("Hello", out);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            String foo = consumer.receiveBodyNoWait(endpoint, String.class);
+            if (foo != null) {
+                assertEquals("Hello", foo);
+            }
+            return foo != null;
+        });
     }
 
     public void testConsumeReceiveEndpointBodyNoWait() throws Exception {
@@ -266,11 +279,13 @@ public class DefaultConsumerTemplateTest extends ContextTestSupport
{
 
         template.sendBody("seda:foo", "Hello");
 
-        // a little delay to let the consumer see it
-        Thread.sleep(400);
-
-        out = consumer.receiveBodyNoWait(endpoint);
-        assertEquals("Hello", out);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> {
+            Object foo = consumer.receiveBodyNoWait(endpoint);
+            if (foo != null) {
+                assertEquals("Hello", foo);
+            }
+            return foo != null;
+        });
     }
 
     public void testReceiveException() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/7c306446/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 9c77862..1e5f239 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
@@ -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")
 public class ShutdownStrategySuppressLoggingOnTimeoutTest extends ContextTestSupport {
 
     public void testSuppressLogging() throws Exception {


Mime
View raw message