You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/01/31 08:14:49 UTC

[camel] 02/03: (chores) camel-core: replace a few Thread.sleep calls in tests with Awaitility

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c389443d6519ccc6412a84da95d03841b2e6e284
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jan 30 18:04:02 2023 +0100

    (chores) camel-core: replace a few Thread.sleep calls in tests with Awaitility
---
 .../camel/component/seda/SedaDefaultDiscardWhenFullTest.java     | 9 +++++----
 .../org/apache/camel/component/seda/SedaDiscardWhenFullTest.java | 9 +++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultDiscardWhenFullTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultDiscardWhenFullTest.java
index 422a48327a0..dc013eb1744 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultDiscardWhenFullTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultDiscardWhenFullTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.seda;
 
+import java.time.Duration;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 public class SedaDefaultDiscardWhenFullTest extends ContextTestSupport {
@@ -37,10 +40,8 @@ public class SedaDefaultDiscardWhenFullTest extends ContextTestSupport {
         // start route
         context.getRouteController().startRoute("foo");
 
-        // wait until  at least 1 message has been consumed
-        while (mock.getReceivedCounter() < 1) {
-            Thread.sleep(100);
-        }
+        // wait until at least 1 message has been consumed
+        Awaitility.await().atMost(Duration.ofSeconds(10)).until(() -> mock.getReceivedCounter() >= 1);
 
         // and now there is room for me
         template.sendBody("seda:foo", "Camel World");
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDiscardWhenFullTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDiscardWhenFullTest.java
index 31a294321f3..93a24f991c1 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDiscardWhenFullTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDiscardWhenFullTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.seda;
 
+import java.time.Duration;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 public class SedaDiscardWhenFullTest extends ContextTestSupport {
@@ -36,10 +39,8 @@ public class SedaDiscardWhenFullTest extends ContextTestSupport {
         // start route
         context.getRouteController().startRoute("foo");
 
-        // wait until  at least 1 message has been consumed
-        while (mock.getReceivedCounter() < 1) {
-            Thread.sleep(100);
-        }
+        // wait until at least 1 message has been consumed
+        Awaitility.await().atMost(Duration.ofSeconds(10)).until(() -> mock.getReceivedCounter() >= 1);
 
         // and now there is room for me
         template.sendBody("seda:foo?discardWhenFull=true", "Camel World");