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

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

commit 65a17aff6dc59f1945ba95284037f5083a3141df
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Mon Nov 16 15:06:40 2026 +0100

    CAMEL-26818: camel-jbang-core - run nearly all the tests in the parallel 
forks, and use less CPU
    
    PR #29701 moved some export, dependency and transform tests to the parallel
    forks, but the serial-test fork still ran 269 tests, and ExportTest alone 
took
    about 60 s locally (104-212 s on Jenkins build 2470, where camel-jbang-core
    took 4:03 to 8:23 min and is on the critical path). The module also used 
about
    10 minutes of CPU on 22 cores for 2 minutes of wall time, which hurts on a 
CI
    machine that already builds other modules with -T1C.
    
    Why the tests were serial, and what replaces it:
    
    - ExportTest was annotated @UsesWorkingDirectory as a class, for 3 tests 
that
      write ./application.properties, and for 6 --console tests that start 
Camel on
      the default port 8080 (@UsesFixedPort in nature). The annotations now 
accept
      a method (@Target TYPE and METHOD), and the tests no longer need them:
      * the 3 tests (and ExportMainJibTest, ExportMainJkubeTest and
        ExportMainApplicationPropertiesTest) write application.properties in a
        temporary base directory of their own and give it as exportBaseDir, so
        they do not touch the module directory the other forks share;
      * the --console tests (and the maven-quarkus-dev case of 
RunExportGoldenTest)
        export with --port=0. The golden file maven-quarkus-dev.maven.txt gets
        quarkus.http.port=0 and quarkus.management.port=0, and nothing else.
    - RunExportGoldenTest has a work directory of its own per test (CamelHome
      .useWorkDir) instead of the shared .camel-jbang, and normalize() maps it 
back
      to .camel-jbang, so the other golden files are unchanged.
    
    The JVM of the forks starts with -XX:TieredStopAtLevel=1 -XX:+UseSerialGC
    (camel.surefire.fork.additional-vmargs). The tests are short and start many
    CamelContexts, so the C1 compiler is enough. Measured on its own, the C1 
flag
    gives the CPU saving and SerialGC adds almost none. A higher forkCount (8, 
12)
    did not help: the serial tail was the bottleneck.
    
    AGENTS.md of the module says that the annotations go on a single method.
    
    Measured locally with taskset, the same machine, port 8080 free, all tests
    green (3310 + 53 after, 3094 + 269 before):
    
                     before          after
      22 CPUs wall   150 s           116 s
      22 CPUs CPU    9 min 52 s      5 min 42 s
      4 CPUs wall    184 s           131 s
      4 CPUs CPU     7 min 57 s      5 min 39 s
    
    What still runs in the serial fork (53 tests): LoadTest, EvalSimpleTest
    (disabled on CI), InfraTest, InfraRestartTest and BaseConfigTestSupport.
    
    Co-authored-by: IBM Bob 2.2.1
    Signed-off-by: AurĂ©lien Pupier <[email protected]>
---
 dsl/camel-jbang/camel-jbang-core/AGENTS.md         |   4 +-
 dsl/camel-jbang/camel-jbang-core/pom.xml           |   4 +
 .../ExportMainApplicationPropertiesTest.java       |  11 +-
 .../dsl/jbang/core/commands/ExportMainJibTest.java |  11 +-
 .../jbang/core/commands/ExportMainJkubeTest.java   |  10 +-
 .../camel/dsl/jbang/core/commands/ExportTest.java  | 130 +++++++++++----------
 .../jbang/core/commands/RunExportGoldenTest.java   |  26 ++++-
 .../dsl/jbang/core/commands/UsesFixedPort.java     |   2 +-
 .../jbang/core/commands/UsesWorkingDirectory.java  |   5 +-
 .../golden/expected/maven-quarkus-dev.maven.txt    |   2 +
 10 files changed, 126 insertions(+), 79 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/AGENTS.md 
b/dsl/camel-jbang/camel-jbang-core/AGENTS.md
index 9fc02a7f5f67..665ddb8aa6f5 100644
--- a/dsl/camel-jbang/camel-jbang-core/AGENTS.md
+++ b/dsl/camel-jbang/camel-jbang-core/AGENTS.md
@@ -22,7 +22,9 @@ reused). So a test must not depend on a fresh JVM, nor share 
anything with the t
   `camel init` writes a file given without a directory there, and a local 
