You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/10/12 07:48:01 UTC

[camel] branch main updated: CAMEL-18608: Fix the test AggregateCompletionOnlyTwoTest.testOnlyTwo

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

nfilotto 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 26ec7615ac6 CAMEL-18608: Fix the test AggregateCompletionOnlyTwoTest.testOnlyTwo
26ec7615ac6 is described below

commit 26ec7615ac6dc995f55467663bc8b8ed663d2307
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Oct 12 09:47:36 2022 +0200

    CAMEL-18608: Fix the test AggregateCompletionOnlyTwoTest.testOnlyTwo
---
 .../aggregator/AggregateCompletionOnlyTwoTest.java      | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletionOnlyTwoTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletionOnlyTwoTest.java
index 244c5d4d7f8..e6ee6f18762 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletionOnlyTwoTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletionOnlyTwoTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.processor.aggregator;
 
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.camel.CamelContext;
@@ -28,14 +29,15 @@ import org.apache.camel.processor.BodyInAggregatingStrategy;
 import org.apache.camel.processor.aggregate.MemoryAggregationRepository;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-public class AggregateCompletionOnlyTwoTest extends ContextTestSupport {
+class AggregateCompletionOnlyTwoTest extends ContextTestSupport {
 
-    private MyRepo repo = new MyRepo();
+    private final MyRepo repo = new MyRepo();
 
     @Test
-    public void testOnlyTwo() throws Exception {
+    void testOnlyTwo() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:aggregated");
         mock.expectedBodiesReceived("A+B", "C+END");
 
@@ -49,26 +51,27 @@ public class AggregateCompletionOnlyTwoTest extends ContextTestSupport {
         assertEquals(4, repo.getGet());
         assertEquals(2, repo.getAdd());
         assertEquals(2, repo.getRemove());
-        assertEquals(2, repo.getConfirm());
+        // A second thread is involved so let's use awaitility to add more flexibility to the test
+        await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(2, repo.getConfirm()));
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
-            public void configure() throws Exception {
+            public void configure() {
                 from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).aggregationRepository(repo)
                         .completionSize(2).to("mock:aggregated");
             }
         };
     }
 
-    private class MyRepo extends MemoryAggregationRepository {
+    private static class MyRepo extends MemoryAggregationRepository {
 
         private int add;
         private int get;
         private int remove;
-        private AtomicInteger confirm = new AtomicInteger(0);
+        private final AtomicInteger confirm = new AtomicInteger();
 
         @Override
         public Exchange add(CamelContext camelContext, String key, Exchange exchange) {