Allow big outputs in forked test processes
MODIFY
dd-java-agent/src/test/java/datadog/trace/agent/test/IntegrationTestUtils.java
dd-java-agent/src/test/java/datadog/trace/agent/test/IntegrationTestUtils.java
@@ -220,28 +220,21 @@ public class IntegrationTestUtils {
commands.addAll(Arrays.asList(mainMethodArgs));
final ProcessBuilder processBuilder = new ProcessBuilder(commands.toArray(new String[0]));
processBuilder.environment().putAll(envVars);
+
final Process process = processBuilder.start();
+ final StreamGobbler errorGobbler =
+ new StreamGobbler(process.getErrorStream(), "ERROR", printOutputStreams);
+ final StreamGobbler outputGobbler =
+ new StreamGobbler(process.getInputStream(), "OUTPUT", printOutputStreams);
+ outputGobbler.start();
+ errorGobbler.start();
+
waitFor(process, 30, TimeUnit.SECONDS);
- if (printOutputStreams) {
- final BufferedReader stdInput =
- new BufferedReader(new InputStreamReader(process.getInputStream(), UTF_8));
+ outputGobbler.join();
+ errorGobbler.join();
- final BufferedReader stdError =
- new BufferedReader(new InputStreamReader(process.getErrorStream(), UTF_8));
- System.out.println("--- " + mainClassName + " stdout ---");
- String s = null;
- while ((s = stdInput.readLine()) != null) {
- System.out.println(s);
- }
- System.out.println("--- stdout end ---");
- System.out.println("--- " + mainClassName + " stderr ---");
- while ((s = stdError.readLine()) != null) {
- System.out.println(s);
- }
- System.out.println("--- stderr end ---");
- }
return process.exitValue();
}
@@ -263,4 +256,31 @@ public class IntegrationTestUtils {
} while (rem > 0);
throw new TimeoutException();
}
+
+ private static class StreamGobbler extends Thread {
+ InputStream stream;
+ String type;
+ boolean print;
+
+ private StreamGobbler(final InputStream stream, final String type, final boolean print) {
+ this.stream = stream;
+ this.type = type;
+ this.print = print;
+ }
+
+ @Override
+ public void run() {
+ try {
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ if (print) {
+ System.out.println(type + "> " + line);
+ }
+ }
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
}

Allow big outputs in forked test processes