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 9a3fcb8d064 CAMEL-19669: fixed non-deterministic assertion (#11028)
9a3fcb8d064 is described below
commit 9a3fcb8d064cf461ed455ed10bb08734411bbc19
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Mon Aug 7 16:41:17 2023 +0200
CAMEL-19669: fixed non-deterministic assertion (#11028)
When two consumers are reading from the same queue, it may not always be
possible to reliably determine which one may receive the message.
As such, tests both mock endpoints to ensure that in combination, all
expected data was received.
---
.../component/jms/TwoConsumerOnSameQueueTest.java | 29 +++++++++++++++++++---
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java
index 39327a67705..9940d6a711b 100644
---
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java
+++
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameQueueTest.java
@@ -16,8 +16,12 @@
*/
package org.apache.camel.component.jms;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Tags;
@@ -25,11 +29,12 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tags({ @Tag("not-parallel") })
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
-@DisabledIfSystemProperty(named = "ci.env.name", matches = "github.com",
disabledReason = "Flaky on Github CI")
public class TwoConsumerOnSameQueueTest extends AbstractPersistentJMSTest {
@Test
@@ -87,13 +92,29 @@ public class TwoConsumerOnSameQueueTest extends
AbstractPersistentJMSTest {
}
private void sendTwoMessagesWhichShouldReceivedOnBothEndpointsAndAssert()
throws InterruptedException {
- getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
- getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
+ final MockEndpoint mockB = getMockEndpoint("mock:b");
+ final MockEndpoint mockA = getMockEndpoint("mock:a");
template.sendBody("activemq:queue:TwoConsumerOnSameQueueTest", "Hello
World");
template.sendBody("activemq:queue:TwoConsumerOnSameQueueTest", "Hello
World");
- MockEndpoint.assertIsSatisfied(context);
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(
+ () -> assertEquals(2, mockA.getReceivedCounter() +
mockB.getReceivedCounter()));
+
+ for (Exchange exchange : mockA.getReceivedExchanges()) {
+ assertExchange(exchange);
+ }
+
+ for (Exchange exchange : mockB.getReceivedExchanges()) {
+ assertExchange(exchange);
+ }
+ }
+
+ private static void assertExchange(Exchange exchange) {
+ assertNotNull( exchange.getIn(), "There should be an in message");
+ assertNotNull(exchange.getIn().getBody(), "There should be an in
body");
+ assertNotNull(exchange.getIn().getBody(String.class), "The in message
body should be of type String");
+ assertEquals("Hello World", exchange.getIn().getBody(), "The in
message body should be 'Hello World");
}
@AfterEach