Skip to content

Commit 1a0bd5c

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

12 files changed

+79
-130
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: 9 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,6 @@
2727
import org.jboss.logging.Logger;
2828

2929
import io.quarkus.runtime.logging.LogRuntimeConfig;
30-
import io.quarkus.test.common.http.TestHTTPResourceManager;
3130
import io.smallrye.config.SmallRyeConfig;
3231

3332
public class DefaultNativeImageLauncher implements NativeImageLauncher {
@@ -48,7 +47,6 @@ public class DefaultNativeImageLauncher implements NativeImageLauncher {
4847
private Process quarkusProcess;
4948
private final Map<String, String> systemProps = new HashMap<>();
5049

51-
private boolean isSsl;
5250
private Path logFile;
5351

5452
@Override
@@ -102,7 +100,8 @@ public LaunchResult runToCompletion(String[] args) {
102100
}
103101
}
104102

105-
public void start() throws IOException {
103+
@Override
104+
public Optional<ListeningAddress> start() throws IOException {
106105
start(new String[0], true);
107106
Supplier<Boolean> startedSupplier = createStartedSupplier(); // keep the legacy SPI handling
108107
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
@@ -111,22 +110,20 @@ public void start() throws IOException {
111110
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
112111
if (startedSupplier != null) {
113112
waitForStartedSupplier(startedSupplier, quarkusProcess, waitTimeSeconds);
113+
return Optional.empty();
114114
} else if (startedFunction != null) {
115-
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
116-
waitTimeSeconds, logRuntimeConfig.file().path().toPath());
117-
isSsl = result.isSsl();
115+
waitForStartedFunction(startedFunction, quarkusProcess, waitTimeSeconds, logRuntimeConfig.file().path().toPath());
116+
return Optional.empty();
118117
} else {
119118
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
120119
waitTimeSeconds);
121-
updateConfigForPort(result.getPort());
122-
isSsl = result.isSsl();
120+
return Optional.of(result);
123121
}
124122
}
125123

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

131128
if (nativeImagePath == null) {
132129
nativeImagePath = guessPath(testClass);
@@ -139,9 +136,8 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
139136
if (DefaultJarLauncher.HTTP_PRESENT) {
140137
args.add("-Dquarkus.http.port=" + httpPort);
141138
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());
139+
args.add(
140+
"-Dtest.url=http://${quarkus.http.host:localhost}:${quarkus.http.test-port:8081}${quarkus.http.root-path:${quarkus.servlet.context-path:}}");
145141
}
146142
logFile = logRuntimeConfig.file().path().toPath();
147143
args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath());
@@ -170,7 +166,6 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
170166
} else {
171167
quarkusProcess = LauncherUtil.launchProcess(args, env);
172168
}
173-
174169
}
175170

176171
private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process quarkusProcess, long waitTime) {
@@ -183,7 +178,6 @@ private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process q
183178
try {
184179
Thread.sleep(100);
185180
if (startedSupplier.get()) {
186-
isSsl = false;
187181
started = true;
188182
break;
189183
}
@@ -286,10 +280,6 @@ private static void logGuessedPath(String guessedPath) {
286280
System.err.println("======================================================================================");
287281
}
288282

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

test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestExtensionState.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
import java.io.Closeable;
44
import java.io.IOException;
55
import java.util.Map;
6+
import java.util.Optional;
67

78
import org.eclipse.microprofile.config.ConfigProvider;
89

10+
import io.quarkus.test.common.ListeningAddress;
911
import io.quarkus.test.common.TestResourceManager;
1012
import io.smallrye.config.SmallRyeConfig;
1113

1214
public class IntegrationTestExtensionState extends QuarkusTestExtensionState {
1315

1416
private final Map<String, String> sysPropRestore;
1517

16-
public IntegrationTestExtensionState(TestResourceManager testResourceManager, Closeable resource,
17-
Runnable clearCallbacks, Map<String, String> sysPropRestore) {
18-
super(testResourceManager, resource, clearCallbacks);
18+
public IntegrationTestExtensionState(TestResourceManager testResourceManager, Closeable resource, Runnable clearCallbacks,
19+
Optional<ListeningAddress> listeningAddress, Map<String, String> sysPropRestore) {
20+
super(testResourceManager, resource, clearCallbacks, listeningAddress);
1921
this.sysPropRestore = sysPropRestore;
2022
}
2123

0 commit comments

Comments
 (0)