You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/10/10 07:20:45 UTC

[camel] branch main updated: CAMEL-19536: replaced Thread.sleep() in camel-micrometer (#11670)

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

acosentino 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 d5f9effdc1a CAMEL-19536: replaced Thread.sleep() in camel-micrometer (#11670)
d5f9effdc1a is described below

commit d5f9effdc1a2595a1d40716dce12c19e3e610f23
Author: LostArtist <93...@users.noreply.github.com>
AuthorDate: Tue Oct 10 09:20:37 2023 +0200

    CAMEL-19536: replaced Thread.sleep() in camel-micrometer (#11670)
    
    * CAMEL-19536: replaced Thread.sleep() in camel-micrometer
    
    * CAMEL-19536: replaced Thread.sleep() in camel-micrometer
    
    ---------
    
    Co-authored-by: Nikita Konovalov <nk...@redhat.com>
---
 components/camel-micrometer/pom.xml                        |  6 ++++++
 .../eventnotifier/MicrometerExchangeEventNotifierTest.java | 14 +++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/components/camel-micrometer/pom.xml b/components/camel-micrometer/pom.xml
index f30d8dece66..b58362bbee1 100644
--- a/components/camel-micrometer/pom.xml
+++ b/components/camel-micrometer/pom.xml
@@ -108,6 +108,12 @@
             <version>${assertj-version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <version>${awaitility-version}</version>
+            <scope>test</scope>
+        </dependency>
 
     </dependencies>
 
diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierTest.java
index 94486512ef6..7369a94c85f 100644
--- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierTest.java
+++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierTest.java
@@ -25,6 +25,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.ExpressionAdapter;
 import org.assertj.core.api.Assertions;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_EXCHANGES_INFLIGHT;
@@ -54,13 +55,16 @@ public class MicrometerExchangeEventNotifierTest extends AbstractMicrometerEvent
             @Override
             public Object evaluate(Exchange exchange) {
                 try {
-                    Assertions.assertThat(currentInflightExchanges()).isEqualTo(1.0D, withPrecision(0.1D));
-                    Thread.sleep(SLEEP);
+                    Awaitility.await().pollDelay(SLEEP, TimeUnit.MILLISECONDS).catchUncaughtExceptions().untilAsserted(() ->
+                            Assertions.assertThat(currentInflightExchanges()).isEqualTo(1.0D, withPrecision(0.1D)));
                     return exchange.getIn().getBody();
-                } catch (InterruptedException e) {
-                    throw new CamelExecutionException(e.getMessage(), exchange, e);
+                } catch (Exception e) {
+                    if (e.getCause() instanceof InterruptedException) {
+                        throw new CamelExecutionException(e.getMessage(), exchange, e);
+                    } else {
+                        throw new RuntimeException("Unexpected Exception");
+                    }
                 }
-
             }
         });
         mock.expectedMessageCount(count);