Skip to content

Commit 22bea87

Browse files
committed
Change ArtifactLauncher.start to return the listening address
1 parent aef7c05 commit 22bea87

13 files changed

+153
-159
lines changed

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: 17 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,6 +18,7 @@
1918
import java.util.List;
2019
import java.util.Locale;
2120
import java.util.Map;
21+
import java.util.Optional;
2222
import java.util.ServiceLoader;
2323
import java.util.function.Function;
2424
import java.util.function.Supplier;
@@ -27,7 +27,7 @@
2727
import org.jboss.logging.Logger;
2828

2929
import io.quarkus.runtime.logging.LogRuntimeConfig;
30-
import io.quarkus.test.common.http.TestHTTPResourceManager;
30+
import io.smallrye.config.ConfigValue;
3131
import io.smallrye.config.SmallRyeConfig;
3232

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

51-
private boolean isSsl;
5251
private Path logFile;
5352

5453
@Override
@@ -102,7 +101,8 @@ public LaunchResult runToCompletion(String[] args) {
102101
}
103102
}
104103

105-
public void start() throws IOException {
104+
@Override
105+
public Optional<ListeningAddress> start() throws IOException {
106106
start(new String[0], true);
107107
Supplier<Boolean> startedSupplier = createStartedSupplier(); // keep the legacy SPI handling
108108
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
@@ -111,22 +111,20 @@ public void start() throws IOException {
111111
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
112112
if (startedSupplier != null) {
113113
waitForStartedSupplier(startedSupplier, quarkusProcess, waitTimeSeconds);
114+
return Optional.empty();
114115
} else if (startedFunction != null) {
115-
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
116-
waitTimeSeconds, logRuntimeConfig.file().path().toPath());
117-
isSsl = result.isSsl();
116+
waitForStartedFunction(startedFunction, quarkusProcess, waitTimeSeconds, logRuntimeConfig.file().path().toPath());
117+
return Optional.empty();
118118
} else {
119119
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
120120
waitTimeSeconds);
121-
updateConfigForPort(result.getPort());
122-
isSsl = result.isSsl();
121+
return Optional.of(result);
123122
}
124123
}
125124

126125
public void start(String[] programArgs, boolean handleIo) throws IOException {
127126
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
128127
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
129-
System.setProperty("test.url", TestHTTPResourceManager.getUri());
130128

131129
if (nativeImagePath == null) {
132130
nativeImagePath = guessPath(testClass);
@@ -139,9 +137,15 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
139137
if (DefaultJarLauncher.HTTP_PRESENT) {
140138
args.add("-Dquarkus.http.port=" + httpPort);
141139
args.add("-Dquarkus.http.ssl-port=" + httpsPort);
142-
// this won't be correct when using the random port but it's really only used by us for the rest client tests
143-
// in the main module, since those tests hit the application itself
144-
args.add("-Dtest.url=" + TestHTTPResourceManager.getUri());
140+
// Check io.quarkus.test.common.http.TestHTTPConfigSourceInterceptor.sanitizeUrl
141+
String rootPath = "";
142+
// These are build time properties so it is fine to evaluate them here
143+
ConfigValue rootPathValue = config.getConfigValue("${quarkus.http.root-path:${quarkus.servlet.context-path:}}");
144+
if (rootPathValue.getValue() != null && rootPathValue.getValue().endsWith("/")) {
145+
rootPath = rootPathValue.getValue().substring(0, rootPathValue.getValue().length() - 1);
146+
}
147+
// We want to keep `quarkus.http.test-port` as an expression so it is evaluated correctly
148+
args.add("-Dtest.url=http://localhost:${quarkus.http.test-port:8081}" + rootPath);
145149
}
146150
logFile = logRuntimeConfig.file().path().toPath();
147151
args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath());
@@ -170,7 +174,6 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
170174
} else {
171175
quarkusProcess = LauncherUtil.launchProcess(args, env);
172176
}
173-
174177
}
175178

176179
private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process quarkusProcess, long waitTime) {
@@ -183,7 +186,6 @@ private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process q
183186
try {
184187
Thread.sleep(100);
185188
if (startedSupplier.get()) {
186-
isSsl = false;
187189
started = true;
188190
break;
189191
}
@@ -286,10 +288,6 @@ private static void logGuessedPath(String guessedPath) {
286288
System.err.println("======================================================================================");
287289
}
288290

289-
public boolean listensOnSsl() {
290-
return isSsl;
291-
}
292-
293291
@Override
294292
public void includeAsSysProps(Map<String, String> systemProps) {
295293
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) {

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.util.Map;
5+
import java.util.Optional;
56

67
/**
78
* A launcher that simply sets the {@code quarkus.http.host} property based on the value {@code quarkus.http.test-host}
@@ -10,13 +11,13 @@
1011
*/
1112
@SuppressWarnings("rawtypes")
1213
public class TestHostLauncher implements ArtifactLauncher {
13-
1414
private String previousHost;
1515

1616
@Override
17-
public void start() throws IOException {
17+
public Optional<ListeningAddress> start() throws IOException {
1818
// set 'quarkus.http.host' to ensure that RestAssured targets the proper host
1919
previousHost = System.setProperty("quarkus.http.host", System.getProperty("quarkus.http.test-host"));
20+
return Optional.empty();
2021
}
2122

2223
@Override
@@ -26,11 +27,6 @@ public void close() throws IOException {
2627
}
2728
}
2829

29-
@Override
30-
public boolean listensOnSsl() {
31-
return Boolean.parseBoolean(System.getProperty("quarkus.http.test-ssl-enabled", "false"));
32-
}
33-
3430
@Override
3531
public void includeAsSysProps(Map systemProps) {
3632

0 commit comments

Comments
 (0)