This is an automated email from the ASF dual-hosted git repository. fmariani pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4d8860471b97499f7364c75c61218ebe95b906eb Author: Croway <[email protected]> AuthorDate: Thu Feb 5 17:19:58 2026 +0100 CAMEL-22962: Camel Infra run specify custom port --- .../dsl/jbang/core/commands/DependencyListTest.java | 5 +---- .../commands/ExportMainApplicationProperties.java | 4 +--- .../dsl/jbang/core/commands/ExportMainJibTest.java | 5 +---- .../dsl/jbang/core/commands/ExportMainJkubeTest.java | 5 +---- .../camel/dsl/jbang/core/commands/ExportTest.java | 5 +---- .../services/AbstractArtemisEmbeddedService.java | 2 +- .../common/services/ContainerEnvironmentUtil.java | 19 +++++++++++++++++++ .../services/embedded/FtpEmbeddedInfraService.java | 7 ++++--- .../services/embedded/FtpsEmbeddedInfraService.java | 7 ++++--- .../services/embedded/SftpEmbeddedInfraService.java | 7 ++++--- .../services/MinioLocalContainerInfraService.java | 11 +++++------ 11 files changed, 42 insertions(+), 35 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyListTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyListTest.java index b7abdcf7f380..80d3c53098a4 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyListTest.java +++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyListTest.java @@ -19,8 +19,6 @@ package org.apache.camel.dsl.jbang.core.commands; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; @@ -42,8 +40,7 @@ class DependencyListTest extends CamelCommandBaseTestSupport { @BeforeEach public void setup() throws Exception { super.setup(); - Path base = Paths.get("target"); - workingDir = Files.createTempDirectory(base, "camel-export").toFile(); + workingDir = Files.createTempDirectory("camel-export").toFile(); } @AfterEach diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationProperties.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationProperties.java index 42f77aaff17f..829e7980778d 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationProperties.java +++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainApplicationProperties.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Arrays; @@ -45,8 +44,7 @@ class ExportMainApplicationProperties { @BeforeEach public void setup() throws IOException { - Path base = Paths.get("target"); - workingDir = Files.createTempDirectory(base, "camel-export").toFile(); + workingDir = Files.createTempDirectory("camel-export").toFile(); } @AfterEach 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 b2220d6ba700..8039058119dd 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 @@ -21,8 +21,6 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.stream.Stream; @@ -46,8 +44,7 @@ class ExportMainJibTest { @BeforeEach public void setup() throws IOException { - Path base = Paths.get("target"); - workingDir = Files.createTempDirectory(base, "camel-export").toFile(); + workingDir = Files.createTempDirectory("camel-export").toFile(); } @AfterEach 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 a8479d2cfdc5..5437e612460e 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 @@ -21,8 +21,6 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.stream.Stream; @@ -46,8 +44,7 @@ class ExportMainJkubeTest { @BeforeEach public void setup() throws IOException { - Path base = Paths.get("target"); - workingDir = Files.createTempDirectory(base, "camel-export").toFile(); + workingDir = Files.createTempDirectory("camel-export").toFile(); } @AfterEach 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 7ff9000fd3db..e99e3bc9e641 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 @@ -21,8 +21,6 @@ import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -59,8 +57,7 @@ class ExportTest { @BeforeEach public void setup() throws IOException { LOG.info("Preparing ExportTest"); - Path base = Paths.get("target"); - workingDir = Files.createTempDirectory(base, "camel-export").toFile(); + workingDir = Files.createTempDirectory("camel-export").toFile(); } @AfterEach diff --git a/test-infra/camel-test-infra-artemis/src/main/java/org/apache/camel/test/infra/artemis/services/AbstractArtemisEmbeddedService.java b/test-infra/camel-test-infra-artemis/src/main/java/org/apache/camel/test/infra/artemis/services/AbstractArtemisEmbeddedService.java index 433edc285dfb..41bf9b4b0f88 100644 --- a/test-infra/camel-test-infra-artemis/src/main/java/org/apache/camel/test/infra/artemis/services/AbstractArtemisEmbeddedService.java +++ b/test-infra/camel-test-infra-artemis/src/main/java/org/apache/camel/test/infra/artemis/services/AbstractArtemisEmbeddedService.java @@ -33,8 +33,8 @@ import org.apache.activemq.artemis.core.server.QueueQueryResult; import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ; import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.infra.artemis.common.ArtemisRunException; -import org.apache.camel.test.infra.common.services.ContainerEnvironmentUtil; import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper; +import org.apache.camel.test.infra.common.services.ContainerEnvironmentUtil; import org.apache.camel.test.infra.messaging.services.ConnectionFactoryAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 e6b504496ca7..779f85da1518 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 @@ -157,6 +157,25 @@ public final class ContainerEnvironmentUtil { return defaultPort; } + /** + * Gets the configured port from system property for embedded services. Returns 0 (random port) if no port is + * explicitly configured. Embedded services should use random ports by default for test isolation, and only use a + * fixed port when explicitly configured. + * + * @return the configured port, or 0 for random port assignment + */ + public static int getConfiguredPortOrRandom() { + String portStr = System.getProperty(INFRA_PORT_PROPERTY); + if (portStr != null && !portStr.isEmpty()) { + try { + return Integer.parseInt(portStr); + } catch (NumberFormatException e) { + LOG.warn("Invalid port value '{}', using random port", portStr); + } + } + return 0; + } + /** * Configures port exposure for a single-port container based on fixed/random port mode. * diff --git a/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpEmbeddedInfraService.java b/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpEmbeddedInfraService.java index 1576ffb6a35b..cfe4397de5c3 100644 --- a/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpEmbeddedInfraService.java +++ b/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpEmbeddedInfraService.java @@ -133,10 +133,11 @@ public class FtpEmbeddedInfraService extends AbstractService implements FtpInfra serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig()); ListenerFactory factory = new ListenerFactory(); - if (ContainerEnvironmentUtil.isFixedPort(this.getClass())) { - factory.setPort(ContainerEnvironmentUtil.getConfiguredPort(2221)); - } else { + // If port was already assigned (restart scenario), reuse it; otherwise get a new one + if (port > 0) { factory.setPort(port); + } else { + factory.setPort(ContainerEnvironmentUtil.getConfiguredPortOrRandom()); } factory.setServerAddress(embeddedConfiguration.getServerAddress()); diff --git a/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpsEmbeddedInfraService.java b/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpsEmbeddedInfraService.java index a1a442d4aa2f..117eea7ff92e 100644 --- a/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpsEmbeddedInfraService.java +++ b/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/FtpsEmbeddedInfraService.java @@ -63,10 +63,11 @@ public class FtpsEmbeddedInfraService extends FtpEmbeddedInfraService { FtpServerFactory serverFactory = super.createFtpServerFactory(embeddedConfiguration); ListenerFactory listenerFactory = new ListenerFactory(serverFactory.getListener(DEFAULT_LISTENER)); - if (ContainerEnvironmentUtil.isFixedPort(this.getClass())) { - listenerFactory.setPort(ContainerEnvironmentUtil.getConfiguredPort(2221)); - } else { + // If port was already assigned (restart scenario), reuse it; otherwise get a new one + if (port > 0) { listenerFactory.setPort(port); + } else { + listenerFactory.setPort(ContainerEnvironmentUtil.getConfiguredPortOrRandom()); } listenerFactory.setImplicitSsl(embeddedConfiguration.getSecurityConfiguration().isUseImplicit()); listenerFactory.setSslConfiguration(createSslConfiguration(embeddedConfiguration).createSslConfiguration()); diff --git a/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/SftpEmbeddedInfraService.java b/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/SftpEmbeddedInfraService.java index b8050c3c5871..96987b6ec6e1 100644 --- a/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/SftpEmbeddedInfraService.java +++ b/test-infra/camel-test-infra-ftp/src/main/java/org/apache/camel/test/infra/ftp/services/embedded/SftpEmbeddedInfraService.java @@ -96,10 +96,11 @@ public class SftpEmbeddedInfraService extends AbstractService implements FtpInfr public void setUpServer() throws Exception { sshd = SshServer.setUpDefaultServer(); - if (ContainerEnvironmentUtil.isFixedPort(this.getClass())) { - sshd.setPort(ContainerEnvironmentUtil.getConfiguredPort(2222)); - } else { + // If port was already assigned (restart scenario), reuse it; otherwise get a new one + if (port > 0) { sshd.setPort(port); + } else { + sshd.setPort(ContainerEnvironmentUtil.getConfiguredPortOrRandom()); } sshd.setKeyPairProvider(createKeyPairProvider()); diff --git a/test-infra/camel-test-infra-minio/src/main/java/org/apache/camel/test/infra/minio/services/MinioLocalContainerInfraService.java b/test-infra/camel-test-infra-minio/src/main/java/org/apache/camel/test/infra/minio/services/MinioLocalContainerInfraService.java index 92d3d5df7d17..3359d9863a35 100644 --- a/test-infra/camel-test-infra-minio/src/main/java/org/apache/camel/test/infra/minio/services/MinioLocalContainerInfraService.java +++ b/test-infra/camel-test-infra-minio/src/main/java/org/apache/camel/test/infra/minio/services/MinioLocalContainerInfraService.java @@ -35,8 +35,6 @@ public class MinioLocalContainerInfraService implements MinioInfraService, Conta public static final String CONTAINER_NAME = "minio"; private static final String ACCESS_KEY = System.getProperty(MinioProperties.ACCESS_KEY, "testAccessKey"); private static final String SECRET_KEY = System.getProperty(MinioProperties.SECRET_KEY, "testSecretKey"); - private static final String USERNAME = System.getProperty(MinioProperties.USERNAME, "minioadmin"); - private static final String PASSWORD = System.getProperty(MinioProperties.PASSWORD, "minioadmin"); private static final int MINIO_TCP_PORT = 9000; private static final int MINIO_UI_PORT = 9001; @@ -78,8 +76,9 @@ public class MinioLocalContainerInfraService implements MinioInfraService, Conta ContainerEnvironmentUtil.PortConfig.primary(MINIO_TCP_PORT), ContainerEnvironmentUtil.PortConfig.secondary(MINIO_UI_PORT)); withCommand("server /data --console-address :9001"); - withEnv("MINIO_ROOT_USER", USERNAME); - withEnv("MINIO_ROOT_PASSWORD", PASSWORD); + // Use same credentials for MINIO_ROOT_USER as accessKey() returns for consistency + withEnv("MINIO_ROOT_USER", accessKey()); + withEnv("MINIO_ROOT_PASSWORD", secretKey()); } else { ContainerEnvironmentUtil.configurePort(this, false, MINIO_TCP_PORT); withCommand("server /data"); @@ -146,11 +145,11 @@ public class MinioLocalContainerInfraService implements MinioInfraService, Conta @Override public String consoleUsername() { - return USERNAME; + return accessKey(); } @Override public String consolePassword() { - return PASSWORD; + return secretKey(); } }
