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 2022/06/15 12:51:40 UTC

[camel] 01/05: (chores) camel-mina: replace a few Thread.sleep 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 a8faad89454670bcc49a4889c011b1bf272350d3
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Jun 15 10:28:44 2022 +0200

    (chores) camel-mina: replace a few Thread.sleep with Awaitility
---
 components/camel-mina/pom.xml                                    | 6 ++++++
 .../apache/camel/component/mina/MinaSpringMultipleUDPTest.java   | 9 ++++++---
 .../java/org/apache/camel/component/mina/MinaUdpNoCamelTest.java | 7 +++++--
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/components/camel-mina/pom.xml b/components/camel-mina/pom.xml
index fa6de55b235..00950d47bed 100644
--- a/components/camel-mina/pom.xml
+++ b/components/camel-mina/pom.xml
@@ -74,6 +74,12 @@
             <artifactId>mockito-junit-jupiter</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaSpringMultipleUDPTest.java b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaSpringMultipleUDPTest.java
index 1e9e99f9aa0..97e59133bf4 100644
--- a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaSpringMultipleUDPTest.java
+++ b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaSpringMultipleUDPTest.java
@@ -16,12 +16,16 @@
  */
 package org.apache.camel.component.mina;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  *
  */
@@ -45,8 +49,7 @@ public class MinaSpringMultipleUDPTest extends CamelSpringTestSupport {
         }
 
         // Sleep for awhile to let the messages go through.
-        Thread.sleep(3000);
-
-        assertMockEndpointsSatisfied();
+        await().atMost(3, TimeUnit.SECONDS)
+                        .untilAsserted(() -> assertMockEndpointsSatisfied());
     }
 }
diff --git a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpNoCamelTest.java b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpNoCamelTest.java
index 694c852ff04..41668f373c7 100644
--- a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpNoCamelTest.java
+++ b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpNoCamelTest.java
@@ -24,6 +24,7 @@ import java.net.InetSocketAddress;
 import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.nio.charset.Charset;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.mina.core.service.IoHandlerAdapter;
@@ -40,6 +41,7 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class MinaUdpNoCamelTest {
@@ -70,8 +72,9 @@ public class MinaUdpNoCamelTest {
         for (int i = 0; i < 222; i++) {
             client.sendNoMina("Hello Mina " + i + System.lineSeparator());
         }
-        Thread.sleep(2000);
-        assertEquals(222, server.numMessagesReceived);
+
+        await().atMost(2, TimeUnit.SECONDS)
+                        .untilAsserted(() -> assertEquals(222, server.numMessagesReceived));
     }
 
     /*