diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java index 136ac025bf788..93a4f51264745 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java @@ -865,10 +865,15 @@ private void setupTcpHttpServer(HttpServer httpServer, HttpServerOptions options clearHttpProperty = true; schema = "http"; } - System.setProperty( - launchMode == LaunchMode.TEST ? "quarkus." + schema + ".test-port" - : "quarkus." + schema + ".port", - String.valueOf(actualPort)); + String portPropertyValue = String.valueOf(actualPort); + String portPropertyName = (launchMode == LaunchMode.TEST ? "quarkus." + schema + ".test-port" + : "quarkus." + schema + ".port"); + System.setProperty(portPropertyName, portPropertyValue); + if (launchMode.isDevOrTest()) { + // set the profile property as well to make sure we don't have any inconsistencies + System.setProperty(propertyWithProfilePrefix(portPropertyName), + portPropertyValue); + } // Set in HttpOptions to output the port in the Timing class options.setPort(actualPort); } @@ -882,10 +887,19 @@ private void setupTcpHttpServer(HttpServer httpServer, HttpServerOptions options @Override public void stop(Future stopFuture) { if (clearHttpProperty) { - System.clearProperty(launchMode == LaunchMode.TEST ? "quarkus.http.test-port" : "quarkus.http.port"); + String portPropertyName = launchMode == LaunchMode.TEST ? "quarkus.http.test-port" : "quarkus.http.port"; + System.clearProperty(portPropertyName); + if (launchMode.isDevOrTest()) { + System.clearProperty(propertyWithProfilePrefix(portPropertyName)); + } + } if (clearHttpsProperty) { - System.clearProperty(launchMode == LaunchMode.TEST ? "quarkus.https.test-port" : "quarkus.https.port"); + String portPropertyName = launchMode == LaunchMode.TEST ? "quarkus.https.test-port" : "quarkus.https.port"; + System.clearProperty(portPropertyName); + if (launchMode.isDevOrTest()) { + System.clearProperty(propertyWithProfilePrefix(portPropertyName)); + } } final AtomicInteger remainingCount = new AtomicInteger(0); @@ -915,6 +929,10 @@ public void stop(Future stopFuture) { domainSocketServer.close(handleClose); } } + + private String propertyWithProfilePrefix(String portPropertyName) { + return "%" + launchMode.getDefaultProfile() + "." + portPropertyName; + } } protected static ServerBootstrap virtualBootstrap; diff --git a/integration-tests/spring-web/src/main/resources/application.properties b/integration-tests/spring-web/src/main/resources/application.properties index 3f44daa1d2e17..24fb66ecc39d4 100644 --- a/integration-tests/spring-web/src/main/resources/application.properties +++ b/integration-tests/spring-web/src/main/resources/application.properties @@ -2,3 +2,4 @@ quarkus.security.users.file.enabled=true quarkus.security.users.file.users=test-users.properties quarkus.security.users.file.roles=test-roles.properties quarkus.security.users.file.plain-text=true +%test.quarkus.http.test-port=0