`camel-cli.properties` is read from it. A
   test that listens on a fixed port, such as `camel infra run` with the 
default port of a service, is annotated
   `@UsesFixedPort`. These tests run after the others, one class at a time, in 
a fork of their own (the `serial-test`
-  execution). Prefer a temporary directory (`--dir`) and port 0, so a test 
does not need them.
+  execution). Prefer a temporary directory (`--dir`) and port 0, so a test 
does not need them. Both annotations also
+  go on a single test method: the serial fork is a tail that nothing runs 
beside, so annotate only the methods that
+  need it (as in `ExportTest`), not the whole class, and the other tests of 
the class run in the parallel forks.
 - Restore what else a test changes in the JVM: system properties 
(`@SetSystemProperty` of junit-pioneer, or set and
   clear them), static fields, and stop the servers, threads and CamelContexts 
that it starts.
 - A test that only fails now and then usually shares something with another 
test: run the module a few times with
diff --git a/dsl/camel-jbang/camel-jbang-core/pom.xml 
b/dsl/camel-jbang/camel-jbang-core/pom.xml
index 4abbe5b9a029..ee1c840f6b31 100644
--- a/dsl/camel-jbang/camel-jbang-core/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-core/pom.xml
@@ -45,6 +45,10 @@
         <camel.surefire.forkCount>4</camel.surefire.forkCount>
         <camel.surefire.reuseForks>true</camel.surefire.reuseForks>
         <camel.surefire.parallel>false</camel.surefire.parallel>
