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/14 10:27:21 UTC
[camel] 02/05: (chores) camel-mybatis: removed usages of 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 16f4b346747014717c95cc943d63ed23f684b1bf
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Jun 14 10:25:41 2022 +0200
(chores) camel-mybatis: removed usages of Thread.sleep
---
components/camel-mybatis/pom.xml | 5 +++++
.../component/mybatis/MyBatisConsumerIdleMessageTest.java | 9 +++++++--
.../org/apache/camel/component/mybatis/MyBatisQueueTest.java | 10 +++++++---
.../camel/component/mybatis/MyBatisShutdownAllTasksTest.java | 10 ++++++----
4 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/components/camel-mybatis/pom.xml b/components/camel-mybatis/pom.xml
index c17fbd960ff..587f2ee81e1 100644
--- a/components/camel-mybatis/pom.xml
+++ b/components/camel-mybatis/pom.xml
@@ -75,5 +75,10 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIdleMessageTest.java b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIdleMessageTest.java
index cbbd22b3c66..804eda4c8f9 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIdleMessageTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIdleMessageTest.java
@@ -16,10 +16,13 @@
*/
package org.apache.camel.component.mybatis;
+import java.util.concurrent.TimeUnit;
+
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
@@ -35,10 +38,12 @@ public class MyBatisConsumerIdleMessageTest extends MyBatisTestSupport {
@Test
public void testConsumeIdleMessages() throws Exception {
- Thread.sleep(110);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(2);
- assertMockEndpointsSatisfied();
+
+ await()
+ .atLeast(110, TimeUnit.MILLISECONDS)
+ .untilAsserted(() -> assertMockEndpointsSatisfied());
assertNull(mock.getExchanges().get(0).getIn().getBody());
assertNull(mock.getExchanges().get(1).getIn().getBody());
}
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java
index 5baa582c3cc..57386321b1e 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java
@@ -17,12 +17,15 @@
package org.apache.camel.component.mybatis;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class MyBatisQueueTest extends MyBatisTestSupport {
@@ -59,11 +62,12 @@ public class MyBatisQueueTest extends MyBatisTestSupport {
assertMockEndpointsSatisfied();
// need a delay here on slower machines
- Thread.sleep(1000);
+ List<?> body = await()
+ .atMost(1, TimeUnit.SECONDS)
+ .until(() -> template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class),
+ Matchers.notNullValue());
// now lets poll that the account has been inserted
- List<?> body = template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class);
-
assertEquals(2, body.size(), "Wrong size: " + body);
Account actual = assertIsInstanceOf(Account.class, body.get(0));
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisShutdownAllTasksTest.java b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisShutdownAllTasksTest.java
index e565546d68a..bcd9e5b6f91 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisShutdownAllTasksTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisShutdownAllTasksTest.java
@@ -16,12 +16,15 @@
*/
package org.apache.camel.component.mybatis;
+import java.util.concurrent.TimeUnit;
+
import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class MyBatisShutdownAllTasksTest extends MyBatisTestSupport {
@@ -95,11 +98,10 @@ public class MyBatisShutdownAllTasksTest extends MyBatisTestSupport {
// shutdown during processing
context.stop();
- // sleep a little
- Thread.sleep(1000);
-
// should route all 8
- assertEquals(8, bar.getReceivedCounter(), "Should complete all messages");
+ await()
+ .atMost(1, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(8, bar.getReceivedCounter(), "Should complete all messages"));
}
@Override