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 5cf0c939ab83 CAMEL-27095: camel-core - shorter test time, round 3 
(#30316)
5cf0c939ab83 is described below

commit 5cf0c939ab83d3ada50d12bdb0147c66a3950410
Author: Adriano Machado <[email protected]>
AuthorDate: Thu Nov 19 08:32:19 2026 -0500

    CAMEL-27095: camel-core - shorter test time, round 3 (#30316)
    
    The JUnit ForkJoinPool saturated (512 threads, none running, 1000+ queued
    classes): TestSupport reads the system properties under a ResourceLock, and 
a
    class writing them queued for the write lock, which ReentrantReadWriteLock
    makes every later reader wait behind, until the longest running class ended.
    The 6 classes writing system properties are now @Isolated, and run in the
    serial tail for 0.1 s in all.
    
    Without these stalls, the classes ran 4 at a time: the bursts of 
compensation
    threads that followed each stall were what made the run fast. The tests 
mostly
    wait, so the parallelism goes from 4 to 32.
    
    The serial tail is shorter too:
    - RouteStopCutOffLogTest: the processed cut-off tests use a 1 s shutdown
      timeout like the other tests of the class (19 s to 7 s)
    - requests.ThrottlingGroupingTest: the route holding the throttled messages
      is stopped at the end of the test, instead of the shutdown waiting 5 s
    - FileChangedReadLockTest and subclasses, FutureConverterTest and
      FileConsumerRestartNotLeakThreadTest wait for the exchange in flight,
      instead of the shutdown polling for it for 1 s
    
    Locally (18 cores) mvn test of camel-core went from 125-148 s to 97 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._
    
    The classes that are @Isolated no longer also take 
@ResourceLock(SYSTEM_PROPERTIES).
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
    Co-authored-by: Claude Sonnet 5.5 <[email protected]>
---
 .../test/java/org/apache/camel/builder/xml/XPathFeatureTest.java | 5 ++---
 .../component/file/FileConsumerRestartNotLeakThreadTest.java     | 5 +++++
 .../camel/component/file/strategy/FileChangedReadLockTest.java   | 9 +++++++++
 .../properties/PropertiesComponentConcatenatePropertiesTest.java | 5 ++---
 .../properties/PropertiesComponentDefaultFunctionsTest.java      | 5 ++---
 .../java/org/apache/camel/converter/FutureConverterTest.java     | 5 +++++
 .../org/apache/camel/impl/engine/CreateContextValueTest.java     | 5 ++---
 .../language/simple/functions/SystemFunctionFactoryTest.java     | 2 ++
 .../camel/processor/errorhandler/RouteStopCutOffLogTest.java     | 6 +++---
 .../processor/throttle/requests/ThrottlingGroupingTest.java      | 7 ++++++-
 .../test/java/org/apache/camel/util/FilePathResolverTest.java    | 5 ++---
 core/camel-core/src/test/resources/junit-platform.properties     | 3 ++-
 12 files changed, 42 insertions(+), 20 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
index 2422701d920e..d28bb40e39bb 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
@@ -33,8 +33,7 @@ import org.apache.camel.TypeConversionException;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.language.xpath.XPathBuilder;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
+import org.junit.jupiter.api.parallel.Isolated;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.camel.language.xpath.XPathBuilder.xpath;
@@ -42,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.*;
 
-@ResourceLock(Resources.SYSTEM_PROPERTIES)
+@Isolated("Writes system properties: as a lock writer among the concurrent 
tests, it would hold back every test reading them until the longest one ends")
 public class XPathFeatureTest extends ContextTestSupport {
     public static final String DOM_BUILDER_FACTORY_FEATURE = 
XmlConverter.DOCUMENT_BUILDER_FACTORY_FEATURE;
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerRestartNotLeakThreadTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerRestartNotLeakThreadTest.java
index ca109c04981d..86d0f8e03877 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerRestartNotLeakThreadTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerRestartNotLeakThreadTest.java
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 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.assertTrue;
 
 @Isolated
@@ -34,6 +37,8 @@ public class FileConsumerRestartNotLeakThreadTest extends 
ContextTestSupport {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
         template.sendBodyAndHeader(fileUri(), "Hello World", 
Exchange.FILE_NAME, "hello.txt");
         assertMockEndpointsSatisfied();
+        // the mock is satisfied before the file consumer commits the 
exchange, which stopping the route would wait for
+        await().atMost(5, TimeUnit.SECONDS).until(() -> 
context.getInflightRepository().size() == 0);
 
         for (int i = 0; i < 50; i++) {
             context.getRouteController().stopRoute("foo");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockTest.java
index 69e6432bbb07..b79c7ac60ef6 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockTest.java
@@ -18,17 +18,20 @@ package org.apache.camel.component.file.strategy;
 
 import java.io.OutputStream;
 import java.nio.file.Files;
+import java.util.concurrent.TimeUnit;
 
 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.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.parallel.Isolated;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 @Isolated("Does not play well with parallel unit test execution")
@@ -43,6 +46,12 @@ public class FileChangedReadLockTest extends 
ContextTestSupport {
         super.setUp();
     }
 
+    @AfterEach
+    void waitForTheFileCommit() {
+        // the mock is satisfied before the file consumer commits the 
exchange, which the shutdown would wait for
+        await().atMost(5, TimeUnit.SECONDS).until(() -> 
context.getInflightRepository().size() == 0);
+    }
+
     @Test
     public void testChangedReadLock() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java
index e6e3ac78ce22..9e87b249ce3c 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java
@@ -22,10 +22,9 @@ import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
+import org.junit.jupiter.api.parallel.Isolated;
 
-@ResourceLock(Resources.SYSTEM_PROPERTIES)
+@Isolated("Writes system properties: as a lock writer among the concurrent 
tests, it would hold back every test reading them until the longest one ends")
 public class PropertiesComponentConcatenatePropertiesTest extends 
ContextTestSupport {
     @Override
     protected CamelContext createCamelContext() throws Exception {
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
index bb667695052a..cda296b5bc6c 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
@@ -21,10 +21,9 @@ import java.util.Map;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
+import org.junit.jupiter.api.parallel.Isolated;
 
-@ResourceLock(Resources.SYSTEM_PROPERTIES)
+@Isolated("Writes system properties: as a lock writer among the concurrent 
tests, it would hold back every test reading them until the longest one ends")
 public class PropertiesComponentDefaultFunctionsTest extends 
ContextTestSupport {
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/converter/FutureConverterTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/converter/FutureConverterTest.java
index a059ea5cbdcc..bab040030c49 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/converter/FutureConverterTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/converter/FutureConverterTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.converter;
 import java.sql.Timestamp;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -29,6 +30,7 @@ import org.apache.camel.support.DefaultExchange;
 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.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -89,6 +91,9 @@ public class FutureConverterTest extends ContextTestSupport {
         Object out = context.getTypeConverter().convertTo(String.class, 
future);
         // should be null since its cancelled
         assertNull(out);
+
+        // cancelling the future does not stop the exchange: let it complete, 
so the shutdown does not wait for it
+        await().atMost(5, TimeUnit.SECONDS).until(() -> 
context.getInflightRepository().size() == 0);
     }
 
     @Test
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CreateContextValueTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CreateContextValueTest.java
index e9a3f3b6f1af..f12bd8939191 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CreateContextValueTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CreateContextValueTest.java
@@ -24,8 +24,7 @@ import org.apache.camel.util.concurrent.ThreadType;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledForJreRange;
 import org.junit.jupiter.api.condition.JRE;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
+import org.junit.jupiter.api.parallel.Isolated;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -33,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
  * CAMEL-24320: {@link ExtendedCamelContext#getCreateRoute()} and {@link 
ExtendedCamelContext#getCreateProcessor()} must
  * return null outside a binding scope (used by Kamelet endpoint init).
  */
+@Isolated("Writes system properties: as a lock writer among the concurrent 
tests, it would hold back every test reading them until the longest one ends")
 class CreateContextValueTest {
 
     private static final String VIRTUAL_THREADS_PROPERTY = 
"camel.threads.virtual.enabled";
@@ -54,7 +54,6 @@ class CreateContextValueTest {
     }
 
     @EnabledForJreRange(min = JRE.JAVA_25)
-    @ResourceLock(Resources.SYSTEM_PROPERTIES)
     @Test
     void getCreateRouteDoesNotThrowWithVirtualThreadsEnabled() throws 
Exception {
         enableVirtualThreads();
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/functions/SystemFunctionFactoryTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/functions/SystemFunctionFactoryTest.java
index bdb28fd1ac6f..fe58b0703302 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/functions/SystemFunctionFactoryTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/functions/SystemFunctionFactoryTest.java
@@ -18,10 +18,12 @@ package org.apache.camel.language.simple.functions;
 
 import org.apache.camel.spi.SimpleLanguageFunctionFactory;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
 import org.junitpioneer.jupiter.SetSystemProperty;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+@Isolated("Writes system properties: as a lock writer among the concurrent 
tests, it would hold back every test reading them until the longest one ends")
 public class SystemFunctionFactoryTest extends 
AbstractSimpleFunctionFactoryTestSupport {
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
index 69c39f46abd0..67aca370e60e 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
@@ -152,7 +152,7 @@ public class RouteStopCutOffLogTest extends 
ContextTestSupport {
         // Use a bounded shutdown timeout so that stopRoute force-stops the 
route (stopping its
         // error handlers) after the timeout, since the inflight exchange will 
not complete on its own.
         // Using direct: (not seda:) ensures the route stop does not interrupt 
the processing thread.
-        context.getShutdownStrategy().setTimeout(5);
+        context.getShutdownStrategy().setTimeout(1);
         context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);
 
         CompletableFuture<Exchange> future = 
template.asyncSend("direct:start", exchange -> {
@@ -184,7 +184,7 @@ public class RouteStopCutOffLogTest extends 
ContextTestSupport {
     @Test
     public void processedCutOffIsNotInTheErrorRegistry() throws Exception {
         context.getErrorRegistry().setEnabled(true);
-        context.getShutdownStrategy().setTimeout(5);
+        context.getShutdownStrategy().setTimeout(1);
         context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);
 
         template.asyncSend("direct:start", exchange -> 
exchange.getIn().setBody(List.of("A")));
@@ -202,7 +202,7 @@ public class RouteStopCutOffLogTest extends 
ContextTestSupport {
     public void processedCutOffIsInTheErrorRegistryWhenIncluded() throws 
Exception {
         context.getErrorRegistry().setEnabled(true);
         context.getErrorRegistry().setIncludeRouteStopping(true);
-        context.getShutdownStrategy().setTimeout(5);
+        context.getShutdownStrategy().setTimeout(1);
         context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);
 
         template.asyncSend("direct:start", exchange -> 
exchange.getIn().setBody(List.of("A")));
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
index 045823962f87..5ece231d3985 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
@@ -95,6 +95,10 @@ public class ThrottlingGroupingTest extends 
ContextTestSupport {
         }
 
         resultEndpoint.assertIsSatisfied();
+
+        // the throttler holds the 3 other messages until the time period has 
elapsed: stop the route without waiting
+        // for them, or the shutdown of the CamelContext would wait for them
+        context.getRouteController().stopRoute("ga", 100, 
TimeUnit.MILLISECONDS);
     }
 
     private void assertThrottlerTiming(
@@ -218,7 +222,8 @@ public class ThrottlingGroupingTest extends 
ContextTestSupport {
                 from("seda:b").throttle(header("max"), 2).to("mock:result2");
                 
from("seda:c").throttle(header("max")).correlationExpression(header("key")).to("mock:resultdynamic");
 
-                from("seda:ga").throttle(constant(3), 
header("key")).timePeriodMillis(5000).to("log:gresult", "mock:gresult");
+                from("seda:ga").routeId("ga").throttle(constant(3), 
header("key")).timePeriodMillis(5000).to("log:gresult",
+                        "mock:gresult");
 
                 from("direct:ga").throttle(constant(5), 
header("key")).timePeriodMillis(INTERVAL).to("log:gresult",
                         "mock:gresult");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java 
b/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
index 8372f326961c..4e773f438b91 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
@@ -17,15 +17,14 @@
 package org.apache.camel.util;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
+import org.junit.jupiter.api.parallel.Isolated;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+@Isolated("Writes system properties: as a lock writer among the concurrent 
tests, it would hold back every test reading them until the longest one ends")
 public class FilePathResolverTest {
 
     @Test
-    @ResourceLock(Resources.SYSTEM_PROPERTIES)
     public void testFilePathResolver() {
         assertEquals("/foo/bar", FilePathResolver.resolvePath("/foo/bar"));
 
diff --git a/core/camel-core/src/test/resources/junit-platform.properties 
b/core/camel-core/src/test/resources/junit-platform.properties
index 60d8fad77c4c..45b59eebc4b3 100644
--- a/core/camel-core/src/test/resources/junit-platform.properties
+++ b/core/camel-core/src/test/resources/junit-platform.properties
@@ -19,7 +19,8 @@ junit.jupiter.execution.parallel.enabled = true
 junit.jupiter.execution.parallel.mode.default = same_thread
 junit.jupiter.execution.parallel.mode.classes.default = concurrent
 junit.jupiter.execution.parallel.config.strategy = custom
-junit.jupiter.execution.parallel.config.custom.parallelism = 4
+# the tests mostly wait (timers, latches, timeouts) rather than use the CPU, 
so many of them can run at once
+junit.jupiter.execution.parallel.config.custom.parallelism = 32
 junit.jupiter.execution.parallel.config.custom.maxPoolSize = 512
 
junit.jupiter.execution.parallel.config.custom.class=org.apache.camel.CamelParallelExecutionStrategy
 junit.jupiter.execution.parallel.config.executor-service = FORK_JOIN_POOL

Reply via email to