8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns

Reviewed-by: dsamersoff
This commit is contained in:
Jaroslav Bachorik 2015-11-06 14:34:06 +01:00
parent 6e0ea9d21c
commit b577a431bd
10 changed files with 59 additions and 5 deletions

View file

@ -23,20 +23,22 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import jdk.test.lib.OutputAnalyzer; import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.ProcessTools;
/* /*
* @test * @test
* @summary Test of diagnostic command GC.run_finalization * @summary Test of diagnostic command GC.run_finalization
* @library /testlibrary * @library /testlibrary
* @library /test/lib/share/classes
* @modules java.base/sun.misc * @modules java.base/sun.misc
* java.compiler * java.compiler
* java.management * java.management
* jdk.jvmstat/sun.jvmstat.monitor * jdk.jvmstat/sun.jvmstat.monitor
* @build jdk.test.lib.* * @build jdk.test.lib.*
* @build jdk.test.lib.dcmd.* * @build jdk.test.lib.dcmd.*
* @build jdk.test.lib.process.*
* @build RunFinalizationTest FinalizationRunner * @build RunFinalizationTest FinalizationRunner
* @run main RunFinalizationTest * @run main RunFinalizationTest
*/ */
@ -50,8 +52,21 @@ public class RunFinalizationTest {
javaArgs.add(TEST_APP_NAME); javaArgs.add(TEST_APP_NAME);
ProcessBuilder testAppPb = ProcessTools.createJavaProcessBuilder(javaArgs.toArray(new String[javaArgs.size()])); ProcessBuilder testAppPb = ProcessTools.createJavaProcessBuilder(javaArgs.toArray(new String[javaArgs.size()]));
OutputAnalyzer out = ProcessTools.executeProcess(testAppPb); final AtomicBoolean failed = new AtomicBoolean();
out.stderrShouldNotMatch("^" + FinalizationRunner.FAILED + ".*") final AtomicBoolean passed = new AtomicBoolean();
.stdoutShouldMatch("^" + FinalizationRunner.PASSED + ".*");
Process runner = ProcessTools.startProcess(
"FinalizationRunner",
testAppPb,
l -> {
failed.compareAndSet(false, l.contains(FinalizationRunner.FAILED));
passed.compareAndSet(false, l.contains(FinalizationRunner.PASSED));
}
);
runner.waitFor();
if (failed.get() || !passed.get()) {
throw new Error("RunFinalizationTest failed");
}
} }
} }

View file

@ -41,7 +41,10 @@ package jdk.test.lib;
* multiple times, then the line number won't provide enough context to * multiple times, then the line number won't provide enough context to
* understand the failure. * understand the failure.
* </pre> * </pre>
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib}
*/ */
@Deprecated
public class Asserts { public class Asserts {
/** /**

View file

@ -27,6 +27,11 @@ import java.io.FileNotFoundException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
/**
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib}
*/
@Deprecated
public final class JDKToolFinder { public final class JDKToolFinder {
private JDKToolFinder() { private JDKToolFinder() {

View file

@ -46,7 +46,10 @@ import java.util.List;
* Process p = pb.start(); * Process p = pb.start();
* } * }
* </pre> * </pre>
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib}
*/ */
@Deprecated
public class JDKToolLauncher { public class JDKToolLauncher {
private final String executable; private final String executable;
private final List<String> vmArgs = new ArrayList<String>(); private final List<String> vmArgs = new ArrayList<String>();

View file

@ -41,7 +41,11 @@ public final class OutputAnalyzer {
* *
* @param process Process to analyze * @param process Process to analyze
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib/process}
*/ */
@Deprecated
public OutputAnalyzer(Process process) throws IOException { public OutputAnalyzer(Process process) throws IOException {
OutputBuffer output = ProcessTools.getOutput(process); OutputBuffer output = ProcessTools.getOutput(process);
exitValue = process.exitValue(); exitValue = process.exitValue();

View file

@ -23,6 +23,11 @@
package jdk.test.lib; package jdk.test.lib;
/**
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib/process}
*/
@Deprecated
public class OutputBuffer { public class OutputBuffer {
private final String stdout; private final String stdout;
private final String stderr; private final String stderr;

View file

@ -25,6 +25,11 @@ package jdk.test.lib;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/**
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib}
*/
@Deprecated
public class Platform { public class Platform {
private static final String osName = System.getProperty("os.name"); private static final String osName = System.getProperty("os.name");
private static final String dataModel = System.getProperty("sun.arch.data.model"); private static final String dataModel = System.getProperty("sun.arch.data.model");

View file

@ -31,6 +31,11 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/**
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib/process}
*/
@Deprecated
public final class ProcessTools { public final class ProcessTools {
private ProcessTools() { private ProcessTools() {

View file

@ -27,6 +27,11 @@ import java.io.OutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
/**
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib/process}
*/
@Deprecated
public final class StreamPumper implements Runnable { public final class StreamPumper implements Runnable {
private static final int BUF_SIZE = 256; private static final int BUF_SIZE = 256;

View file

@ -55,7 +55,11 @@ import sun.misc.Unsafe;
/** /**
* Common library for various test helper functions. * Common library for various test helper functions.
*
* @deprecated This class is deprecated. Use the one from
* {@code <root>/test/lib/share/classes/jdk/test/lib}
*/ */
@Deprecated
public final class Utils { public final class Utils {
/** /**