From 6445ba2cdc985ab46015ab01fc49cf6ae3d7c77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pupier?= Date: Wed, 3 Oct 2018 09:35:58 +0200 Subject: [PATCH] Check message received in queue in no particular order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit there is no expected order from product side. The tests were checking them in a particular order. Signed-off-by: Aurélien Pupier --- components/camel-reactive-streams/pom.xml | 6 +++ .../reactive/streams/DirectClientAPITest.java | 40 ++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/components/camel-reactive-streams/pom.xml b/components/camel-reactive-streams/pom.xml index a05a650be284d..542c56e51f563 100644 --- a/components/camel-reactive-streams/pom.xml +++ b/components/camel-reactive-streams/pom.xml @@ -94,6 +94,12 @@ junit test + + org.assertj + assertj-core + ${assertj-version} + test + diff --git a/components/camel-reactive-streams/src/test/java/org/apache/camel/component/reactive/streams/DirectClientAPITest.java b/components/camel-reactive-streams/src/test/java/org/apache/camel/component/reactive/streams/DirectClientAPITest.java index 9c0a333b1368c..e82d5c20bbf7f 100644 --- a/components/camel-reactive-streams/src/test/java/org/apache/camel/component/reactive/streams/DirectClientAPITest.java +++ b/components/camel-reactive-streams/src/test/java/org/apache/camel/component/reactive/streams/DirectClientAPITest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.component.reactive.streams; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; @@ -26,10 +29,10 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.component.reactive.streams.support.ReactiveStreamsTestSupport; import org.apache.camel.impl.JndiRegistry; +import org.assertj.core.api.Assertions; import org.junit.Test; import org.reactivestreams.Publisher; - public class DirectClientAPITest extends ReactiveStreamsTestSupport { @Test @@ -85,11 +88,7 @@ public void testDirectCall() throws Exception { .doOnNext(queue::add) .subscribe(); - for (int i = 1; i <= 3; i++) { - String res = queue.poll(1, TimeUnit.SECONDS); - assertEquals("Hello " + i, res); - } - + check3HelloInQueue(queue); } @Test @@ -131,11 +130,7 @@ public void testDirectCallOverload() throws Exception { .doOnNext(queue::add) .subscribe(); - for (int i = 1; i <= 3; i++) { - String res = queue.poll(1, TimeUnit.SECONDS); - assertEquals("Hello " + i, res); - } - + check3HelloInQueue(queue); } @Test @@ -149,12 +144,17 @@ public void testDirectCallWithExchange() throws Exception { .map(ex -> ex.getOut().getBody(String.class)) .doOnNext(queue::add) .subscribe(); + + check3HelloInQueue(queue); + } - for (int i = 1; i <= 3; i++) { - String res = queue.poll(1, TimeUnit.SECONDS); - assertEquals("Hello " + i, res); - } - + private void check3HelloInQueue(BlockingQueue queue) throws InterruptedException { + Set res = new HashSet<>(); + res.add(queue.poll(1, TimeUnit.SECONDS)); + res.add(queue.poll(1, TimeUnit.SECONDS)); + res.add(queue.poll(1, TimeUnit.SECONDS)); + + Assertions.assertThat(res).containsExactlyInAnyOrderElementsOf(Arrays.asList("Hello 1", "Hello 2", "Hello 3")); } @Test @@ -169,15 +169,9 @@ public void testDirectCallWithExchangeOverload() throws Exception { .doOnNext(queue::add) .subscribe(); - for (int i = 1; i <= 3; i++) { - String res = queue.poll(1, TimeUnit.SECONDS); - assertEquals("Hello " + i, res); - } - + check3HelloInQueue(queue); } - - @Test public void testProxiedDirectCall() throws Exception { context.start();