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 9014f4436d2 CAMEL-20158 await executor termination after shutdown (#12291) 9014f4436d2 is described below commit 9014f4436d2d1c8ae5ab0fca942f447a32f7eb68 Author: Jono Morris <j...@apache.org> AuthorDate: Sat Dec 2 04:14:02 2023 +1300 CAMEL-20158 await executor termination after shutdown (#12291) --- .../org/apache/camel/processor/ThrottlerTest.java | 23 ++++++++++++++-------- .../camel/processor/ThrottlingGroupingTest.java | 17 ++++++++++++---- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerTest.java index 7072bb1d110..b49770d1f13 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; // time-bound that does not run well in shared environments @DisabledOnOs(OS.WINDOWS) @@ -56,8 +57,7 @@ public class ThrottlerTest extends ContextTestSupport { } assertMockEndpointsSatisfied(); } finally { - executor.awaitTermination(1000, TimeUnit.MILLISECONDS); - executor.shutdownNow(); + shutdownAndAwait(executor); } } @@ -84,8 +84,7 @@ public class ThrottlerTest extends ContextTestSupport { try { sendMessagesWithHeaderExpression(executor, resultEndpoint, CONCURRENT_REQUESTS, MESSAGE_COUNT); } finally { - executor.awaitTermination(1000, TimeUnit.MILLISECONDS); - executor.shutdownNow(); + shutdownAndAwait(executor); } } @@ -114,8 +113,7 @@ public class ThrottlerTest extends ContextTestSupport { resultEndpoint.reset(); sendMessagesWithHeaderExpression(executor, resultEndpoint, 4, MESSAGE_COUNT); } finally { - executor.awaitTermination(1000, TimeUnit.MILLISECONDS); - executor.shutdownNow(); + shutdownAndAwait(executor); } } @@ -156,8 +154,7 @@ public class ThrottlerTest extends ContextTestSupport { receivingEndpoint.assertIsSatisfied(); } } finally { - executor.awaitTermination(1000, TimeUnit.MILLISECONDS); - executor.shutdownNow(); + shutdownAndAwait(executor); } } @@ -185,6 +182,16 @@ public class ThrottlerTest extends ContextTestSupport { .forEach(b -> template.sendBody(endpoint, b)); } + private void shutdownAndAwait(final ExecutorService executorService) { + executorService.shutdown(); + try { + assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS), + "Test ExecutorService shutdown is not expected to take longer than 10 seconds."); + } catch (InterruptedException e) { + fail("Test ExecutorService shutdown is not expected to be interrupted."); + } + } + @Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlingGroupingTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlingGroupingTest.java index 2c11829333c..8639310ecdf 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlingGroupingTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlingGroupingTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Isolated; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @Isolated public class ThrottlingGroupingTest extends ContextTestSupport { @@ -109,8 +110,7 @@ public class ThrottlingGroupingTest extends ContextTestSupport { receivingEndpoint.assertIsSatisfied(); } } finally { - executor.awaitTermination(1000, TimeUnit.MILLISECONDS); - executor.shutdownNow(); + shutdownAndAwait(executor); } } @@ -123,8 +123,7 @@ public class ThrottlingGroupingTest extends ContextTestSupport { try { sendMessagesWithHeaderExpression(executor, resultEndpoint, CONCURRENT_REQUESTS, MESSAGE_COUNT); } finally { - executor.awaitTermination(1000, TimeUnit.MILLISECONDS); - executor.shutdownNow(); + shutdownAndAwait(executor); } } @@ -152,6 +151,16 @@ public class ThrottlingGroupingTest extends ContextTestSupport { resultEndpoint.assertIsSatisfied(); } + private void shutdownAndAwait(final ExecutorService executorService) { + executorService.shutdown(); + try { + assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS), + "Test ExecutorService shutdown is not expected to take longer than 10 seconds."); + } catch (InterruptedException e) { + fail("Test ExecutorService shutdown is not expected to be interrupted."); + } + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() {