From 162f59eab9b100a7f6d09b041d943aebff911260 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 27 Mar 2026 00:00:50 +0100 Subject: [PATCH 1/4] test-infra: Fix Docker container name collisions in parallel builds Append the JVM PID to generated Docker container names to avoid 409 Conflict errors when multiple modules sharing the same test infrastructure (e.g., camel-elasticsearch and camel-elasticsearch-rest-client) run integration tests in parallel via mvnd. Co-Authored-By: Claude Opus 4.6 --- .../test/infra/common/services/ContainerEnvironmentUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java index 689e6ef7fb67c..4e36f79fcdf65 100644 --- a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java +++ b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java @@ -114,6 +114,9 @@ public static String containerName(Class cls) { if (annotation.serviceImplementationAlias().length > 0) { name += "-" + annotation.serviceImplementationAlias()[0]; } + // Append PID to avoid Docker container name conflicts when multiple + // modules run tests in parallel (e.g., via mvnd with multiple threads) + name += "-" + ProcessHandle.current().pid(); } else { LOG.warn("InfraService annotation not Found to determine container name alias."); } From 60f9f48265d7eadc050580a2014ac407175f55fa Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 27 Mar 2026 11:05:17 +0100 Subject: [PATCH 2/4] test-infra: Fix misleading comment - it's separate JVMs, not threads Co-Authored-By: Claude Opus 4.6 --- .../test/infra/common/services/ContainerEnvironmentUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java index 4e36f79fcdf65..6209e98892b9d 100644 --- a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java +++ b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java @@ -115,7 +115,7 @@ public static String containerName(Class cls) { name += "-" + annotation.serviceImplementationAlias()[0]; } // Append PID to avoid Docker container name conflicts when multiple - // modules run tests in parallel (e.g., via mvnd with multiple threads) + // modules run tests in separate JVMs (e.g., via mvnd parallel builds) name += "-" + ProcessHandle.current().pid(); } else { LOG.warn("InfraService annotation not Found to determine container name alias."); From 5ea6a8005e95eb3f35be4a41be533be10ca43d98 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 27 Mar 2026 11:52:08 +0100 Subject: [PATCH 3/4] test-infra: Add within-JVM uniqueness and fix RocketMQ hardcoded name - Add AtomicInteger counter alongside PID for within-JVM uniqueness, making container names safe for parallel test class execution - Remove hardcoded withName("nameserver") in RocketMQNameserverContainer that bypassed ContainerEnvironmentUtil (the network alias "nameserver" is sufficient for inter-container communication) Co-Authored-By: Claude Opus 4.6 --- .../infra/common/services/ContainerEnvironmentUtil.java | 8 +++++--- .../rocketmq/services/RocketMQNameserverContainer.java | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java index 6209e98892b9d..5aa3da48a3942 100644 --- a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java +++ b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; import com.github.dockerjava.api.model.Version; import com.github.dockerjava.api.model.VersionComponent; @@ -35,6 +36,7 @@ public final class ContainerEnvironmentUtil { public static final String INFRA_PORT_PROPERTY = "camel.infra.port"; public static final String INFRA_FIXED_PORT_PROPERTY = "camel.infra.fixedPort"; private static final Logger LOG = LoggerFactory.getLogger(ContainerEnvironmentUtil.class); + private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger(0); private static boolean dockerAvailable; private static boolean environmentCheckState; @@ -114,9 +116,9 @@ public static String containerName(Class cls) { if (annotation.serviceImplementationAlias().length > 0) { name += "-" + annotation.serviceImplementationAlias()[0]; } - // Append PID to avoid Docker container name conflicts when multiple - // modules run tests in separate JVMs (e.g., via mvnd parallel builds) - name += "-" + ProcessHandle.current().pid(); + // Append PID for cross-JVM uniqueness (parallel builds via mvnd) + // and instance counter for within-JVM uniqueness (parallel test classes) + name += "-" + ProcessHandle.current().pid() + "-" + INSTANCE_COUNTER.incrementAndGet(); } else { LOG.warn("InfraService annotation not Found to determine container name alias."); } diff --git a/test-infra/camel-test-infra-rocketmq/src/main/java/org/apache/camel/test/infra/rocketmq/services/RocketMQNameserverContainer.java b/test-infra/camel-test-infra-rocketmq/src/main/java/org/apache/camel/test/infra/rocketmq/services/RocketMQNameserverContainer.java index a0b7aaaef8372..e3fcf19fcdc17 100644 --- a/test-infra/camel-test-infra-rocketmq/src/main/java/org/apache/camel/test/infra/rocketmq/services/RocketMQNameserverContainer.java +++ b/test-infra/camel-test-infra-rocketmq/src/main/java/org/apache/camel/test/infra/rocketmq/services/RocketMQNameserverContainer.java @@ -32,7 +32,6 @@ public RocketMQNameserverContainer(Network network) { addExposedPort(RocketMQProperties.ROCKETMQ_NAMESRV_PORT); withTmpFs(Collections.singletonMap("/home/rocketmq/logs", "rw")); withCommand("sh", "mqnamesrv"); - withCreateContainerCmdModifier(cmd -> cmd.withName("nameserver")); waitingFor(Wait.forListeningPort()); } From c00970789b00510dcb6ad85487af686e8f4eee3f Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 27 Mar 2026 15:19:25 +0100 Subject: [PATCH 4/4] test-infra: Keep clean container names for camel infra run Skip PID+counter suffix when camel.infra.fixedPort=true (set by camel infra run) so containers get predictable names like camel-postgres for docker exec usability. Co-Authored-By: Claude Opus 4.6 --- .../infra/common/services/ContainerEnvironmentUtil.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java index 5aa3da48a3942..69cdf3a32ba84 100644 --- a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java +++ b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java @@ -116,9 +116,11 @@ public static String containerName(Class cls) { if (annotation.serviceImplementationAlias().length > 0) { name += "-" + annotation.serviceImplementationAlias()[0]; } - // Append PID for cross-JVM uniqueness (parallel builds via mvnd) - // and instance counter for within-JVM uniqueness (parallel test classes) - name += "-" + ProcessHandle.current().pid() + "-" + INSTANCE_COUNTER.incrementAndGet(); + // In fixed port mode (camel infra run), use clean names for docker exec usability + // Otherwise, append PID + counter for cross-JVM and within-JVM uniqueness + if (!Boolean.parseBoolean(System.getProperty(INFRA_FIXED_PORT_PROPERTY, "false"))) { + name += "-" + ProcessHandle.current().pid() + "-" + INSTANCE_COUNTER.incrementAndGet(); + } } else { LOG.warn("InfraService annotation not Found to determine container name alias."); }