This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 69eb14ee422f CAMEL-25893: camel-core - the multicast and split timeout
tests no longer keep the shutdown waiting (#30002)
69eb14ee422f is described below
commit 69eb14ee422f36bb89e5aca564cc80f86527f8c4
Author: Adriano Machado <[email protected]>
AuthorDate: Sun Nov 15 02:20:36 2026 -0500
CAMEL-25893: camel-core - the multicast and split timeout tests no longer
keep the shutdown waiting (#30002)
The @Isolated multicast, recipient list and split timeout tests ran their
timed-out
branch with a fixed delay(). The timeout does not cancel that branch, so
after the
assertion the graceful shutdown of the CamelContext waited for it, in steps
of one
second, while every other test worker sat idle. That was about half of the
86 s that
the isolated classes take, on the critical path of the module.
The branch that must time out now waits on a latch that an @AfterEach
releases, then
the test waits until no exchange is in flight. The branch can no longer
complete
before the timeout when the machine is loaded, and the shutdown has nothing
to wait
for. The fast branches and the timeouts are unchanged, so the tests stay
isolated.
MulticastParallelStreamingTimeoutTest has a 10 s timeout against a 500 ms
branch
and its flakiness (CAMEL-23901) came from an ordering assertion, so it is
no longer
isolated. Its Awaitility-wrapped mock assertion becomes the timed
MockEndpoint.assertIsSatisfied.
Locally the 14 classes take 20 s instead of 47 s, and the camel-core tests
run in
127 s instead of 170 s.
_Claude Code on behalf of Adriano Machado (@ammachado)_
_This was generated by an AI agent and may contain inaccuracies.
Please verify before relying on it._
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../processor/BeanRecipientListTimeoutTest.java | 17 ++++++++++++++++-
.../MulticastParallelAllTimeoutAwareTest.java | 21 ++++++++++++++++++---
.../MulticastParallelLastTimeoutTest.java | 17 ++++++++++++++++-
.../MulticastParallelMiddleTimeoutTest.java | 18 +++++++++++++++++-
.../MulticastParallelStreamingTimeoutTest.java | 22 ++++++++++++++--------
.../MulticastParallelStreamingTwoTimeoutTest.java | 20 ++++++++++++++++++--
.../processor/MulticastParallelTimeout2Test.java | 17 ++++++++++++++++-
.../processor/MulticastParallelTimeout3Test.java | 17 ++++++++++++++++-
.../MulticastParallelTimeoutAwareTest.java | 17 ++++++++++++++++-
.../processor/MulticastParallelTimeoutTest.java | 18 +++++++++++++++++-
.../MulticastParallelTwoTimeoutMiddleTest.java | 20 ++++++++++++++++++--
.../processor/MulticastParallelTwoTimeoutTest.java | 20 ++++++++++++++++++--
...itParallelTimeoutNoAggregationStrategyTest.java | 17 ++++++++++++++++-
.../camel/processor/SplitParallelTimeoutTest.java | 16 +++++++++++++++-
14 files changed, 231 insertions(+), 26 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/BeanRecipientListTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/BeanRecipientListTimeoutTest.java
index 605f32108e12..0986960829de 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/BeanRecipientListTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/BeanRecipientListTimeoutTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
import org.apache.camel.AggregationStrategy;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
@@ -23,9 +26,11 @@ import org.apache.camel.RecipientList;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spi.Registry;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -37,6 +42,16 @@ public class BeanRecipientListTimeoutTest extends
ContextTestSupport {
private volatile int receivedTotal;
private volatile long receivedTimeout;
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testBeanRecipientListParallelTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -67,7 +82,7 @@ public class BeanRecipientListTimeoutTest extends
ContextTestSupport {
public void configure() {
from("direct:start").bean("myBean", "route").to("mock:result");
- from("direct:a").delay(2000).setBody(constant("A"));
+ from("direct:a").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("A"));
from("direct:b").setBody(constant("B"));
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelAllTimeoutAwareTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelAllTimeoutAwareTest.java
index 68942e09dd6f..380518d66fef 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelAllTimeoutAwareTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelAllTimeoutAwareTest.java
@@ -16,14 +16,19 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -35,6 +40,16 @@ public class MulticastParallelAllTimeoutAwareTest extends
ContextTestSupport {
private volatile int receivedTotal;
private volatile long receivedTimeout;
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelAllTimeoutAware() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -63,11 +78,11 @@ public class MulticastParallelAllTimeoutAwareTest extends
ContextTestSupport {
// use end to indicate end of multicast route
.end().to("mock:result");
- from("direct:a").delay(1000).setBody(constant("A"));
+ from("direct:a").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("A"));
- from("direct:b").delay(2000).setBody(constant("B"));
+ from("direct:b").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("B"));
- from("direct:c").delay(1500).setBody(constant("C"));
+ from("direct:c").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("C"));
}
};
}
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 a68c45e4d1e7..84ccd24b3e65 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,6 +16,7 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
@@ -24,18 +25,31 @@ 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.AfterEach;
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;
+import static org.awaitility.Awaitility.await;
+
@Isolated
@Timeout(60)
public class MulticastParallelLastTimeoutTest extends ContextTestSupport {
private final Phaser phaser = new Phaser(3);
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@BeforeEach
void sendEarly() {
Assumptions.assumeTrue(context.isStarted(), "The test cannot be run
because the context is not started");
@@ -76,7 +90,8 @@ public class MulticastParallelLastTimeoutTest extends
ContextTestSupport {
from("direct:b").process(e ->
phaser.arriveAndAwaitAdvance()).setBody(constant("B"));
- from("direct:c").process(e ->
phaser.arriveAndAwaitAdvance()).delay(3000).setBody(constant("C"));
+ from("direct:c").process(e ->
phaser.arriveAndAwaitAdvance()).process(e -> release.await(30,
TimeUnit.SECONDS))
+ .setBody(constant("C"));
}
};
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelMiddleTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelMiddleTimeoutTest.java
index 82e49f56c989..b2f792b2a722 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelMiddleTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelMiddleTimeoutTest.java
@@ -16,17 +16,33 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
+
@Isolated
public class MulticastParallelMiddleTimeoutTest extends ContextTestSupport {
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelMiddleTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -59,7 +75,7 @@ public class MulticastParallelMiddleTimeoutTest extends
ContextTestSupport {
from("direct:a").setBody(constant("A"));
- from("direct:b").delay(1000).setBody(constant("B"));
+ from("direct:b").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("B"));
from("direct:c").delay(100).setBody(constant("C"));
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTimeoutTest.java
index 10e476fbf728..4cb976c8b5e1 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTimeoutTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.camel.AggregationStrategy;
@@ -23,17 +24,26 @@ 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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
-import org.junit.jupiter.api.parallel.Isolated;
import static org.awaitility.Awaitility.await;
-@Isolated("Short timeouts cause problems with parallel test execution")
@DisabledOnOs(architectures = { "s390x" },
disabledReason = "This test does not run reliably on s390x (see
CAMEL-21438)")
public class MulticastParallelStreamingTimeoutTest extends ContextTestSupport {
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelStreamingTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -42,14 +52,10 @@ public class MulticastParallelStreamingTimeoutTest extends
ContextTestSupport {
mock.message(0).body().not(body().contains("A"));
mock.message(0).body().contains("B");
mock.message(0).body().contains("C");
- // Use a short result wait time so each Awaitility attempt checks
quickly
- // without blocking (default 0 maps to 10s internally in MockEndpoint)
- mock.setResultWaitTime(100);
template.sendBody("direct:start", "Hello");
- await().atMost(20, TimeUnit.SECONDS)
- .untilAsserted(() -> assertMockEndpointsSatisfied());
+ MockEndpoint.assertIsSatisfied(context, 20, TimeUnit.SECONDS);
}
@Override
@@ -71,7 +77,7 @@ public class MulticastParallelStreamingTimeoutTest extends
ContextTestSupport {
// use end to indicate end of multicast route
.end().to("mock:result");
- from("direct:a").delay(20000).setBody(constant("A"));
+ from("direct:a").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("A"));
from("direct:b").delay(500).setBody(constant("B"));
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTwoTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTwoTimeoutTest.java
index 9b74e0824f3e..35ccb497a0e2 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTwoTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelStreamingTwoTimeoutTest.java
@@ -16,17 +16,33 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
+
@Isolated("Short timeouts cause problems with parallel text execution")
public class MulticastParallelStreamingTwoTimeoutTest extends
ContextTestSupport {
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelStreamingTwoTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -57,11 +73,11 @@ public class MulticastParallelStreamingTwoTimeoutTest
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 -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("A"));
from("direct:b").setBody(constant("B"));
- from("direct:c").delay(500).setBody(constant("C"));
+ from("direct:c").process(e -> release.await(30,
TimeUnit.SECONDS)).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 13de6d4ba508..9710f5b5b796 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,6 +16,7 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
@@ -24,18 +25,31 @@ 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.AfterEach;
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;
+import static org.awaitility.Awaitility.await;
+
@Isolated
@Timeout(60)
public class MulticastParallelTimeout2Test extends ContextTestSupport {
private final Phaser phaser = new Phaser(3);
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@BeforeEach
void sendEarly() {
Assumptions.assumeTrue(context.isStarted(), "The test cannot be run
because the context is not started");
@@ -79,7 +93,8 @@ public class MulticastParallelTimeout2Test extends
ContextTestSupport {
from("direct:a").process(e ->
phaser.arriveAndAwaitAdvance()).to("mock:A").setBody(constant("A"));
- from("direct:b").process(e ->
phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:B").setBody(constant("B"));
+ from("direct:b").process(e ->
phaser.arriveAndAwaitAdvance()).process(e -> release.await(30,
TimeUnit.SECONDS))
+ .to("mock:B").setBody(constant("B"));
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 aef4dbe7cbc3..75dca7dee3d4 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,6 +16,7 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
@@ -24,18 +25,31 @@ 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.AfterEach;
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;
+import static org.awaitility.Awaitility.await;
+
@Isolated
@Timeout(60)
public class MulticastParallelTimeout3Test extends ContextTestSupport {
private final Phaser phaser = new Phaser(3);
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@BeforeEach
void sendEarly() {
Assumptions.assumeTrue(context.isStarted(), "The test cannot be run
because the context is not started");
@@ -81,7 +95,8 @@ public class MulticastParallelTimeout3Test extends
ContextTestSupport {
from("direct:b").process(e ->
phaser.arriveAndAwaitAdvance()).to("mock:B").setBody(constant("B"));
- from("direct:c").process(e ->
phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:C").setBody(constant("C"));
+ from("direct:c").process(e ->
phaser.arriveAndAwaitAdvance()).process(e -> release.await(30,
TimeUnit.SECONDS))
+ .to("mock:C").setBody(constant("C"));
// END SNIPPET: e1
}
};
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutAwareTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutAwareTest.java
index d232f1e83458..a78e8e66538e 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutAwareTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutAwareTest.java
@@ -16,14 +16,19 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -35,6 +40,16 @@ public class MulticastParallelTimeoutAwareTest extends
ContextTestSupport {
private volatile int receivedTotal;
private volatile long receivedTimeout;
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelTimeoutAware() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -61,7 +76,7 @@ public class MulticastParallelTimeoutAwareTest extends
ContextTestSupport {
// use end to indicate end of multicast route
.end().to("mock:result");
- from("direct:a").delay(2000).setBody(constant("A"));
+ from("direct:a").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("A"));
from("direct:b").setBody(constant("B"));
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutTest.java
index b3988a669a7b..6ba99b422f83 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeoutTest.java
@@ -16,17 +16,33 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
+
@Isolated("Short timeouts cause problems with parallel text execution")
public class MulticastParallelTimeoutTest extends ContextTestSupport {
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -62,7 +78,7 @@ public class MulticastParallelTimeoutTest extends
ContextTestSupport {
// use end to indicate end of multicast route
.end().to("mock:result");
-
from("direct:a").delay(1000).to("mock:A").setBody(constant("A"));
+ from("direct:a").process(e -> release.await(30,
TimeUnit.SECONDS)).to("mock:A").setBody(constant("A"));
from("direct:b").to("mock:B").setBody(constant("B"));
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutMiddleTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutMiddleTest.java
index 83337a937528..631299b6e1c1 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutMiddleTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutMiddleTest.java
@@ -16,17 +16,33 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
+
@Isolated("Short timeouts cause problems with parallel text execution")
public class MulticastParallelTwoTimeoutMiddleTest extends ContextTestSupport {
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -68,11 +84,11 @@ public class MulticastParallelTwoTimeoutMiddleTest extends
ContextTestSupport {
from("direct:a").to("mock:A").setBody(constant("A"));
-
from("direct:b").delay(1000).to("mock:B").setBody(constant("B"));
+ from("direct:b").process(e -> release.await(30,
TimeUnit.SECONDS)).to("mock:B").setBody(constant("B"));
from("direct:c").to("mock:C").setBody(constant("C"));
-
from("direct:d").delay(1000).to("mock:D").setBody(constant("D"));
+ from("direct:d").process(e -> release.await(30,
TimeUnit.SECONDS)).to("mock:D").setBody(constant("D"));
from("direct:e").to("mock:E").setBody(constant("E"));
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutTest.java
index 372ab50332fa..d9ad316fc014 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTwoTimeoutTest.java
@@ -16,17 +16,33 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
+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.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import static org.awaitility.Awaitility.await;
+
@Isolated("Does not play well with parallel execution")
public class MulticastParallelTwoTimeoutTest extends ContextTestSupport {
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@Test
public void testMulticastParallelTwoTimeout() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -57,11 +73,11 @@ public class MulticastParallelTwoTimeoutTest 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 -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("A"));
from("direct:b").setBody(constant("B"));
- from("direct:c").delay(500).setBody(constant("C"));
+ from("direct:c").process(e -> release.await(30,
TimeUnit.SECONDS)).setBody(constant("C"));
}
};
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutNoAggregationStrategyTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutNoAggregationStrategyTest.java
index 50c004119c61..65f5dab55657 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutNoAggregationStrategyTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/SplitParallelTimeoutNoAggregationStrategyTest.java
@@ -16,24 +16,38 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.AfterEach;
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;
+import static org.awaitility.Awaitility.await;
+
@Isolated
@Timeout(60)
public class SplitParallelTimeoutNoAggregationStrategyTest extends
ContextTestSupport {
private final Phaser phaser = new Phaser(3);
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@BeforeEach
void sendEarly() {
Assumptions.assumeTrue(context.isStarted(), "The test cannot be run
because the context is not started");
@@ -67,7 +81,8 @@ public class SplitParallelTimeoutNoAggregationStrategyTest
extends ContextTestSu
.end() // end split
.to("mock:result");
- from("direct:a").process(e ->
phaser.arriveAndAwaitAdvance()).delay(200).setBody(constant("A"));
+ from("direct:a").process(e ->
phaser.arriveAndAwaitAdvance()).process(e -> release.await(30,
TimeUnit.SECONDS))
+ .setBody(constant("A"));
from("direct:b").process(e ->
phaser.arriveAndAwaitAdvance()).setBody(constant("B"));
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 574fc73f63f3..5c340872b76e 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.processor;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
@@ -24,12 +25,14 @@ 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.AfterEach;
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.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -43,6 +46,16 @@ public class SplitParallelTimeoutTest extends
ContextTestSupport {
private volatile long receivedTimeout;
private final Phaser phaser = new Phaser(3);
+ // holds the branch that must time out until the test is done: it cannot
complete before the timeout,
+ // and it does not keep the graceful shutdown of the CamelContext waiting
+ private final CountDownLatch release = new CountDownLatch(1);
+
+ @AfterEach
+ void releaseTimedOutBranch() {
+ release.countDown();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
context.getInflightRepository().size() == 0);
+ }
+
@BeforeEach
void sendEarly() {
Assumptions.assumeTrue(context.isStarted(), "The test cannot be run
because the context is not started");
@@ -81,7 +94,8 @@ public class SplitParallelTimeoutTest extends
ContextTestSupport {
.end() // end split
.to("mock:result");
- from("direct:a").process(e ->
phaser.arriveAndAwaitAdvance()).delay(200).setBody(constant("A"));
+ from("direct:a").process(e ->
phaser.arriveAndAwaitAdvance()).process(e -> release.await(30,
TimeUnit.SECONDS))
+ .setBody(constant("A"));
from("direct:b").process(e ->
phaser.arriveAndAwaitAdvance()).setBody(constant("B"));