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

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


The following commit(s) were added to refs/heads/main by this push:
     new 66681bc86bc CAMEL-19298 Snmp replacing Thread.sleep with Awaitility 
(#10102)
66681bc86bc is described below

commit 66681bc86bcdce296072cedf99e2aaf3d722f2cb
Author: JiriOndrusek <[email protected]>
AuthorDate: Tue May 16 12:13:44 2023 +0200

    CAMEL-19298 Snmp replacing Thread.sleep with Awaitility (#10102)
---
 components/camel-snmp/pom.xml                                |  6 ++++++
 .../test/java/org/apache/camel/component/snmp/TrapTest.java  | 12 +++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/components/camel-snmp/pom.xml b/components/camel-snmp/pom.xml
index ac12ae7cf87..cc89b5d5d2f 100644
--- a/components/camel-snmp/pom.xml
+++ b/components/camel-snmp/pom.xml
@@ -58,6 +58,12 @@
             <artifactId>junit-jupiter</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <version>${awaitility-version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
diff --git 
a/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/TrapTest.java
 
b/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/TrapTest.java
index 5abbf7b8d40..6e681f2f5bc 100644
--- 
a/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/TrapTest.java
+++ 
b/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/TrapTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.snmp;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
@@ -24,6 +26,7 @@ import org.apache.camel.Producer;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.AvailablePortFinder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
@@ -56,14 +59,13 @@ public class TrapTest extends SnmpTestSupport {
         Producer producer = endpoint.createProducer();
         producer.process(exchange);
 
-        synchronized (this) {
-            Thread.sleep(1000);
-        }
-
         // If all goes right it should come here
         MockEndpoint mock = getMockEndpoint("mock:resultV" + version);
         mock.expectedMessageCount(1);
-        mock.assertIsSatisfied();
+
+        // wait a bit
+        Awaitility.await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> mock.assertIsSatisfied());
 
         Message in = mock.getReceivedExchanges().get(0).getIn();
         Assertions.assertTrue(in instanceof SnmpMessage, "Expected received 
object 'SnmpMessage.class'. Got: " + in.getClass());

Reply via email to