You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by on...@apache.org on 2018/10/03 08:49:34 UTC

[camel] branch camel-2.21.x updated: Check message received in queue in no particular order

This is an automated email from the ASF dual-hosted git repository.

onders pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.21.x by this push:
     new fdda26b  Check message received in queue in no particular order
fdda26b is described below

commit fdda26b91c2b0375aa3885998f1c1c7bc1a6f8ee
Author: Aurélien Pupier <ap...@redhat.com>
AuthorDate: Wed Oct 3 09:35:58 2018 +0200

    Check message received in queue in no particular order
    
    there is no expected order from product side. The tests were checking
    them in a particular order.
    
    Signed-off-by: Aurélien Pupier <ap...@redhat.com>
---
 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 cf85d45..b125cf6 100644
--- a/components/camel-reactive-streams/pom.xml
+++ b/components/camel-reactive-streams/pom.xml
@@ -93,6 +93,12 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <version>${assertj-version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
\ 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 06bf882..a42942b 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;
@@ -27,10 +30,10 @@ 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;
 
-
 public class DirectClientAPITest extends ReactiveStreamsTestSupport {
 
     @Test
@@ -86,11 +89,7 @@ public class DirectClientAPITest extends ReactiveStreamsTestSupport {
                 .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 +131,7 @@ public class DirectClientAPITest extends ReactiveStreamsTestSupport {
                 .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,12 +145,17 @@ public class DirectClientAPITest extends ReactiveStreamsTestSupport {
                 .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<String> queue) throws InterruptedException {
+        Set<String> 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
@@ -170,15 +170,9 @@ public class DirectClientAPITest extends ReactiveStreamsTestSupport {
                 .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();