Skip to content

Commit 34b4442

Browse files
committed
Reinstate missing output from @QuarkusIntegrationTest
Follows up on: #50952
1 parent 7e5adfb commit 34b4442

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class DefaultJarLauncher implements JarArtifactLauncher {
5656
private Process quarkusProcess;
5757

5858
private boolean isSsl;
59+
private Path logFile;
5960

6061
@Override
6162
public void init(JarArtifactLauncher.JarInitContext initContext) {
@@ -74,9 +75,10 @@ public void start() throws IOException {
7475
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
7576
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
7677
.getConfigMapping(LogRuntimeConfig.class);
78+
logFile = logRuntimeConfig.file().path().toPath();
7779
if (startedFunction != null) {
7880
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
79-
waitTimeSeconds, logRuntimeConfig.file().path().toPath());
81+
waitTimeSeconds, logFile);
8082
isSsl = result.isSsl();
8183
} else {
8284
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
@@ -107,6 +109,7 @@ public LaunchResult runToCompletion(String[] args) {
107109
public void start(String[] programArgs, boolean handleIo) throws IOException {
108110
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
109111
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
112+
logFile = logRuntimeConfig.file().path().toPath();
110113
System.setProperty("test.url", TestHTTPResourceManager.getUri());
111114

112115
List<String> args = new ArrayList<>();
@@ -120,12 +123,12 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
120123
if (HTTP_PRESENT) {
121124
args.add("-Dquarkus.http.port=" + httpPort);
122125
args.add("-Dquarkus.http.ssl-port=" + httpsPort);
123-
// this won't be correct when using the random port but it's really only used by us for the rest client tests
126+
// this won't be correct when using the random port but it's really only used by us for the rest client
127+
// tests
124128
// in the main module, since those tests hit the application itself
125129
args.add("-Dtest.url=" + TestHTTPResourceManager.getUri());
126130
}
127-
File logPath = logRuntimeConfig.file().path();
128-
args.add("-Dquarkus.log.file.path=" + logPath.getAbsolutePath());
131+
args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath());
129132
args.add("-Dquarkus.log.file.enabled=true");
130133
args.add("-Dquarkus.log.category.\"io.quarkus\".level=INFO");
131134
if (testProfile != null) {
@@ -141,12 +144,12 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
141144
System.out.println("Executing \"" + String.join(" ", args) + "\"");
142145

143146
try {
144-
Files.deleteIfExists(logPath.toPath());
145-
if (logPath.getParent() != null) {
146-
Files.createDirectories(logPath.toPath().getParent());
147+
Files.deleteIfExists(logFile);
148+
if (logFile.getParent() != null) {
149+
Files.createDirectories(logFile.getParent());
147150
}
148151
} catch (FileSystemException e) {
149-
log.warnf("Log file %s deletion failed, could happen on Windows, we can carry on.", logPath);
152+
log.warnf("Log file %s deletion failed, could happen on Windows, we can carry on.", logFile);
150153
}
151154

152155
if (handleIo) {
@@ -189,6 +192,8 @@ public void includeAsSysProps(Map<String, String> systemProps) {
189192

190193
@Override
191194
public void close() {
195+
LauncherUtil.toStdOut(logFile);
192196
LauncherUtil.destroyProcess(quarkusProcess);
193197
}
198+
194199
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.net.URLClassLoader;
1212
import java.nio.file.FileSystemException;
1313
import java.nio.file.Files;
14+
import java.nio.file.Path;
1415
import java.security.CodeSource;
1516
import java.util.ArrayList;
1617
import java.util.Arrays;
@@ -48,6 +49,7 @@ public class DefaultNativeImageLauncher implements NativeImageLauncher {
4849
private final Map<String, String> systemProps = new HashMap<>();
4950

5051
private boolean isSsl;
52+
private Path logFile;
5153

5254
@Override
5355
public void init(NativeImageInitContext initContext) {
@@ -105,6 +107,7 @@ public void start() throws IOException {
105107
Supplier<Boolean> startedSupplier = createStartedSupplier(); // keep the legacy SPI handling
106108
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
107109
.getConfigMapping(LogRuntimeConfig.class);
110+
logFile = logRuntimeConfig.file().path().toPath();
108111
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
109112
if (startedSupplier != null) {
110113
waitForStartedSupplier(startedSupplier, quarkusProcess, waitTimeSeconds);
@@ -140,8 +143,8 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
140143
// in the main module, since those tests hit the application itself
141144
args.add("-Dtest.url=" + TestHTTPResourceManager.getUri());
142145
}
143-
File logPath = logRuntimeConfig.file().path();
144-
args.add("-Dquarkus.log.file.path=" + logPath.getAbsolutePath());
146+
logFile = logRuntimeConfig.file().path().toPath();
147+
args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath());
145148
args.add("-Dquarkus.log.file.enabled=true");
146149
args.add("-Dquarkus.log.category.\"io.quarkus\".level=INFO");
147150
if (testProfile != null) {
@@ -154,12 +157,12 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
154157
System.out.println("Executing \"" + String.join(" ", args) + "\"");
155158

156159
try {
157-
Files.deleteIfExists(logPath.toPath());
158-
if (logPath.getParent() != null) {
159-
Files.createDirectories(logPath.toPath().getParent());
160+
Files.deleteIfExists(logFile);
161+
if (logFile.getParent() != null) {
162+
Files.createDirectories(logFile.getParent());
160163
}
161164
} catch (FileSystemException e) {
162-
log.warnf("Log file %s deletion failed, could happen on Windows, we can carry on.", logPath);
165+
log.warnf("Log file %s deletion failed, could happen on Windows, we can carry on.", logFile);
163166
}
164167

165168
if (handleIo) {
@@ -294,6 +297,7 @@ public void includeAsSysProps(Map<String, String> systemProps) {
294297

295298
@Override
296299
public void close() {
300+
LauncherUtil.toStdOut(logFile);
297301
LauncherUtil.destroyProcess(quarkusProcess);
298302
}
299303
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ static Process launchProcessAndDrainIO(List<String> args, Map<String, String> en
5050
.redirectError(ProcessBuilder.Redirect.DISCARD)
5151
.redirectInput(ProcessBuilder.Redirect.INHERIT);
5252
pb.environment().putAll(env);
53-
Process process = pb.start();
54-
// new Thread(new ProcessReader(process.getInputStream())).start();
55-
// new Thread(new ProcessReader(process.getErrorStream())).start();
56-
return process;
53+
return pb.start();
5754
}
5855

5956
/**
@@ -224,6 +221,16 @@ static void updateConfigForPort(Integer effectivePort) {
224221
}
225222
}
226223

224+
static void toStdOut(Path log) {
225+
if (log != null) {
226+
try (var r = Files.newBufferedReader(log, StandardCharsets.UTF_8)) {
227+
r.lines().forEach(System.out::println);
228+
} catch (IOException ignored) {
229+
System.err.println("Unable to write process output");
230+
}
231+
}
232+
}
233+
227234
/**
228235
* Thread that reads a process output file looking for the line that indicates the address the application
229236
* is listening on.

0 commit comments

Comments
 (0)