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 13:38:31 UTC
[camel] 01/02: (chores) camel-aws-xray: remove a few calls to Thread.sleep
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 b1f0ff73d3aced847da046060abd1b4cffe60761
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Jun 15 13:55:57 2022 +0200
(chores) camel-aws-xray: remove a few calls to Thread.sleep
---
components/camel-aws/camel-aws-xray/pom.xml | 5 +++++
.../camel/component/aws/xray/CamelAwsXRayTestSupport.java | 13 ++++++-------
.../component/aws/xray/SpringAwsXRaySimpleRouteTest.java | 7 +++++--
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/components/camel-aws/camel-aws-xray/pom.xml b/components/camel-aws/camel-aws-xray/pom.xml
index e93c35752f0..7424437b9b1 100644
--- a/components/camel-aws/camel-aws-xray/pom.xml
+++ b/components/camel-aws/camel-aws-xray/pom.xml
@@ -103,6 +103,11 @@
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/CamelAwsXRayTestSupport.java b/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/CamelAwsXRayTestSupport.java
index df6ed2bed9e..114138dcbf1 100644
--- a/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/CamelAwsXRayTestSupport.java
+++ b/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/CamelAwsXRayTestSupport.java
@@ -21,6 +21,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.component.aws.xray.TestDataBuilder.TestTrace;
@@ -29,6 +30,8 @@ import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
+import static org.awaitility.Awaitility.await;
+
public class CamelAwsXRayTestSupport extends CamelTestSupport {
protected FakeAWSDaemon socketListener = new FakeAWSDaemon();
@@ -87,13 +90,9 @@ public class CamelAwsXRayTestSupport extends CamelTestSupport {
}
protected void verify() {
- try {
- // give the socket listener a bit time to receive the data and transform it to Java objects
- Thread.sleep(500);
- } catch (InterruptedException iEx) {
- // ignore
- }
- Map<String, TestTrace> receivedData = socketListener.getReceivedData();
+ Map<String, TestTrace> receivedData = await().atMost(500, TimeUnit.MILLISECONDS)
+ .until(socketListener::getReceivedData, v -> v.size() == testData.size());
+
TestUtils.checkData(receivedData, testData);
}
}
diff --git a/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/SpringAwsXRaySimpleRouteTest.java b/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/SpringAwsXRaySimpleRouteTest.java
index 54423f612bb..7cf39175aa2 100644
--- a/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/SpringAwsXRaySimpleRouteTest.java
+++ b/components/camel-aws/camel-aws-xray/src/test/java/org/apache/camel/component/aws/xray/SpringAwsXRaySimpleRouteTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws.xray;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.camel.builder.NotifyBuilder;
@@ -29,6 +30,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -82,8 +84,9 @@ public class SpringAwsXRaySimpleRouteTest extends CamelSpringTestSupport {
.withSegment(TestDataBuilder.createSegment("dude"))
.withSegment(TestDataBuilder.createSegment("car")));
- Thread.sleep(2000);
+ Map<String, TestTrace> receivedData = await().atMost(2, TimeUnit.SECONDS)
+ .until(socketListener::getReceivedData, v -> v.size() == testData.size());
- TestUtils.checkData(socketListener.getReceivedData(), testData);
+ TestUtils.checkData(receivedData, testData);
}
}