8056143: interrupted java/lang/management/MemoryMXBean/LowMemoryTest.java leaves running process

Reviewed-by: sla, dholmes
This commit is contained in:
Jaroslav Bachorik 2014-10-17 10:53:30 +02:00
parent d64da6c76e
commit c603f42b91
25 changed files with 169 additions and 156 deletions

View File

@ -134,8 +134,6 @@ java/lang/instrument/NativeMethodPrefixAgent.java generic-all
# 8044591
com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationContentTest.java generic-all
com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationTest.java generic-all
# 8056143
java/lang/management/MemoryMXBean/LowMemoryTest.java generic-all
# 8058492
java/lang/management/ThreadMXBean/FindDeadlocks.java generic-all
@ -308,7 +306,7 @@ sun/tools/jstatd/TestJstatdServer.java generic-all
sun/tools/jstatd/TestJstatdPort.java generic-all
sun/tools/jstatd/TestJstatdPortAndServer.java generic-all
# 8046285 8027668
# 8046285 8027668
sun/tools/jstatd/TestJstatdExternalRegistry.java generic-all
# 6456333

View File

@ -23,21 +23,14 @@
*/
import jdk.testlibrary.JDKToolLauncher;
import jdk.testlibrary.OutputAnalyzer;
import jdk.testlibrary.ProcessTools;
import java.io.IOException;
import java.nio.file.Path;
public class TestDaemonThreadLauncher {
private static ProcessBuilder processBuilder = new ProcessBuilder();
public static void main(String args[]) throws Exception {
for(int i=0; i<50; i++) {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-javaagent:DummyAgent.jar", "TestDaemonThread", ".");
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
OutputAnalyzer analyzer = ProcessTools.executeProcess(pb);
analyzer.shouldNotContain("ASSERTION FAILED");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,7 +46,7 @@ public class NoPremainAgentTest {
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeProcess(pb);
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,7 +47,7 @@ public class PremainClassTest {
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeProcess(pb);
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,7 +46,7 @@ public class ZeroArgPremainAgentTest {
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeProcess(pb);
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,6 +21,7 @@
* questions.
*/
package jdk.testlibrary;
/*
* @test
@ -28,13 +29,13 @@
* such as printing additional diagnostic info
* (exit code, stdout, stderr, command line, etc.)
* @library /testlibrary
* @build jdk.testlibrary.*
* @run main jdk.testlibrary.OutputAnalyzerReportingTest
*/
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import jdk.testlibrary.OutputAnalyzer;
public class OutputAnalyzerReportingTest {
public static void main(String[] args) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -20,15 +20,16 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.testlibrary;
/*
* @test
* @summary Test the OutputAnalyzer utility class
* @library /testlibrary
* @build jdk.testlibrary.*
* @run main jdk.testlibrary.OutputAnalyzerTest
*/
import jdk.testlibrary.OutputAnalyzer;
public class OutputAnalyzerTest {
public static void main(String args[]) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -108,7 +108,7 @@ public final class JcmdBase {
}
processBuilder.command(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,13 @@ package jdk.testlibrary;
import static jdk.testlibrary.Asserts.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -35,34 +39,37 @@ import java.util.regex.Pattern;
* Utility class for verifying output and exit value from a {@code Process}.
*/
public final class OutputAnalyzer {
private final OutputBuffer output;
private final String stdout;
private final String stderr;
private final int exitValue;
/**
* Create an OutputAnalyzer, a utility class for verifying output and exit
* value from a Process
* value from a Process.
* <p>
* OutputAnalyzer should never be instantiated directly -
* use {@linkplain ProcessTools#executeProcess(p)} instead
*
* @param process
* Process to analyze
* @throws IOException
* If an I/O error occurs.
*/
public OutputAnalyzer(Process process) throws IOException {
OutputBuffer output = ProcessTools.getOutput(process);
exitValue = process.exitValue();
this.stdout = output.getStdout();
this.stderr = output.getStderr();
OutputAnalyzer(Process process) throws IOException {
output = new OutputBuffer(process);
exitValue = -1;
this.stdout = null;
this.stderr = null;
}
/**
* Create an OutputAnalyzer, a utility class for verifying output
* Create an OutputAnalyzer, a utility class for verifying output.
*
* @param buf
* String buffer to analyze
*/
public OutputAnalyzer(String buf) {
OutputAnalyzer(String buf) {
this(buf, buf);
}
@ -74,7 +81,8 @@ public final class OutputAnalyzer {
* @param stderr
* stderr buffer to analyze
*/
public OutputAnalyzer(String stdout, String stderr) {
OutputAnalyzer(String stdout, String stderr) {
this.output = null;
this.stdout = stdout;
this.stderr = stderr;
exitValue = -1;
@ -90,8 +98,8 @@ public final class OutputAnalyzer {
* If the string was not found
*/
public void shouldContain(String expectedString) {
if (!stdout.contains(expectedString)
&& !stderr.contains(expectedString)) {
if (!getStdout().contains(expectedString)
&& !getStderr().contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString
+ "' missing from stdout/stderr \n");
@ -107,7 +115,7 @@ public final class OutputAnalyzer {
* If the string was not found
*/
public void stdoutShouldContain(String expectedString) {
if (!stdout.contains(expectedString)) {
if (!getStdout().contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString
+ "' missing from stdout \n");
@ -123,7 +131,7 @@ public final class OutputAnalyzer {
* If the string was not found
*/
public void stderrShouldContain(String expectedString) {
if (!stderr.contains(expectedString)) {
if (!getStderr().contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString
+ "' missing from stderr \n");
@ -140,12 +148,12 @@ public final class OutputAnalyzer {
* If the string was found
*/
public void shouldNotContain(String notExpectedString) {
if (stdout.contains(notExpectedString)) {
if (getStdout().contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString
+ "' found in stdout \n");
}
if (stderr.contains(notExpectedString)) {
if (getStderr().contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString
+ "' found in stderr \n");
@ -162,7 +170,7 @@ public final class OutputAnalyzer {
* If the string was found
*/
public void stdoutShouldNotContain(String notExpectedString) {
if (stdout.contains(notExpectedString)) {
if (getStdout().contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString
+ "' found in stdout \n");
@ -179,7 +187,7 @@ public final class OutputAnalyzer {
* If the string was found
*/
public void stderrShouldNotContain(String notExpectedString) {
if (stderr.contains(notExpectedString)) {
if (getStderr().contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString
+ "' found in stderr \n");
@ -196,9 +204,9 @@ public final class OutputAnalyzer {
*/
public void shouldMatch(String pattern) {
Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
.matcher(stdout);
.matcher(getStdout());
Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
.matcher(stderr);
.matcher(getStderr());
if (!stdoutMatcher.find() && !stderrMatcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern
@ -215,7 +223,7 @@ public final class OutputAnalyzer {
*/
public void stdoutShouldMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stdout);
getStdout());
if (!matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern
@ -232,7 +240,7 @@ public final class OutputAnalyzer {
*/
public void stderrShouldMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stderr);
getStderr());
if (!matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern
@ -250,13 +258,13 @@ public final class OutputAnalyzer {
*/
public void shouldNotMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stdout);
getStdout());
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stdout: '"
+ matcher.group() + "' \n");
}
matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(getStderr());
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stderr: '"
@ -274,7 +282,7 @@ public final class OutputAnalyzer {
*/
public void stdoutShouldNotMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stdout);
getStdout());
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stdout \n");
@ -291,7 +299,7 @@ public final class OutputAnalyzer {
*/
public void stderrShouldNotMatch(String pattern) {
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(
stderr);
getStderr());
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern + "' found in stderr \n");
@ -310,9 +318,9 @@ public final class OutputAnalyzer {
*/
public String firstMatch(String pattern, int group) {
Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
.matcher(stderr);
.matcher(getStderr());
Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE)
.matcher(stdout);
.matcher(getStdout());
if (stderrMatcher.find()) {
return stderrMatcher.group(group);
}
@ -357,7 +365,7 @@ public final class OutputAnalyzer {
* exit code Note: the command line is printed by the ProcessTools
*/
private void reportDiagnosticSummary() {
String msg = " stdout: [" + stdout + "];\n" + " stderr: [" + stderr
String msg = " stdout: [" + getStdout() + "];\n" + " stderr: [" + getStderr()
+ "]\n" + " exitValue = " + getExitValue() + "\n";
System.err.println(msg);
@ -369,7 +377,7 @@ public final class OutputAnalyzer {
* @return Content of the output buffer
*/
public String getOutput() {
return stdout + stderr;
return getStdout() + getStderr();
}
/**
@ -378,7 +386,7 @@ public final class OutputAnalyzer {
* @return Content of the stdout buffer
*/
public String getStdout() {
return stdout;
return output == null ? stdout : output.getStdout();
}
/**
@ -387,7 +395,7 @@ public final class OutputAnalyzer {
* @return Content of the stderr buffer
*/
public String getStderr() {
return stderr;
return output == null ? stderr : output.getStderr();
}
/**
@ -396,7 +404,7 @@ public final class OutputAnalyzer {
* @return Process exit value
*/
public int getExitValue() {
return exitValue;
return output == null ? exitValue : output.getExitValue();
}
/**
@ -492,5 +500,4 @@ public final class OutputAnalyzer {
return matchedCount;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,9 +23,23 @@
package jdk.testlibrary;
public class OutputBuffer {
private final String stdout;
private final String stderr;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
class OutputBuffer {
private static class OutputBufferException extends RuntimeException {
public OutputBufferException(Throwable cause) {
super(cause);
}
}
private final Process p;
private final Future<Void> outTask;
private final Future<Void> errTask;
private final ByteArrayOutputStream stderrBuffer = new ByteArrayOutputStream();
private final ByteArrayOutputStream stdoutBuffer = new ByteArrayOutputStream();
/**
* Create an OutputBuffer, a class for storing and managing stdout and
@ -36,9 +50,15 @@ public class OutputBuffer {
* @param stderr
* stderr result
*/
public OutputBuffer(String stdout, String stderr) {
this.stdout = stdout;
this.stderr = stderr;
OutputBuffer(Process p) {
this.p = p;
StreamPumper outPumper = new StreamPumper(p.getInputStream(),
stdoutBuffer);
StreamPumper errPumper = new StreamPumper(p.getErrorStream(),
stderrBuffer);
outTask = outPumper.process();
errTask = errPumper.process();
}
/**
@ -47,7 +67,15 @@ public class OutputBuffer {
* @return stdout result
*/
public String getStdout() {
return stdout;
try {
outTask.get();
return stdoutBuffer.toString();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new OutputBufferException(e);
} catch (ExecutionException | CancellationException e) {
throw new OutputBufferException(e);
}
}
/**
@ -56,6 +84,23 @@ public class OutputBuffer {
* @return stderr result
*/
public String getStderr() {
return stderr;
try {
errTask.get();
return stderrBuffer.toString();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new OutputBufferException(e);
} catch (ExecutionException | CancellationException e) {
throw new OutputBufferException(e);
}
}
public int getExitValue() {
try {
return p.waitFor();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new OutputBufferException(e);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -154,12 +154,14 @@ public class ProcessThread extends TestThread {
// Will block...
try {
this.process.waitFor();
output = new OutputAnalyzer(this.process);
} catch (Throwable t) {
String name = Thread.currentThread().getName();
System.out.println(String.format("ProcessThread[%s] failed: %s", name, t.toString()));
throw t;
} finally {
this.process.destroyForcibly().waitFor();
String logMsg = ProcessTools.getProcessLog(processBuilder, output);
System.out.println(logMsg);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,6 @@
package jdk.testlibrary;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
@ -34,7 +33,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -213,55 +211,6 @@ public final class ProcessTools {
return startProcess(name, processBuilder, linePredicate, 0, TimeUnit.SECONDS);
}
/**
* Pumps stdout and stderr from running the process into a String.
*
* @param processBuilder
* ProcessHandler to run.
* @return Output from process.
* @throws IOException
* If an I/O error occurs.
*/
public static OutputBuffer getOutput(ProcessBuilder processBuilder)
throws IOException {
return getOutput(processBuilder.start());
}
/**
* Pumps stdout and stderr the running process into a String.
*
* @param process
* Process to pump.
* @return Output from process.
* @throws IOException
* If an I/O error occurs.
*/
public static OutputBuffer getOutput(Process process) throws IOException {
ByteArrayOutputStream stderrBuffer = new ByteArrayOutputStream();
ByteArrayOutputStream stdoutBuffer = new ByteArrayOutputStream();
StreamPumper outPumper = new StreamPumper(process.getInputStream(),
stdoutBuffer);
StreamPumper errPumper = new StreamPumper(process.getErrorStream(),
stderrBuffer);
Future<Void> outTask = outPumper.process();
Future<Void> errTask = errPumper.process();
try {
process.waitFor();
outTask.get();
errTask.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
throw new IOException(e);
}
return new OutputBuffer(stdoutBuffer.toString(),
stderrBuffer.toString());
}
/**
* Get the process id of the current running Java process
*
@ -343,34 +292,51 @@ public final class ProcessTools {
* The command line will be like:
* {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
*
* The jvm process will have exited before this method returns.
*
* @param cmds User specifed arguments.
* @return The output from the process.
*/
public static OutputAnalyzer executeTestJvm(String... cmds) throws Throwable {
public static OutputAnalyzer executeTestJvm(String... cmds) throws Exception {
ProcessBuilder pb = createJavaProcessBuilder(Utils.addTestJavaOpts(cmds));
return executeProcess(pb);
}
/**
* Executes a process, waits for it to finish and returns the process output.
* The process will have exited before this method returns.
* @param pb The ProcessBuilder to execute.
* @return The output from the process.
* @return The {@linkplain OutputAnalyzer} instance wrapping the process.
*/
public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Throwable {
public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception {
OutputAnalyzer output = null;
Process p = null;
boolean failed = false;
try {
output = new OutputAnalyzer(pb.start());
p = pb.start();
output = new OutputAnalyzer(p);
p.waitFor();
return output;
} catch (Throwable t) {
failed = true;
System.out.println("executeProcess() failed: " + t);
throw t;
} finally {
System.out.println(getProcessLog(pb, output));
if (p != null) {
p.destroyForcibly().waitFor();
}
if (failed) {
System.err.println(getProcessLog(pb, output));
}
}
}
/**
* Executes a process, waits for it to finish and returns the process output.
*
* The process will have exited before this method returns.
*
* @param cmds The command line to execute.
* @return The output from the process.
*/
@ -394,6 +360,7 @@ public final class ProcessTools {
logMsg.append("exitvalue: " + exitValue + nl);
logMsg.append("stderr: " + stderr + nl);
logMsg.append("stdout: " + stdout + nl);
return logMsg.toString();
}

View File

@ -34,7 +34,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Semaphore;
import jdk.testlibrary.OutputBuffer;
import jdk.testlibrary.OutputAnalyzer;
import jdk.testlibrary.ProcessTools;
import sun.jvmstat.monitor.MonitorException;
import sun.jvmstat.monitor.MonitoredHost;
@ -305,13 +305,13 @@ public final class MonitorVmStartTerminate {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
}
private void executeJava() throws Exception, IOException {
private void executeJava() throws Throwable {
String className = JavaProcess.class.getName();
String classPath = System.getProperty("test.classes");
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Dtest.timeout.factor=" + System.getProperty("test.timeout.factor", "1.0"),
"-cp", classPath, className, mainArgsIdentifier);
OutputBuffer ob = ProcessTools.getOutput(pb.start());
OutputAnalyzer ob = ProcessTools.executeProcess(pb);
System.out.println("Java Process " + getMainArgsIdentifier() + " stderr:"
+ ob.getStderr());
System.err.println("Java Process " + getMainArgsIdentifier() + " stdout:"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -63,7 +63,7 @@ public abstract class DynamicLauncher {
protected OutputAnalyzer runVM() throws Exception {
String[] options = this.options();
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options);
OutputAnalyzer out = new OutputAnalyzer(pb.start());
OutputAnalyzer out = ProcessTools.executeProcess(pb);
System.out.println(out.getStdout());
System.err.println(out.getStderr());
return out;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -176,16 +176,15 @@ public abstract class AbstractFilePermissionTest {
command.toArray(new String[command.size()]));
System.out.println("test cmdline: " + Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
Process p = processBuilder.start();
OutputAnalyzer output = new OutputAnalyzer(p);
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println("test output:");
System.out.println(output.getOutput());
if ((p.exitValue() == 0) ||
if ((output.getExitValue() == 0) ||
!output.getOutput().contains("Exception thrown by the agent : " +
"java.rmi.server.ExportException: Port already in use")) {
return p.exitValue();
return output.getExitValue();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -188,15 +188,14 @@ public class RmiRegistrySslTest {
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(command.toArray(new String[command.size()]));
Process p = processBuilder.start();
OutputAnalyzer output = new OutputAnalyzer(p);
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println("test output:");
System.out.println(output.getOutput());
if (!output.getOutput().contains("Exception thrown by the agent : " +
"java.rmi.server.ExportException: Port already in use")) {
return p.exitValue();
return output.getExitValue();
}
}
throw new Error("Cannot find free port");

View File

@ -52,7 +52,7 @@ public class HatHeapDump1Test {
"-Xverify:all",
"-agentlib:hprof=heap=dump,format=b,file=" + dumpFile.getAbsolutePath(),
className);
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
output.shouldContain("Dumping Java heap ... done");
@ -79,7 +79,7 @@ public class HatHeapDump1Test {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;

View File

@ -91,7 +91,7 @@ public class BasicJMapTest {
processBuilder.command(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;

View File

@ -36,6 +36,7 @@ import jdk.testlibrary.Asserts;
import jdk.testlibrary.JDKToolLauncher;
import jdk.testlibrary.OutputAnalyzer;
import jdk.testlibrary.Utils;
import jdk.testlibrary.ProcessTools;
/**
* The helper class for running jps utility and verifying output from it
@ -160,7 +161,7 @@ public final class JpsHelper {
ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;

View File

@ -55,7 +55,7 @@ public class TestJpsClass {
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}

View File

@ -55,7 +55,7 @@ public class TestJpsJar {
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}

View File

@ -55,7 +55,7 @@ public class TestJpsJarRelative {
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}

View File

@ -66,7 +66,7 @@ public class BasicJStackTest {
processBuilder.command(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,6 @@ import static jdk.testlibrary.Asserts.*;
import jdk.testlibrary.JDKToolLauncher;
import jdk.testlibrary.OutputAnalyzer;
import jdk.testlibrary.ProcessThread;
import jdk.testlibrary.TestThread;
import jdk.testlibrary.Utils;
import jdk.testlibrary.ProcessTools;
@ -145,8 +144,8 @@ public final class JstatdTest {
return output;
}
private OutputAnalyzer waitForJstatdRMI(ProcessBuilder pb) throws IOException, InterruptedException {
OutputAnalyzer output = new OutputAnalyzer(pb.start());
private OutputAnalyzer waitForJstatdRMI(ProcessBuilder pb) throws Exception {
OutputAnalyzer output = ProcessTools.executeProcess(pb);
String remoteHost = (serverName != null) ? serverName : "JStatRemoteHost";
while (output.getExitValue() != 0) {
@ -155,7 +154,7 @@ public final class JstatdTest {
if (out.contains("RMI Registry not available") ||
out.contains("RMI Server " + remoteHost + " not available")) {
Thread.sleep(100);
output = new OutputAnalyzer(pb.start());
output = ProcessTools.executeProcess(pb);
} else {
output.shouldHaveExitValue(0);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,7 @@
import jdk.testlibrary.JDKToolLauncher;
import jdk.testlibrary.OutputAnalyzer;
import jdk.testlibrary.ProcessTools;
/*
* @test
@ -42,7 +43,7 @@ public class TestJstatdUsage {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
launcher.addToolArg(option);
ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]");
output.shouldHaveExitValue(1);