You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/07/14 08:23:25 UTC

[camel] branch main updated (e7cc9c5a709 -> 80b34d3bb36)

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

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from e7cc9c5a709 Upgrade Rome tools to version 2.1.0
     new 38aa89cc942 (chores) camel-core: file test fixes and cleanups
     new d3e1c0db253 (chores) camel-core: SplitParallelTimeoutTest test fixes and cleanups
     new 746f82eabe1 (chores) camel-core: PooledExchangeTest test fixes and cleanups
     new 47214ce2b42 (chores) camel-core: multicast test fixes and cleanups
     new 80b34d3bb36 (chores) camel-core: DurationRoutePolicyMaxSecondsTest test fixes and cleanups

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../file/watch/FileWatchComponentTest.java         | 18 ++++++++--------
 .../file/FileConsumerDeleteAndMoveFailedTest.java  |  2 ++
 .../file/FileConsumerPollStrategyTest.java         |  9 ++++----
 .../file/FileConsumerPreMoveNoopTest.java          |  8 ++++---
 .../impl/DurationRoutePolicyMaxSecondsTest.java    | 13 ++++++-----
 .../MulticastParallelLastTimeoutTest.java          | 25 ++++++++++++++++++----
 .../processor/MulticastParallelTimeout2Test.java   | 25 ++++++++++++++++++----
 .../processor/MulticastParallelTimeout3Test.java   | 25 ++++++++++++++++++----
 .../apache/camel/processor/PooledExchangeTest.java |  5 ++++-
 .../camel/processor/SplitParallelTimeoutTest.java  | 17 +++++++++++----
 10 files changed, 107 insertions(+), 40 deletions(-)


[camel] 01/05: (chores) camel-core: file test fixes and cleanups

Posted by or...@apache.org.
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

commit 38aa89cc942c156695808afde7479aa321fcf11d
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 08:33:06 2023 +0200

    (chores) camel-core: file test fixes and cleanups
    
    - adjust timeouts for less flakiness on slower hosts
    - replace Thread.sleep with Awaitility
    - other minor cleanups
---
 .../component/file/watch/FileWatchComponentTest.java   | 18 +++++++++---------
 .../file/FileConsumerDeleteAndMoveFailedTest.java      |  2 ++
 .../component/file/FileConsumerPollStrategyTest.java   |  9 +++++----
 .../component/file/FileConsumerPreMoveNoopTest.java    |  8 +++++---
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
index be1cd855318..22765424c11 100644
--- a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
+++ b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
@@ -125,7 +125,7 @@ public class FileWatchComponentTest extends FileWatchComponentTestBase {
                 .getHeader(FileWatchConstants.EVENT_TYPE_HEADER, FileEventEnum.class) == FileEventEnum.CREATE);
 
         for (int i = 0; i < 10; i++) {
-            createFile(testPath(), i + "");
+            createFile(testPath(), String.valueOf(i));
         }
 
         MockEndpoint.assertIsSatisfied(context);
