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


The following commit(s) were added to refs/heads/main by this push:
     new c4499beb638 CAMEL-19543 - camel-sjms2: replace Thread.sleep in tests.
c4499beb638 is described below

commit c4499beb6385dae4fd014391ad1c440356a1f5c0
Author: Vaishnavi R <v...@var-thinkpadp1gen4i.remote.csb>
AuthorDate: Wed Apr 3 14:41:55 2024 +0530

    CAMEL-19543 - camel-sjms2: replace Thread.sleep in tests.
    
    Updated the code.
    
    Updated the code.
    
    Removed unused dependency from pom.xml.
---
 .../sjms2/consumer/InOnlyTopicDurableConsumerTest.java      | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-sjms2/src/test/java/org/apache/camel/component/sjms2/consumer/InOnlyTopicDurableConsumerTest.java
 
b/components/camel-sjms2/src/test/java/org/apache/camel/component/sjms2/consumer/InOnlyTopicDurableConsumerTest.java
index 8470bedd66c..1c14b29b4f4 100644
--- 
a/components/camel-sjms2/src/test/java/org/apache/camel/component/sjms2/consumer/InOnlyTopicDurableConsumerTest.java
+++ 
b/components/camel-sjms2/src/test/java/org/apache/camel/component/sjms2/consumer/InOnlyTopicDurableConsumerTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.sjms2.consumer;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import jakarta.jms.ConnectionFactory;
 
 import org.apache.camel.CamelContext;
@@ -25,6 +28,7 @@ import org.apache.camel.component.sjms2.Sjms2Component;
 import org.apache.camel.component.sjms2.support.Jms2TestSupport;
 import org.apache.camel.test.infra.artemis.services.ArtemisService;
 import org.apache.camel.test.infra.artemis.services.ArtemisServiceFactory;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
@@ -32,6 +36,7 @@ import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
 public class InOnlyTopicDurableConsumerTest extends Jms2TestSupport {
 
     private static final String CONNECTION_ID = "test-connection-1";
+    private CountDownLatch latch = new CountDownLatch(2);
     @RegisterExtension
     public static ArtemisService service = 
ArtemisServiceFactory.createTCPAllProtocolsService();
 
@@ -49,10 +54,12 @@ public class InOnlyTopicDurableConsumerTest extends 
Jms2TestSupport {
         mock2.expectedBodiesReceived("Hello World");
 
         // wait a bit and send the message
-        Thread.sleep(1000);
-
         template.sendBody("sjms2:topic:foo", "Hello World");
 
+        if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
+            Assertions.fail("Message is not received as expected");
+        }
+
         MockEndpoint.assertIsSatisfied(context);
     }
 
@@ -76,9 +83,11 @@ public class InOnlyTopicDurableConsumerTest extends 
Jms2TestSupport {
             @Override
             public void configure() {
                 from("sjms2:topic:foo?durableSubscriptionName=bar1")
+                        .process(e -> latch.countDown())
                         .to("mock:result");
 
                 from("sjms2:topic:foo?durableSubscriptionName=bar2")
+                        .process(e -> latch.countDown())
                         .to("mock:result2");
             }
         };

Reply via email to