Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log issue with @QuarkusIntegrationTest #33432

Merged
merged 2 commits into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
Expand Down Expand Up @@ -49,12 +51,15 @@ public static Config installAndGetSomeConfig() {

/**
* Launches a process using the supplied arguments and makes sure the process's output is drained to standard out
* <p>
* Implementation detail: Avoid using ProcessBuilder's redirect here because it causes problems with Maven Failsafe
* as can be seen in <a href="https://github.com/quarkusio/quarkus/issues/33229">here</a>
*/
static Process launchProcess(List<String> args) throws IOException {
return new ProcessBuilder(args)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.start();
Process process = Runtime.getRuntime().exec(args.toArray(new String[0]));
new Thread(new ProcessReader(process.getInputStream())).start();
new Thread(new ProcessReader(process.getErrorStream())).start();
return process;
}

/**
Expand Down Expand Up @@ -307,6 +312,31 @@ private void unableToDetermineData(String errorMessage) {
}
}

/**
* Used to drain the input of a launched process
*/
private static class ProcessReader implements Runnable {

private final InputStream inputStream;

private ProcessReader(InputStream inputStream) {
this.inputStream = inputStream;
}

@Override
public void run() {
byte[] b = new byte[100];
int i;
try {
while ((i = inputStream.read(b)) > 0) {
System.out.print(new String(b, 0, i, StandardCharsets.UTF_8));
}
} catch (IOException e) {
//ignore
}
}
}

private static class SimpleContext implements IntegrationTestStartedNotifier.Context {
private final Path logFile;

Expand Down