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 2021/11/24 17:09:23 UTC

[camel] branch main updated (f4c7766 -> d58c731)

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

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


    from f4c7766  (chores) camel-rabbitmq: replace Thread.sleep with Awaitility in tests
     new d2e1d30  (chores) core/camel-management: replace Thread.sleep with Awaitility in tests
     new d58c731  (chores) core/camel-core: replace Thread.sleep with Awaitility in tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/support/DefaultTimeoutMapTest.java       | 27 ++++++++--------------
 .../ManagedRouteStopWithAbortAfterTimeoutTest.java |  8 ++++---
 .../camel/management/ManagedThreadPoolTest.java    | 20 ++++++++++++----
 3 files changed, 30 insertions(+), 25 deletions(-)

[camel] 01/02: (chores) core/camel-management: replace Thread.sleep with Awaitility in tests

Posted by or...@apache.org.
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 d2e1d303c5942e25f686918f70de87362127397d
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Wed Nov 24 16:19:16 2021 +0100

    (chores) core/camel-management: replace Thread.sleep with Awaitility in tests
---
 .../ManagedRouteStopWithAbortAfterTimeoutTest.java   |  8 +++++---
 .../camel/management/ManagedThreadPoolTest.java      | 20 ++++++++++++++++----
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteStopWithAbortAfterTimeoutTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteStopWithAbortAfterTimeoutTest.java
index ea8d92e..e4c731e 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteStopWithAbortAfterTimeoutTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteStopWithAbortAfterTimeoutTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.management;
 
+import java.time.Duration;
 import java.util.Set;
 
 import javax.management.MBeanServer;
@@ -24,6 +25,7 @@ import javax.management.ObjectName;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.DisabledOnOs;
 import org.junit.jupiter.api.condition.OS;
@@ -115,9 +117,9 @@ public class ManagedRouteStopWithAbortAfterTimeoutTest extends ManagementTestSup
             template.sendBody("seda:start", "message-" + i);
         }
 
-        Thread.sleep(1000);
-
-        assertTrue(mockEP.getExchanges().size() <= 5, "Should not have received more than 5 messages");
+        Awaitility.await().atMost(Duration.ofSeconds(1))
+                .untilAsserted(
+                        () -> assertTrue(mockEP.getExchanges().size() <= 5, "Should not have received more than 5 messages"));
     }
 
     static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
index bd0f789..83cfc32 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
@@ -16,10 +16,17 @@
  */
 package org.apache.camel.management;
 
+import java.time.Duration;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.DisabledOnOs;
 import org.junit.jupiter.api.condition.OS;
@@ -59,10 +66,8 @@ public class ManagedThreadPoolTest extends ManagementTestSupport {
         assertMockEndpointsSatisfied();
 
         // wait a bit to ensure JMX have updated values
-        Thread.sleep(2000);
-
-        poolSize = (Integer) mbeanServer.getAttribute(on, "PoolSize");
-        assertEquals(1, poolSize.intValue());
+        Awaitility.await().atMost(Duration.ofSeconds(2))
+                .untilAsserted(() -> assertPoolSize(mbeanServer, on));
 
         Integer largest = (Integer) mbeanServer.getAttribute(on, "LargestPoolSize");
         assertEquals(1, largest.intValue());
@@ -80,6 +85,13 @@ public class ManagedThreadPoolTest extends ManagementTestSupport {
         assertEquals(200, remainingCapacity, "remainingCapacity");
     }
 
+    private void assertPoolSize(MBeanServer mbeanServer, ObjectName on)
+            throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
+        Integer poolSize;
+        poolSize = (Integer) mbeanServer.getAttribute(on, "PoolSize");
+        assertEquals(1, poolSize.intValue());
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {

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

Posted by or...@apache.org.
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 d58c7318cb81f8faa5f2f4acd28d7a215855450d
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Wed Nov 24 16:28:08 2021 +0100

    (chores) core/camel-core: replace Thread.sleep with Awaitility in tests
---
 .../camel/support/DefaultTimeoutMapTest.java       | 27 ++++++++--------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/DefaultTimeoutMapTest.java b/core/camel-core/src/test/java/org/apache/camel/support/DefaultTimeoutMapTest.java
index fa84544..dfd53ea 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/DefaultTimeoutMapTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/DefaultTimeoutMapTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.support;
 
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Executors;
@@ -58,13 +59,8 @@ public class DefaultTimeoutMapTest {
         map.put("A", 123, 50);
         assertEquals(1, map.size());
 
-        Thread.sleep(250);
-        if (map.size() > 0) {
-            LOG.warn("Waiting extra due slow CI box");
-            Thread.sleep(1000);
-        }
-
-        assertEquals(0, map.size());
+        await().atMost(Duration.ofSeconds(2))
+                .untilAsserted(() -> assertEquals(0, map.size()));
 
         map.stop();
     }
@@ -120,14 +116,9 @@ public class DefaultTimeoutMapTest {
         map.put("A", 123, 100);
         assertEquals(1, map.size());
 
-        Thread.sleep(250);
-
-        if (map.size() > 0) {
-            LOG.warn("Waiting extra due slow CI box");
-            Thread.sleep(1000);
-        }
         // should have been timed out now
-        assertEquals(0, map.size());
+        await().atMost(Duration.ofSeconds(2))
+                .untilAsserted(() -> assertEquals(0, map.size()));
 
         assertSame(e, map.getExecutor());
 
@@ -157,9 +148,9 @@ public class DefaultTimeoutMapTest {
         // is not expired
         map.put("F", 6, 800);
 
-        Thread.sleep(250);
+        await().atMost(Duration.ofSeconds(1))
+                .untilAsserted(() -> assertEquals("D", keys.get(0)));
 
-        assertEquals("D", keys.get(0));
         assertEquals(4, values.get(0).intValue());
         assertEquals("B", keys.get(1));
         assertEquals(2, values.get(1).intValue());
@@ -188,8 +179,8 @@ public class DefaultTimeoutMapTest {
         map.put("A", 1, 50);
 
         // should not timeout as the scheduler doesn't run
-        Thread.sleep(250);
-        assertEquals(1, map.size());
+        await().atMost(Duration.ofSeconds(1))
+                .untilAsserted(() -> assertEquals(1, map.size()));
 
         // start
         map.start();