+        <!-- the tests are short and start many CamelContexts: the C1 compiler 
only and the serial GC cost far less CPU
+             than the defaults (about 30% less in total), which matters as the 
CI machine runs other modules at the
+             same time -->
+        <camel.surefire.fork.additional-vmargs>-XX:TieredStopAtLevel=1 
-XX:+UseSerialGC</camel.surefire.fork.additional-vmargs>
     </properties>
 
     <dependencies>
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationPropertiesTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationPropertiesTest.java
index 7203f683eb43..96b02406520e 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationPropertiesTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationPropertiesTest.java
@@ -38,23 +38,25 @@ import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
-// writes ./application.properties in the module directory, which the exports 
of the tests in the other forks read
-@UsesWorkingDirectory
 class ExportMainApplicationPropertiesTest {
 
     private File workingDir;
-    private File profile = new File(".", "application.properties");
+    private File baseDir;
+    private File profile;
 
     @BeforeEach
     public void setup() throws IOException {
         workingDir = Files.createTempDirectory("camel-export").toFile();
+        // a base directory of its own: the application.properties of the 
module directory is shared with the other forks
+        baseDir = Files.createTempDirectory("camel-export-base").toFile();
+        profile = new File(baseDir, "application.properties");
     }
 
     @AfterEach
     public void end() throws IOException {
         // force removing, since deleteOnExit is not removing.
         FileUtil.removeDir(workingDir);
-        FileUtil.deleteFile(profile);
+        FileUtil.removeDir(baseDir);
     }
 
     private static Stream<Arguments> runtimeProvider() {
@@ -96,6 +98,7 @@ class ExportMainApplicationPropertiesTest {
 
     private Export createCommand(RuntimeType rt, String[] files, String... 
args) {
         Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir.toPath();
         CommandLineTestHelper.parse(command, "--gav=examples:route:1.0.0", 
"--dir=" + workingDir, "--quiet",
                 "--runtime=%s".formatted(rt.runtime()),
                 CamelCommandBaseTestSupport.quarkusExtRegistry());
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
index d43a0a1975ef..56504900368e 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
@@ -37,11 +37,11 @@ import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
-@UsesWorkingDirectory
 class ExportMainJibTest extends CamelCommandBaseTestSupport {
 
     private File workingDir;
-    private File profile = new File(".", "application.properties");
+    private File baseDir;
+    private File profile;
 
     @BeforeEach
     @Override
@@ -49,13 +49,16 @@ class ExportMainJibTest extends CamelCommandBaseTestSupport 
{
         super.setup();
         useTestWorkDir();
         workingDir = Files.createTempDirectory("camel-export").toFile();
+        // a base directory of its own: the application.properties of the 
module directory is shared with the other forks
+        baseDir = Files.createTempDirectory("camel-export-base").toFile();
+        profile = new File(baseDir, "application.properties");
     }
 
     @AfterEach
     public void end() throws IOException {
         // force removing, since deleteOnExit is not removing.
         FileUtil.removeDir(workingDir);
-        FileUtil.deleteFile(profile);
+        FileUtil.removeDir(baseDir);
     }
 
     private static Stream<Arguments> runtimeProvider() {
@@ -71,6 +74,7 @@ class ExportMainJibTest extends CamelCommandBaseTestSupport {
                 StandardCopyOption.REPLACE_EXISTING);
 
         Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir.toPath();
         CommandLineTestHelper.parse(command, "--gav=examples:route:1.0.0", 
"--dir=" + workingDir,
                 "--runtime=%s".formatted(rt.runtime()), "--java-version=21",
                 CamelCommandBaseTestSupport.quarkusExtRegistry(),
@@ -104,6 +108,7 @@ class ExportMainJibTest extends CamelCommandBaseTestSupport 
{
                 StandardCopyOption.REPLACE_EXISTING);
 
         Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir.toPath();
         CommandLineTestHelper.parse(command, "--gav=examples:route:1.0.0", 
"--dir=" + workingDir,
                 "--runtime=%s".formatted(rt.runtime()),
                 CamelCommandBaseTestSupport.quarkusExtRegistry(),
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java
index e48b70a3d5c0..17fdcb991305 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java
@@ -37,11 +37,11 @@ import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
-@UsesWorkingDirectory
 class ExportMainJkubeTest extends CamelCommandBaseTestSupport {
 
     private File workingDir;
-    private File profile = new File(".", "application.properties");
+    private File baseDir;
+    private File profile;
 
     @BeforeEach
     @Override
@@ -49,13 +49,16 @@ class ExportMainJkubeTest extends 
CamelCommandBaseTestSupport {
         super.setup();
         useTestWorkDir();
         workingDir = Files.createTempDirectory("camel-export").toFile();
+        // a base directory of its own: the application.properties of the 
module directory is shared with the other forks
+        baseDir = Files.createTempDirectory("camel-export-base").toFile();
+        profile = new File(baseDir, "application.properties");
     }
 
     @AfterEach
     public void end() throws IOException {
         // force removing, since deleteOnExit is not removing.
         FileUtil.removeDir(workingDir);
-        FileUtil.deleteFile(profile);
+        FileUtil.removeDir(baseDir);
     }
 
     private static Stream<Arguments> runtimeProvider() {
@@ -71,6 +74,7 @@ class ExportMainJkubeTest extends CamelCommandBaseTestSupport 
{
                 StandardCopyOption.REPLACE_EXISTING);
 
         Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir.toPath();
         CommandLineTestHelper.parse(command, "--gav=examples:route:1.0.0", 
"--dir=" + workingDir,
                 "--runtime=%s".formatted(rt.runtime()),
                 CamelCommandBaseTestSupport.quarkusExtRegistry(),
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
index a9216bd31b6b..d53e413a0aa8 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
@@ -56,7 +56,6 @@ import org.slf4j.LoggerFactory;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-@UsesWorkingDirectory
 class ExportTest extends CamelCommandBaseTestSupport {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(ExportTest.class);
@@ -68,6 +67,7 @@ class ExportTest extends CamelCommandBaseTestSupport {
     private static final String RELEASED_CAMEL_VERSION = "4.13.0";
 
     private File workingDir;
+    private final List<File> baseDirs = new ArrayList<>();
 
     @BeforeEach
     @Override
@@ -82,6 +82,7 @@ class ExportTest extends CamelCommandBaseTestSupport {
     public void end() throws IOException {
         // force removing, since deleteOnExit is not removing.
         FileUtil.removeDir(workingDir);
+        baseDirs.forEach(FileUtil::removeDir);
     }
 
     private static Stream<Arguments> runtimeProvider() {
@@ -1156,10 +1157,15 @@ class ExportTest extends CamelCommandBaseTestSupport {
     }
 
     private int exportWithConsole(RuntimeType rt, String... extraArgs) throws 
Exception {
+        return exportWithConsole(null, rt, extraArgs);
+    }
+
+    private int exportWithConsole(Path baseDir, RuntimeType rt, String... 
extraArgs) throws Exception {
         Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir;
         List<String> cmdArgs = new ArrayList<>(
                 List.of("--gav=examples:route:1.0.0", "--dir=" + workingDir, 
"--quiet",
-                        "--runtime=%s".formatted(rt.runtime()), "--console"));
+                        "--runtime=%s".formatted(rt.runtime()), "--console", 
"--port=0"));
         if (rt == RuntimeType.springBoot) {
             cmdArgs.add("--camel-version=" + RELEASED_CAMEL_VERSION);
         }
@@ -1247,6 +1253,7 @@ class ExportTest extends CamelCommandBaseTestSupport {
                 "--quiet",
                 "--runtime=main",
                 "--console",
+                "--port=0",
                 "src/test/resources/devprofile");
         int exit = command.doCall();
 
@@ -1579,52 +1586,55 @@ class ExportTest extends CamelCommandBaseTestSupport {
     @ValueSource(strings = { "camel.metrics.enabled", 
"camel.management.metricsEnabled", "camel.server.metricsEnabled" })
     void shouldNotDuplicateMetricsDependency(String metricsOption) throws 
Exception {
         LOG.info("shouldNotDuplicateMetricsDependency {}", metricsOption);
-        File profile = new File(".", "application.properties");
-        try {
-            Files.writeString(profile.toPath(), metricsOption + "=true\n");
+        Path baseDir = baseDirWithApplicationProperties(metricsOption + 
"=true\n");
 
-            Export command = new Export(new CamelJBangMain());
-            CommandLineTestHelper.parse(command,
-                    "--gav=examples:route:1.0.0", "--dir=" + workingDir, 
"--quiet",
-                    "--runtime=camel-main",
-                    "src/test/resources/route.yaml");
-            int exit = command.doCall();
+        Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir;
+        CommandLineTestHelper.parse(command,
+                "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet",
+                "--runtime=camel-main",
+                "src/test/resources/route.yaml");
+        int exit = command.doCall();
 
-            assertThat(exit).isEqualTo(0);
-            Model model = readMavenModel();
+        assertThat(exit).isEqualTo(0);
+        Model model = readMavenModel();
 
-            
assertThat(model.getDependencies()).extracting(Dependency::getArtifactId)
-                    .as("the metrics option adds camel-micrometer-prometheus")
-                    .contains("camel-micrometer-prometheus");
-            assertEachArtifactOnce(model);
-        } finally {
-            FileUtil.deleteFile(profile);
-        }
+        
assertThat(model.getDependencies()).extracting(Dependency::getArtifactId)
+                .as("the metrics option adds camel-micrometer-prometheus")
+                .contains("camel-micrometer-prometheus");
+        assertEachArtifactOnce(model);
+    }
+
+    /**
+     * A base directory of its own with the given application.properties, 
instead of the working directory that the
+     * tests of the other forks share.
+     */
+    private Path baseDirWithApplicationProperties(String content) throws 
IOException {
+        Path baseDir = workingDir.toPath().resolveSibling(workingDir.getName() 
+ "-base");
+        Files.createDirectories(baseDir);
+        baseDirs.add(baseDir.toFile());
+        Files.writeString(baseDir.resolve("application.properties"), content);
+        return baseDir;
     }
 
     @ParameterizedTest
     @MethodSource("runtimeProvider")
     void shouldNotDuplicateConsoleDependencies(RuntimeType rt) throws 
Exception {
         LOG.info("shouldNotDuplicateConsoleDependencies {}", rt);
-        File profile = new File(".", "application.properties");
-        try {
-            // a project that has the console options itself, exported with 
--console: the dependencies of the
-            // console are added for the options and for the flag
-            Files.writeString(profile.toPath(), """
-                    camel.management.devConsoleEnabled=true
-                    camel.management.healthCheckEnabled=true
-                    camel.management.jolokiaEnabled=true
-                    """);
-            int exit = exportWithConsole(rt);
-
-            assertThat(exit).isEqualTo(0);
-            Model model = readMavenModel();
+        // a project that has the console options itself, exported with 
--console: the dependencies of the
+        // console are added for the options and for the flag
+        Path baseDir = baseDirWithApplicationProperties("""
+                camel.management.devConsoleEnabled=true
+                camel.management.healthCheckEnabled=true
+                camel.management.jolokiaEnabled=true
+                """);
+        int exit = exportWithConsole(baseDir, rt);
 
-            assertConsoleDependencies(model, rt);
-            assertEachArtifactOnce(model);
-        } finally {
-            FileUtil.deleteFile(profile);
-        }
+        assertThat(exit).isEqualTo(0);
+        Model model = readMavenModel();
+
+        assertConsoleDependencies(model, rt);
+        assertEachArtifactOnce(model);
     }
 
     private static Stream<Arguments> consoleArtifactProvider() {
@@ -1660,31 +1670,27 @@ class ExportTest extends CamelCommandBaseTestSupport {
         // camel-spring-boot 4.19+ requires JDK 21 (Spring Boot 4), as 
runtimeProvider has it
         Assumptions.assumeTrue(Runtime.version().feature() >= 21, 
"camel-spring-boot requires JDK 21");
 
-        File profile = new File(".", "application.properties");
-        try {
-            // a profile, so the exported project has an 
application.properties to read
-            Files.writeString(profile.toPath(), 
"camel.main.name=platform-http-demo\n");
-
-            // --dep=camel-platform-http becomes camel:platform-http, and it 
is the HTTP server of the exported
-            // project, so the run controller is not needed to keep it alive
-            Export command = new Export(new CamelJBangMain());
-            CommandLineTestHelper.parse(command,
-                    "--gav=examples:route:1.0.0", "--dir=" + workingDir, 
"--quiet",
-                    "--runtime=spring-boot", "--camel-version=" + 
RELEASED_CAMEL_VERSION,
-                    CamelCommandBaseTestSupport.quarkusExtRegistry(),
-                    "--dep=camel-platform-http",
-                    "src/test/resources/route.yaml");
-            int exit = command.doCall();
+        // a profile, so the exported project has an application.properties to 
read
+        Path baseDir = 
baseDirWithApplicationProperties("camel.main.name=platform-http-demo\n");
 
-            assertThat(exit).isEqualTo(0);
-            Properties props = 
loadExportedProperties("application.properties");
-            assertThat(exportedProperty(props, "camel.main.run-controller"))
-                    .as("the export has an HTTP server of its own")
-                    .isNull();
-            assertEachArtifactOnce(readMavenModel());
-        } finally {
-            FileUtil.deleteFile(profile);
-        }
+        // --dep=camel-platform-http becomes camel:platform-http, and it is 
the HTTP server of the exported
+        // project, so the run controller is not needed to keep it alive
+        Export command = new Export(new CamelJBangMain());
+        command.exportBaseDir = baseDir;
+        CommandLineTestHelper.parse(command,
+                "--gav=examples:route:1.0.0", "--dir=" + workingDir, "--quiet",
+                "--runtime=spring-boot", "--camel-version=" + 
RELEASED_CAMEL_VERSION,
+                CamelCommandBaseTestSupport.quarkusExtRegistry(),
+                "--dep=camel-platform-http",
+                "src/test/resources/route.yaml");
+        int exit = command.doCall();
+
+        assertThat(exit).isEqualTo(0);
+        Properties props = loadExportedProperties("application.properties");
+        assertThat(exportedProperty(props, "camel.main.run-controller"))
+                .as("the export has an HTTP server of its own")
+                .isNull();
+        assertEachArtifactOnce(readMavenModel());
     }
 
     @Test
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExportGoldenTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExportGoldenTest.java
index a7a686ac7fba..dd15cbdfeca7 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExportGoldenTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExportGoldenTest.java
@@ -39,10 +39,12 @@ import 
org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.apache.camel.dsl.jbang.core.common.CommandLineTestHelper;
 import org.apache.camel.dsl.jbang.run.ConfiguredRun;
 import org.apache.camel.dsl.jbang.run.RunContext;
+import org.apache.camel.dsl.jbang.run.common.CamelHome;
 import org.apache.camel.dsl.jbang.run.common.ExportHelper;
 import org.apache.camel.dsl.jbang.run.common.PathUtils;
 import org.apache.camel.dsl.jbang.run.common.RuntimeType;
 import org.apache.camel.main.KameletMain;
+import org.apache.camel.util.FileUtil;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -65,7 +67,6 @@ import static org.assertj.core.api.Assertions.assertThat;
  * src/test/resources/golden/expected. Run with -Dcamel.golden.update=true to 
write the expected files again, and review
  * the difference.
  */
-@UsesWorkingDirectory
 class RunExportGoldenTest {
 
     private static final Path GOLDEN = Path.of("src/test/resources/golden");
@@ -76,6 +77,22 @@ class RunExportGoldenTest {
     // them, so a property that another test left set does not change the 
output
     private final Map<String, String> camelProperties = new TreeMap<>();
 
+    // a work directory of its own, so the test does not share .camel-jbang 
with the tests of the other forks. The
+    // expected files have the default one, which normalize() puts back
+    private Path testWorkDir;
+
+    @BeforeEach
+    void useWorkDirOfItsOwn() throws Exception {
+        testWorkDir = Files.createTempDirectory("camel-jbang-work");
+        CamelHome.useWorkDir(testWorkDir);
+    }
+
+    @AfterEach
+    void resetWorkDirOfItsOwn() {
+        CamelHome.resetWorkDir();
+        FileUtil.removeDir(testWorkDir.toFile());
+    }
+
     @BeforeEach
     void clearCamelSystemProperties() {
         for (String key : System.getProperties().stringPropertyNames()) {
@@ -298,7 +315,7 @@ class RunExportGoldenTest {
                 new MavenCase("maven-quarkus", files("yaml/hello.camel.yaml"), 
List.of("--runtime=quarkus"), false),
                 new MavenCase(
                         "maven-quarkus-dev", files("yaml/hello.camel.yaml"),
-                        List.of("--runtime=quarkus", "--dev", "--console"), 
false),
+                        List.of("--runtime=quarkus", "--dev", "--console", 
"--port=0"), false),
                 // a released Camel, as the catalog of camel-spring-boot is 
not built with this one
                 new MavenCase(
                         "maven-spring-boot", files("yaml/hello.camel.yaml"),
@@ -502,9 +519,12 @@ class RunExportGoldenTest {
      * Replaces what differs from one machine or build to another: the 
directories, and the versions that the build
      * brings (of Camel, Spring Boot and the Kamelets), so that a version 
upgrade does not change the expected output.
      */
-    private static String normalize(String text, Path dir) throws Exception {
+    private String normalize(String text, Path dir) throws Exception {
         String answer = text;
         Map<String, String> replacements = new LinkedHashMap<>();
+        // the work directory of the test is the default one (.camel-jbang) in 
the expected files
+        replacements.put(testWorkDir.toRealPath().toString(), ".camel-jbang");
+        replacements.put(testWorkDir.toAbsolutePath().toString(), 
".camel-jbang");
         replacements.put(dir.toRealPath().toString(), "${dir}");
         replacements.put(dir.toAbsolutePath().toString(), "${dir}");
         // the home of the CLI of the tests, which differs per test execution
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesFixedPort.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesFixedPort.java
index f312a176b172..77e5a71f91a7 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesFixedPort.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesFixedPort.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.Tag;
  * The test forks run in parallel, and two tests on the same port fail to 
bind, so these tests run after them in a fork
  * of their own, one class at a time (the {@code serial-test} execution in 
pom.xml).
  */
-@Target(ElementType.TYPE)
+@Target({ ElementType.TYPE, ElementType.METHOD })
 @Retention(RetentionPolicy.RUNTIME)
 @Inherited
 @Tag("serial")
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesWorkingDirectory.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesWorkingDirectory.java
index 9fb024310c7e..5dabad0659f1 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesWorkingDirectory.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UsesWorkingDirectory.java
@@ -30,9 +30,10 @@ import org.junit.jupiter.api.Tag;
  * {@code ./application.properties} file in the module directory.
  * <p/>
  * The test forks run in parallel and share the working directory, so these 
tests run after them in a fork of their own,
- * one class at a time (the {@code serial-test} execution in pom.xml).
+ * one class at a time (the {@code serial-test} execution in pom.xml). On a 
method, only that test runs there and the
+ * other tests of the class run in the parallel forks.
  */
-@Target(ElementType.TYPE)
+@Target({ ElementType.TYPE, ElementType.METHOD })
 @Retention(RetentionPolicy.RUNTIME)
 @Inherited
 @Tag("serial")
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/maven-quarkus-dev.maven.txt
 
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/maven-quarkus-dev.maven.txt
index 4588c80aefec..daf6939cb2b4 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/maven-quarkus-dev.maven.txt
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/maven-quarkus-dev.maven.txt
@@ -47,6 +47,8 @@ plugin org.apache.maven.plugins:maven-failsafe-plugin
 
 # application.properties
 camel.main.name=hello
+quarkus.http.port=0
+quarkus.management.port=0
 camel.main.dev-console-enabled=true
 camel.main.profile=dev
 

Reply via email to