@@ -135,32 +135,32 @@ public class FileWatchComponentTest extends FileWatchComponentTestBase {
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("file-watch://" + testPath())
+                fromF("file-watch://%s", testPath())
                         .routeId("watchAll")
                         .to("mock:watchAll");
 
-                from("file-watch://" + testPath() + "?events=CREATE&antInclude=*.txt")
+                fromF("file-watch://%s?events=CREATE&antInclude=*.txt", testPath())
                         .routeId("onlyTxtInRoot")
                         .to("mock:onlyTxtInRoot");
 
-                from("file-watch://" + testPath() + "?events=CREATE&antInclude=*/*.txt")
+                fromF("file-watch://%s?events=CREATE&antInclude=*/*.txt", testPath())
                         .routeId("onlyTxtInSubdirectory")
                         .to("mock:onlyTxtInSubdirectory");
 
-                from("file-watch://" + testPath() + "?events=CREATE&antInclude=**/*.txt")
+                fromF("file-watch://%s?events=CREATE&antInclude=**/*.txt", testPath())
                         .routeId("onlyTxtAnywhere")
                         .to("mock:onlyTxtAnywhere");
 
-                from("file-watch://" + testPath() + "?events=CREATE")
+                fromF("file-watch://%s?events=CREATE", testPath())
                         .to("mock:watchCreate");
 
-                from("file-watch://" + testPath() + "?events=MODIFY")
+                fromF("file-watch://%s?events=MODIFY", testPath())
                         .to("mock:watchModify");
 
-                from("file-watch://" + testPath() + "?events=DELETE,CREATE")
+                fromF("file-watch://%s?events=DELETE,CREATE", testPath())
                         .to("mock:watchDeleteOrCreate");
 
-                from("file-watch://" + testPath() + "?events=DELETE,MODIFY")
+                fromF("file-watch://%s?events=DELETE,MODIFY", testPath())
                         .to("mock:watchDeleteOrModify");
             }
         };
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java
index a7fe5a9eb2c..b3944bb96c9 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.file;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated("Flaky and may have conflicts if running along with its parent class")
 public class FileConsumerDeleteAndMoveFailedTest extends FileConsumerDeleteAndFailureTest {
 
     @Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
index 07fbf9fe01d..b3abb6ef1cd 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file;
 
+import java.time.Duration;
+
 import org.apache.camel.Consumer;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
@@ -24,6 +26,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 import org.apache.camel.spi.Registry;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -64,10 +67,8 @@ public class FileConsumerPollStrategyTest extends ContextTestSupport {
 
         oneExchangeDone.matchesWaitTime();
 
-        // give file consumer a bit time
-        Thread.sleep(20);
-
-        assertTrue(event.startsWith("rollbackcommit"));
+        // give the file consumer a bit of time
+        Awaitility.await().atMost(Duration.ofSeconds(1)).untilAsserted(() -> assertTrue(event.startsWith("rollbackcommit")));
     }
 
     private static class MyPollStrategy implements PollingConsumerPollStrategy {
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java
index 699cd606002..65ea7399225 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java
@@ -29,12 +29,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FileConsumerPreMoveNoopTest extends ContextTestSupport {
 
+    private final String endpointUri = fileUri();
+
     @Test
     public void testPreMoveNoop() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
 
-        template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(endpointUri, "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
 
@@ -48,7 +50,7 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Hello World");
 
-        template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(endpointUri, "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
         oneExchangeDone.matchesWaitTime();
@@ -58,7 +60,7 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport {
         oneExchangeDone.reset();
         mock.expectedBodiesReceived("Hello Again World");
 
-        template.sendBodyAndHeader(fileUri(), "Hello Again World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(endpointUri, "Hello Again World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
         oneExchangeDone.matchesWaitTime();


[camel] 05/05: (chores) camel-core: DurationRoutePolicyMaxSecondsTest test fixes and cleanups

Posted by or...@apache.org.
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

commit 80b34d3bb369e9ab43c189820405de9c5e24484d
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 09:51:42 2023 +0200

    (chores) camel-core: DurationRoutePolicyMaxSecondsTest test fixes and cleanups
    
    - use assumptions to skip testing on very slow hosts
    - reduce the number of expected messages to reduce flakiness on slow CI hosts
---
 .../camel/impl/DurationRoutePolicyMaxSecondsTest.java       | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DurationRoutePolicyMaxSecondsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DurationRoutePolicyMaxSecondsTest.java
index 4536ea179d1..db220303c16 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DurationRoutePolicyMaxSecondsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DurationRoutePolicyMaxSecondsTest.java
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.engine.DurationRoutePolicy;
+import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.Test;
 
 import static org.awaitility.Awaitility.await;
@@ -31,19 +32,17 @@ public class DurationRoutePolicyMaxSecondsTest extends ContextTestSupport {
 
     @Test
     public void testDurationRoutePolicy() throws Exception {
-        assertTrue(context.getRouteController().getRouteStatus("foo").isStarted());
-        assertFalse(context.getRouteController().getRouteStatus("foo").isStopped());
-
-        // the policy should stop the route after 2 seconds which is approx
-        // 20-30 messages
-        getMockEndpoint("mock:foo").expectedMinimumMessageCount(10);
-        assertMockEndpointsSatisfied();
+        Assumptions.assumeTrue(context.getRouteController().getRouteStatus("foo").isStarted());
+        Assumptions.assumeFalse(context.getRouteController().getRouteStatus("foo").isStopped());
 
         // need a little time to stop async
         await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
             assertFalse(context.getRouteController().getRouteStatus("foo").isStarted());
             assertTrue(context.getRouteController().getRouteStatus("foo").isStopped());
         });
+
+        // the policy should stop the route after 2 seconds, which should be enough for at least 1 message even on slow CI hosts
+        getMockEndpoint("mock:foo").expectedMinimumMessageCount(1);
     }
 
     @Override


[camel] 03/05: (chores) camel-core: PooledExchangeTest test fixes and cleanups

Posted by or...@apache.org.
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

commit 746f82eabe1bde2c1aad49b682c0baeb402585ee
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 09:05:30 2023 +0200

    (chores) camel-core: PooledExchangeTest test fixes and cleanups
    
    - use Awaitility for wait for assertions
---
 .../src/test/java/org/apache/camel/processor/PooledExchangeTest.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeTest.java
index 8ab45bbbdd7..bcf4a1a06cd 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.processor;
 
+import java.time.Duration;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
@@ -30,6 +31,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.engine.PooledExchangeFactory;
 import org.apache.camel.impl.engine.PooledProcessorExchangeFactory;
 import org.apache.camel.spi.PooledObjectFactory;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -72,7 +74,8 @@ class PooledExchangeTest extends ContextTestSupport {
                 = context.getCamelContextExtension().getExchangeFactoryManager().getStatistics();
         assertEquals(1, stat.getCreatedCounter());
         assertEquals(2, stat.getAcquiredCounter());
-        assertEquals(3, stat.getReleasedCounter());
+
+        Awaitility.await().atMost(Duration.ofSeconds(1)).untilAsserted(() -> assertEquals(3, stat.getReleasedCounter()));
         assertEquals(0, stat.getDiscardedCounter());
     }
 


[camel] 04/05: (chores) camel-core: multicast test fixes and cleanups

Posted by or...@apache.org.
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

commit 47214ce2b421cf6fff6b0622158fc53c38bf5785
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 09:16:05 2023 +0200

    (chores) camel-core: multicast test fixes and cleanups
    
    - adjust timeouts for less flakiness on slower hosts
    - send the test kick-off message earlier
    - skip running the test on very slow hosts than take too long to start the context
    - run in isolation for more stability in hosts with smaller core counts
    - improve coordination between different routes and the assertion time
---
 .../MulticastParallelLastTimeoutTest.java          | 25 ++++++++++++++++++----
 .../processor/MulticastParallelTimeout2Test.java   | 25 ++++++++++++++++++----
 .../processor/MulticastParallelTimeout3Test.java   | 25 ++++++++++++++++++----
 3 files changed, 63 insertions(+), 12 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
index 2dfec034cb9..7d150bf9a3e 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
@@ -16,22 +16,39 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.AggregationStrategy;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated
+@Timeout(60)
 public class MulticastParallelLastTimeoutTest extends ContextTestSupport {
 
+    private final Phaser phaser = new Phaser(3);
+
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run because the context is not started");
+        template.sendBody("direct:start", "Hello");
+    }
+
     @Test
     public void testMulticastParallelLastTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         // C will timeout so we only get A and B
         mock.expectedBodiesReceived("AB");
 
-        template.sendBody("direct:start", "Hello");
+        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
     }
@@ -55,11 +72,11 @@ public class MulticastParallelLastTimeoutTest extends ContextTestSupport {
                         // use end to indicate end of multicast route
                         .end().to("mock:result");
 
-                from("direct:a").delay(500).setBody(constant("A"));
+                from("direct:a").process(e -> phaser.arriveAndAwaitAdvance()).delay(500).setBody(constant("A"));
 
-                from("direct:b").setBody(constant("B"));
+                from("direct:b").process(e -> phaser.arriveAndAwaitAdvance()).setBody(constant("B"));
 
-                from("direct:c").delay(3000).setBody(constant("C"));
+                from("direct:c").process(e -> phaser.arriveAndAwaitAdvance()).delay(3000).setBody(constant("C"));
             }
         };
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
index dcfc132288f..501a601aae1 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
@@ -16,15 +16,32 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.AggregationStrategy;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated
+@Timeout(60)
 public class MulticastParallelTimeout2Test extends ContextTestSupport {
 
+    private final Phaser phaser = new Phaser(3);
+
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run because the context is not started");
+        template.sendBody("direct:start", "Hello");
+    }
+
     @Test
     public void testMulticastParallelTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -35,7 +52,7 @@ public class MulticastParallelTimeout2Test extends ContextTestSupport {
         getMockEndpoint("mock:B").expectedMessageCount(0);
         getMockEndpoint("mock:C").expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Hello");
+        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
     }
@@ -60,11 +77,11 @@ public class MulticastParallelTimeout2Test extends ContextTestSupport {
                         // use end to indicate end of multicast route
                         .end().to("mock:result");
 
-                from("direct:a").to("mock:A").setBody(constant("A"));
+                from("direct:a").process(e -> phaser.arriveAndAwaitAdvance()).to("mock:A").setBody(constant("A"));
 
-                from("direct:b").delay(1000).to("mock:B").setBody(constant("B"));
+                from("direct:b").process(e -> phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:B").setBody(constant("B"));
 
-                from("direct:c").to("mock:C").setBody(constant("C"));
+                from("direct:c").process(e -> phaser.arriveAndAwaitAdvance()).to("mock:C").setBody(constant("C"));
                 // END SNIPPET: e1
             }
         };
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
index 53c6dfaeb82..768deb1826a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
@@ -16,15 +16,32 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.AggregationStrategy;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated
+@Timeout(60)
 public class MulticastParallelTimeout3Test extends ContextTestSupport {
 
+    private final Phaser phaser = new Phaser(3);
+
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run because the context is not started");
+        template.sendBody("direct:start", "Hello");
+    }
+
     @Test
     public void testMulticastParallelTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -35,7 +52,7 @@ public class MulticastParallelTimeout3Test extends ContextTestSupport {
         getMockEndpoint("mock:B").expectedMessageCount(1);
         getMockEndpoint("mock:C").expectedMessageCount(0);
 
-        template.sendBody("direct:start", "Hello");
+        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
     }
@@ -60,11 +77,11 @@ public class MulticastParallelTimeout3Test extends ContextTestSupport {
                         // use end to indicate end of multicast route
                         .end().to("mock:result");
 
-                from("direct:a").to("mock:A").setBody(constant("A"));
+                from("direct:a").process(e -> phaser.arriveAndAwaitAdvance()).to("mock:A").setBody(constant("A"));
 
-                from("direct:b").to("mock:B").setBody(constant("B"));
+                from("direct:b").process(e -> phaser.arriveAndAwaitAdvance()).to("mock:B").setBody(constant("B"));
 
-                from("direct:c").delay(1000).to("mock:C").setBody(constant("C"));
+                from("direct:c").process(e -> phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:C").setBody(constant("C"));
                 // END SNIPPET: e1
             }
         };


[camel] 02/05: (chores) camel-core: SplitParallelTimeoutTest test fixes and cleanups

Posted by or...@apache.org.
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

commit d3e1c0db2537875058b676f7fb9edddd4d887779
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 08:35:10 2023 +0200

    (chores) camel-core: SplitParallelTimeoutTest test fixes and cleanups
    
    - adjust timeouts for less flakiness on slower hosts
    - send the test kick-off message earlier
    - skip running the test on very slow hosts than take too long to start the context
    - run in isolation for more stability in hosts with smaller core counts
---
 .../camel/processor/SplitParallelTimeoutTest.java       | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutTest.java
index 436df15a7c6..d0adc902fec 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutTest.java
@@ -24,13 +24,17 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.RepeatedTest;
 import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-@Timeout(50)
+@Isolated
+@Timeout(60)
 public class SplitParallelTimeoutTest extends ContextTestSupport {
 
     private volatile Exchange receivedExchange;
@@ -39,14 +43,18 @@ public class SplitParallelTimeoutTest extends ContextTestSupport {
     private volatile long receivedTimeout;
     private final Phaser phaser = new Phaser(3);
 
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run because the context is not started");
+        template.sendBody("direct:start", "A,B,C");
+    }
+
     @RepeatedTest(20)
     public void testSplitParallelTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         // A will timeout so we only get B and/or C
         mock.message(0).body().not(body().contains("A"));
 
-        template.sendBody("direct:start", "A,B,C");
-
         phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
@@ -62,7 +70,8 @@ public class SplitParallelTimeoutTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").split(body().tokenize(","), new MyAggregationStrategy()).parallelProcessing().timeout(100)
+                from("direct:start")
+                        .split(body().tokenize(","), new MyAggregationStrategy()).parallelProcessing().timeout(100)
                         .choice()
                             .when(body().isEqualTo("A")).to("direct:a")
                             .when(body().isEqualTo("B")).to("direct:b")