Skip to content

Commit 882e6bd

Browse files
authored
test-infra: Fix Docker container name collisions in parallel execution
- Append PID + AtomicInteger counter to container names in ContainerEnvironmentUtil.containerName() for cross-JVM (mvnd) and within-JVM (parallel test classes) uniqueness - Skip the suffix when camel.infra.fixedPort=true (camel infra run) to preserve clean names like camel-postgres for docker exec usability - Remove hardcoded withName("nameserver") from RocketMQNameserverContainer that bypassed ContainerEnvironmentUtil (network alias is sufficient)
1 parent 79fbb87 commit 882e6bd

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/services/ContainerEnvironmentUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Arrays;
2222
import java.util.List;
2323
import java.util.Objects;
24+
import java.util.concurrent.atomic.AtomicInteger;
2425

2526
import com.github.dockerjava.api.model.Version;
2627
import com.github.dockerjava.api.model.VersionComponent;
@@ -35,6 +36,7 @@ public final class ContainerEnvironmentUtil {
3536
public static final String INFRA_PORT_PROPERTY = "camel.infra.port";
3637
public static final String INFRA_FIXED_PORT_PROPERTY = "camel.infra.fixedPort";
3738
private static final Logger LOG = LoggerFactory.getLogger(ContainerEnvironmentUtil.class);
39+
private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger(0);
3840

3941
private static boolean dockerAvailable;
4042
private static boolean environmentCheckState;
@@ -114,6 +116,11 @@ public static String containerName(Class cls) {
114116
if (annotation.serviceImplementationAlias().length > 0) {
115117
name += "-" + annotation.serviceImplementationAlias()[0];
116118
}
119+
// In fixed port mode (camel infra run), use clean names for docker exec usability
120+
// Otherwise, append PID + counter for cross-JVM and within-JVM uniqueness
121+
if (!Boolean.parseBoolean(System.getProperty(INFRA_FIXED_PORT_PROPERTY, "false"))) {
122+
name += "-" + ProcessHandle.current().pid() + "-" + INSTANCE_COUNTER.incrementAndGet();
123+
}
117124
} else {
118125
LOG.warn("InfraService annotation not Found to determine container name alias.");
119126
}

test-infra/camel-test-infra-rocketmq/src/main/java/org/apache/camel/test/infra/rocketmq/services/RocketMQNameserverContainer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public RocketMQNameserverContainer(Network network) {
3232
addExposedPort(RocketMQProperties.ROCKETMQ_NAMESRV_PORT);
3333
withTmpFs(Collections.singletonMap("/home/rocketmq/logs", "rw"));
3434
withCommand("sh", "mqnamesrv");
35-
withCreateContainerCmdModifier(cmd -> cmd.withName("nameserver"));
3635

3736
waitingFor(Wait.forListeningPort());
3837
}

0 commit comments

Comments
 (0)