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 2024/01/05 12:39:53 UTC
(camel) branch main updated: (chores) camel-jms: JmsDeliveryDelayTest fix flackiness (#12669)
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 7969abdc630 (chores) camel-jms: JmsDeliveryDelayTest fix flackiness (#12669)
7969abdc630 is described below
commit 7969abdc630ac3f375a2321020b0cc97d00a5db3
Author: Ivan Kulaga <ku...@gmail.com>
AuthorDate: Fri Jan 5 18:39:45 2024 +0600
(chores) camel-jms: JmsDeliveryDelayTest fix flackiness (#12669)
* testInOnlyWithDelay was flacky because sometimes message is not received from artemis before .assertIsSatisfied(context) is called.
* testInOutWithDelay was missing assertions of mock endpoint condition and of response contents.
* StopWatch should be used to measure time
---
.../camel/component/jms/JmsDeliveryDelayTest.java | 40 +++++++++++++++++-----
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeliveryDelayTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeliveryDelayTest.java
index f7d4e299a36..175e2e8d909 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeliveryDelayTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeliveryDelayTest.java
@@ -16,14 +16,20 @@
*/
package org.apache.camel.component.jms;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.util.StopWatch;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Tags;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/*
* Note: these tests offer only a naive check of the deliveryDelay functionality as they check the
@@ -35,23 +41,40 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@Tags({ @Tag("not-parallel") })
public class JmsDeliveryDelayTest extends AbstractPersistentJMSTest {
+ private CountDownLatch routeComplete;
+ private final StopWatch routeWatch = new StopWatch();
+
@Test
void testInOnlyWithDelay() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
- StopWatch watch = new StopWatch();
+ routeWatch.restart();
template.sendBody("activemq:topic:JmsDeliveryDelayTest?deliveryDelay=1000", "Hello World");
- MockEndpoint.assertIsSatisfied(context);
+ if(!routeComplete.await(2000, TimeUnit.MILLISECONDS)) {
+ fail("Message was not received from Artemis topic for too long");
+ }
- assertTrue(watch.taken() >= 1000, "Should take at least 1000 millis");
+ MockEndpoint.assertIsSatisfied(context);
+ assertTrue(routeWatch.taken() >= 1000, "Should take at least 1000 millis");
}
@Test
- void testInOutWithDelay() {
- StopWatch watch = new StopWatch();
- template.requestBody("activemq:topic:JmsDeliveryDelayTest?deliveryDelay=1000", "Hello World");
- assertTrue(watch.taken() >= 1000, "Should take at least 1000 millis");
+ void testInOutWithDelay() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ routeWatch.restart();
+ var response = template.requestBody("activemq:topic:JmsDeliveryDelayTest?deliveryDelay=1000", "Hello World");
+
+ MockEndpoint.assertIsSatisfied(context);
+ assertEquals(response, "Hello World");
+ assertTrue(routeWatch.taken() >= 1000, "Should take at least 1000 millis");
+ }
+
+ @BeforeEach
+ public void initLatch() {
+ routeComplete = new CountDownLatch(1);
}
@Override
@@ -60,7 +83,8 @@ public class JmsDeliveryDelayTest extends AbstractPersistentJMSTest {
@Override
public void configure() {
from("activemq:topic:JmsDeliveryDelayTest")
- .to("mock:result");
+ .to("mock:result")
+ .process(exchange -> routeComplete.countDown());
}
};
}