From 42a2f3b3831e502e6b963d3f92ec20e5850613ab 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 | 45 +++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/components/camel-reactive-streams/pom.xml b/components/camel-reactive-streams/pom.xml index cf85d4504dce2..f40a2134502e7 100644 --- a/components/camel-reactive-streams/pom.xml +++ b/components/camel-reactive-streams/pom.xml @@ -93,6 +93,12 @@ junit test + + org.assertj + assertj-core + 3.11.1 + test + \ No newline at end of file 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 06bf8825a80cb..a7aa3f2488041 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,20 +16,24 @@ */ 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; -import io.reactivex.Flowable; - import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; 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; +import io.reactivex.Flowable; + public class DirectClientAPITest extends ReactiveStreamsTestSupport { @@ -86,11 +90,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 @@ -132,11 +132,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 @@ -150,14 +146,19 @@ public void testDirectCallWithExchange() throws Exception { .map(ex -> ex.getOut().getBody(String.class)) .doOnNext(queue::add) .subscribe(); - - for (int i = 1; i <= 3; i++) { - String res = queue.poll(1, TimeUnit.SECONDS); - assertEquals("Hello " + i, res); - } - + + check3HelloInQueue(queue); } + 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 public void testDirectCallWithExchangeOverload() throws Exception { context.start(); @@ -170,15 +171,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();