Skip to content

Commit 7922fa3

Browse files
committed
Change ArtifactLauncher.start to return the listening address
1 parent e25d7c6 commit 7922fa3

File tree

14 files changed

+155
-162
lines changed

14 files changed

+155
-162
lines changed

integration-tests/awt-packaging/src/test/java/io/quarkus/it/jaxb/AwtJaxbTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.quarkus.it.jaxb;
22

33
import static io.restassured.RestAssured.given;
4-
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.CoreMatchers.containsString;
55

66
import org.junit.jupiter.api.Test;
77

@@ -31,7 +31,7 @@ void book() {
3131
.then()
3232
.statusCode(200)
3333
// The height in pixels of the book's cover image.
34-
.body(equalTo("\"10\""));
34+
.body(containsString("10"));
3535
}
3636

3737
/**
@@ -47,6 +47,6 @@ void lambda() {
4747
.post()
4848
.then()
4949
.statusCode(200)
50-
.body(equalTo("\"10\""));
50+
.body(containsString("10"));
5151
}
5252
}

test-framework/common/src/main/java/io/quarkus/test/common/ArtifactLauncher.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
import java.time.Duration;
66
import java.util.List;
77
import java.util.Map;
8+
import java.util.Optional;
89

910
import io.quarkus.bootstrap.app.CuratedApplication;
1011

1112
public interface ArtifactLauncher<T extends ArtifactLauncher.InitContext> extends Closeable {
1213

1314
void init(T t);
1415

15-
void start() throws IOException;
16+
Optional<ListeningAddress> start() throws IOException;
1617

1718
LaunchResult runToCompletion(String[] args);
1819

1920
void includeAsSysProps(Map<String, String> systemProps);
2021

21-
boolean listensOnSsl();
22-
2322
interface InitContext {
2423

2524
int httpPort();

test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.quarkus.test.common;
22

33
import static io.quarkus.test.common.LauncherUtil.createStartedFunction;
4-
import static io.quarkus.test.common.LauncherUtil.updateConfigForPort;
54
import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData;
65
import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction;
76
import static java.lang.ProcessBuilder.Redirect.DISCARD;
@@ -52,7 +51,6 @@ public class DefaultDockerContainerLauncher implements DockerContainerArtifactLa
5251
private Map<String, String> volumeMounts;
5352
private Map<String, String> labels;
5453
private final Map<String, String> systemProps = new HashMap<>();
55-
private boolean isSsl;
5654
private final String containerName = "quarkus-integration-test-" + RandomStringUtils.insecure().next(5, true, false);
5755
private String containerRuntimeBinaryName;
5856
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@@ -96,8 +94,6 @@ public LaunchResult runToCompletion(String[] argz) {
9694
}
9795
}
9896

99-
System.setProperty("test.url", TestHTTPResourceManager.getUri());
100-
10197
final List<String> args = new ArrayList<>();
10298
args.add(containerRuntimeBinaryName);
10399
args.add("run");
@@ -188,7 +184,7 @@ public LaunchResult runToCompletion(String[] argz) {
188184
}
189185

190186
@Override
191-
public void start() throws IOException {
187+
public Optional<ListeningAddress> start() throws IOException {
192188
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
193189
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
194190

@@ -208,8 +204,6 @@ public void start() throws IOException {
208204
}
209205
}
210206

211-
System.setProperty("test.url", TestHTTPResourceManager.getUri());
212-
213207
if (httpPort == 0) {
214208
httpPort = getRandomPort();
215209
}
@@ -301,15 +295,13 @@ public void start() throws IOException {
301295
.start();
302296

303297
if (startedFunction != null) {
304-
final IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, containerProcess,
305-
waitTimeSeconds, logPath);
306-
isSsl = result.isSsl();
298+
waitForStartedFunction(startedFunction, containerProcess, waitTimeSeconds, logPath);
299+
return Optional.empty();
307300
} else {
308301
log.info("Wait for server to start by capturing listening data...");
309-
final ListeningAddress result = waitForCapturedListeningData(containerProcess, logPath, waitTimeSeconds);
302+
ListeningAddress result = waitForCapturedListeningData(containerProcess, logPath, waitTimeSeconds);
310303
log.infof("Server started on port %s", result.getPort());
311-
updateConfigForPort(result.getPort());
312-
isSsl = result.isSsl();
304+
return Optional.of(result);
313305
}
314306
}
315307

@@ -319,10 +311,6 @@ private int getRandomPort() throws IOException {
319311
}
320312
}
321313

322-
public boolean listensOnSsl() {
323-
return isSsl;
324-
}
325-
326314
public void includeAsSysProps(Map<String, String> systemProps) {
327315
this.systemProps.putAll(systemProps);
328316
}

test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.quarkus.test.common;
22

33
import static io.quarkus.test.common.LauncherUtil.createStartedFunction;
4-
import static io.quarkus.test.common.LauncherUtil.updateConfigForPort;
54
import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData;
65
import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction;
76

@@ -15,6 +14,7 @@
1514
import java.util.HashMap;
1615
import java.util.List;
1716
import java.util.Map;
17+
import java.util.Optional;
1818
import java.util.function.Function;
1919

2020
import org.eclipse.microprofile.config.ConfigProvider;
@@ -55,7 +55,6 @@ public class DefaultJarLauncher implements JarArtifactLauncher {
5555
private final Map<String, String> systemProps = new HashMap<>();
5656
private Process quarkusProcess;
5757

58-
private boolean isSsl;
5958
private Path logFile;
6059

6160
@Override
@@ -70,21 +69,20 @@ public void init(JarArtifactLauncher.JarInitContext initContext) {
7069
this.generateAotFile = initContext.generateAotFile();
7170
}
7271

73-
public void start() throws IOException {
72+
@Override
73+
public Optional<ListeningAddress> start() throws IOException {
7474
start(new String[0], true);
7575
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
7676
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
7777
.getConfigMapping(LogRuntimeConfig.class);
7878
logFile = logRuntimeConfig.file().path().toPath();
7979
if (startedFunction != null) {
80-
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
81-
waitTimeSeconds, logFile);
82-
isSsl = result.isSsl();
80+
waitForStartedFunction(startedFunction, quarkusProcess, waitTimeSeconds, logFile);
81+
return Optional.empty();
8382
} else {
8483
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
8584
waitTimeSeconds);
86-
updateConfigForPort(result.getPort());
87-
isSsl = result.isSsl();
85+
return Optional.of(result);
8886
}
8987
}
9088

@@ -110,7 +108,6 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
110108
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
111109
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
112110
logFile = logRuntimeConfig.file().path().toPath();
113-
System.setProperty("test.url", TestHTTPResourceManager.getUri());
114111

115112
List<String> args = new ArrayList<>();
116113
args.add(determineJavaPath());
@@ -180,11 +177,6 @@ private String determineJavaPath() {
180177
return "java";
181178
}
182179

183-
@Override
184-
public boolean listensOnSsl() {
185-
return isSsl;
186-
}
187-
188180
@Override
189181
public void includeAsSysProps(Map<String, String> systemProps) {
190182
this.systemProps.putAll(systemProps);

test-framework/common/src/main/java/io/quarkus/test/common/DefaultNativeImageLauncher.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.quarkus.test.common;
22

33
import static io.quarkus.test.common.LauncherUtil.createStartedFunction;
4-
import static io.quarkus.test.common.LauncherUtil.updateConfigForPort;
54
import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData;
65
import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction;
76

@@ -19,14 +18,15 @@
1918
import java.util.List;
2019
import java.util.Locale;
2120
import java.util.Map;
21+
import java.util.Optional;
2222
import java.util.function.Function;
2323
import java.util.function.Supplier;
2424

2525
import org.eclipse.microprofile.config.ConfigProvider;
2626
import org.jboss.logging.Logger;
2727

2828
import io.quarkus.runtime.logging.LogRuntimeConfig;
29-
import io.quarkus.test.common.http.TestHTTPResourceManager;
29+
import io.smallrye.config.ConfigValue;
3030
import io.smallrye.config.SmallRyeConfig;
3131

3232
public class DefaultNativeImageLauncher implements NativeImageLauncher {
@@ -47,7 +47,6 @@ public class DefaultNativeImageLauncher implements NativeImageLauncher {
4747
private Process quarkusProcess;
4848
private final Map<String, String> systemProps = new HashMap<>();
4949

50-
private boolean isSsl;
5150
private Path logFile;
5251

5352
@Override
@@ -83,28 +82,26 @@ public LaunchResult runToCompletion(String[] args) {
8382
}
8483
}
8584

86-
public void start() throws IOException {
85+
@Override
86+
public Optional<ListeningAddress> start() throws IOException {
8787
start(new String[0], true);
8888
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
8989
.getConfigMapping(LogRuntimeConfig.class);
9090
logFile = logRuntimeConfig.file().path().toPath();
9191
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
9292
if (startedFunction != null) {
93-
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
94-
waitTimeSeconds, logRuntimeConfig.file().path().toPath());
95-
isSsl = result.isSsl();
93+
waitForStartedFunction(startedFunction, quarkusProcess, waitTimeSeconds, logRuntimeConfig.file().path().toPath());
94+
return Optional.empty();
9695
} else {
9796
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
9897
waitTimeSeconds);
99-
updateConfigForPort(result.getPort());
100-
isSsl = result.isSsl();
98+
return Optional.of(result);
10199
}
102100
}
103101

104102
public void start(String[] programArgs, boolean handleIo) throws IOException {
105103
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
106104
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
107-
System.setProperty("test.url", TestHTTPResourceManager.getUri());
108105

109106
if (nativeImagePath == null) {
110107
nativeImagePath = guessPath(testClass);
@@ -117,9 +114,15 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
117114
if (DefaultJarLauncher.HTTP_PRESENT) {
118115
args.add("-Dquarkus.http.port=" + httpPort);
119116
args.add("-Dquarkus.http.ssl-port=" + httpsPort);
120-
// this won't be correct when using the random port but it's really only used by us for the rest client tests
121-
// in the main module, since those tests hit the application itself
122-
args.add("-Dtest.url=" + TestHTTPResourceManager.getUri());
117+
// Check io.quarkus.test.common.http.TestHTTPConfigSourceInterceptor.sanitizeUrl
118+
String rootPath = "";
119+
// These are build time properties so it is fine to evaluate them here
120+
ConfigValue rootPathValue = config.getConfigValue("${quarkus.http.root-path:${quarkus.servlet.context-path:}}");
121+
if (rootPathValue.getValue() != null && rootPathValue.getValue().endsWith("/")) {
122+
rootPath = rootPathValue.getValue().substring(0, rootPathValue.getValue().length() - 1);
123+
}
124+
// We want to keep `quarkus.http.test-port` as an expression so it is evaluated correctly
125+
args.add("-Dtest.url=http://localhost:${quarkus.http.test-port:8081}" + rootPath);
123126
}
124127
logFile = logRuntimeConfig.file().path().toPath();
125128
args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath());
@@ -148,7 +151,6 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
148151
} else {
149152
quarkusProcess = LauncherUtil.launchProcess(args, env);
150153
}
151-
152154
}
153155

154156
private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process quarkusProcess, long waitTime) {
@@ -161,7 +163,6 @@ private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process q
161163
try {
162164
Thread.sleep(100);
163165
if (startedSupplier.get()) {
164-
isSsl = false;
165166
started = true;
166167
break;
167168
}
@@ -264,10 +265,6 @@ private static void logGuessedPath(String guessedPath) {
264265
System.err.println("======================================================================================");
265266
}
266267

267-
public boolean listensOnSsl() {
268-
return isSsl;
269-
}
270-
271268
@Override
272269
public void includeAsSysProps(Map<String, String> systemProps) {
273270
this.systemProps.putAll(systemProps);

test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.eclipse.microprofile.config.Config;
2424
import org.eclipse.microprofile.config.ConfigProvider;
2525

26-
import io.quarkus.test.common.http.TestHTTPResourceManager;
2726
import io.smallrye.common.os.OS;
2827

2928
public final class LauncherUtil {
@@ -208,19 +207,6 @@ static IntegrationTestStartedNotifier.Result waitForStartedFunction(
208207
return result;
209208
}
210209

211-
/**
212-
* Updates the configuration necessary to make all test systems knowledgeable about the port on which the launched
213-
* process is listening
214-
*/
215-
static void updateConfigForPort(Integer effectivePort) {
216-
if (effectivePort != null) {
217-
System.setProperty("quarkus.http.port", effectivePort.toString()); //set the port as a system property in order to have it applied to Config
218-
System.setProperty("quarkus.http.test-port", effectivePort.toString()); // needed for RestAssuredManager
219-
System.clearProperty("test.url"); // make sure the old value does not interfere with setting the new one
220-
System.setProperty("test.url", TestHTTPResourceManager.getUri());
221-
}
222-
}
223-
224210
static void toStdOut(Path log) {
225211
if (log != null) {
226212
try (var r = Files.newBufferedReader(log, StandardCharsets.UTF_8)) {

test-framework/common/src/main/java/io/quarkus/test/common/RunCommandLauncher.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.HashMap;
1616
import java.util.List;
1717
import java.util.Map;
18+
import java.util.Optional;
1819
import java.util.concurrent.CountDownLatch;
1920
import java.util.concurrent.ExecutorService;
2021
import java.util.concurrent.Executors;
@@ -110,7 +111,7 @@ public LaunchResult runToCompletion(String[] args) {
110111
}
111112

112113
@Override
113-
public void start() throws IOException {
114+
public Optional<ListeningAddress> start() throws IOException {
114115
System.setProperty("test.url", TestHTTPResourceManager.getUri());
115116

116117
Path logFile = logFilePath;
@@ -161,10 +162,8 @@ public void start() throws IOException {
161162
LauncherUtil.destroyProcess(quarkusProcess, true);
162163
throw new RuntimeException("Unable to start target quarkus application " + this.waitTimeSeconds + "s");
163164
}
164-
}
165165

166-
public boolean listensOnSsl() {
167-
return false;
166+
return Optional.empty();
168167
}
169168

170169
public void includeAsSysProps(Map<String, String> systemProps) {

0 commit comments

Comments
 (0)