8224165: [TESTBUG] Docker tests produce excessive output
Trimmed child process output, saving child stdout to file Reviewed-by: dholmes, lmesnik
This commit is contained in:
parent
b582ed131a
commit
e4f31b1cd7
@ -24,6 +24,7 @@
|
|||||||
package jdk.test.lib.containers.docker;
|
package jdk.test.lib.containers.docker;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
@ -32,6 +33,7 @@ import java.nio.file.Paths;
|
|||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -46,6 +48,12 @@ public class DockerTestUtils {
|
|||||||
private static boolean isDockerEngineAvailable = false;
|
private static boolean isDockerEngineAvailable = false;
|
||||||
private static boolean wasDockerEngineChecked = false;
|
private static boolean wasDockerEngineChecked = false;
|
||||||
|
|
||||||
|
// Specifies how many lines to copy from child STDOUT to main test output.
|
||||||
|
// Having too many lines in the main test output will result
|
||||||
|
// in JT harness trimming the output, and can lead to loss of useful
|
||||||
|
// diagnostic information.
|
||||||
|
private static final int MAX_LINES_TO_COPY_FOR_CHILD_STDOUT = 100;
|
||||||
|
|
||||||
// Use this property to specify docker location on your system.
|
// Use this property to specify docker location on your system.
|
||||||
// E.g.: "/usr/local/bin/docker".
|
// E.g.: "/usr/local/bin/docker".
|
||||||
private static final String DOCKER_COMMAND =
|
private static final String DOCKER_COMMAND =
|
||||||
@ -266,16 +274,41 @@ public class DockerTestUtils {
|
|||||||
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));
|
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));
|
||||||
|
|
||||||
long started = System.currentTimeMillis();
|
long started = System.currentTimeMillis();
|
||||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
Process p = pb.start();
|
||||||
|
long pid = p.pid();
|
||||||
|
OutputAnalyzer output = new OutputAnalyzer(p);
|
||||||
|
|
||||||
|
String stdoutLogFile = String.format("docker-stdout-%d.log", pid);
|
||||||
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
|
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
|
||||||
System.out.println("[STDERR]\n" + output.getStderr());
|
System.out.println("[STDERR]\n" + output.getStderr());
|
||||||
System.out.println("[STDOUT]\n" + output.getStdout());
|
System.out.println("[STDOUT]\n" +
|
||||||
|
trimLines(output.getStdout(),MAX_LINES_TO_COPY_FOR_CHILD_STDOUT));
|
||||||
|
System.out.printf("Child process STDOUT is trimmed to %d lines \n",
|
||||||
|
MAX_LINES_TO_COPY_FOR_CHILD_STDOUT);
|
||||||
|
writeOutputToFile(output.getStdout(), stdoutLogFile);
|
||||||
|
System.out.println("Full child process STDOUT was saved to " + stdoutLogFile);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void writeOutputToFile(String output, String fileName) throws Exception {
|
||||||
|
try (FileWriter fw = new FileWriter(fileName)) {
|
||||||
|
fw.write(output, 0, output.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static String trimLines(String buffer, int nrOfLines) {
|
||||||
|
List<String> l = Arrays.asList(buffer.split("\\R"));
|
||||||
|
if (l.size() < nrOfLines) {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.join("\n", l.subList(0, nrOfLines));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void generateDockerFile(Path dockerfile, String baseImage,
|
private static void generateDockerFile(Path dockerfile, String baseImage,
|
||||||
String baseImageVersion) throws Exception {
|
String baseImageVersion) throws Exception {
|
||||||
String template =
|
String template =
|
||||||
|
Loading…
Reference in New Issue
Block a user