本文整理汇总了Java中jdk.testlibrary.ProcessTools.executeProcess方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessTools.executeProcess方法的具体用法?Java ProcessTools.executeProcess怎么用?Java ProcessTools.executeProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.testlibrary.ProcessTools
的用法示例。
在下文中一共展示了ProcessTools.executeProcess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTest
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
* Runs a test in a separate JVM.
* command line like:
* {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
*
* {defaultopts} are the default java options set by the framework.
* Default GC options in {defaultopts} may be removed.
* This is used when the test specifies its own GC options.
*
* @param main Name of the main class.
* @param clearGcOpts true if the default GC options should be removed.
* @param testOpts java options specified by the test.
*/
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
throws Throwable {
List<String> opts = new ArrayList<>();
opts.add(JDKToolFinder.getJDKTool("java"));
opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
opts.add("-cp");
opts.add(System.getProperty("test.class.path", "test.class.path"));
opts.add("-XX:+PrintGCDetails");
if (clearGcOpts) {
opts = Utils.removeGcOpts(opts);
}
opts.addAll(Arrays.asList(testOpts));
opts.add(main);
OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
output.shouldHaveExitValue(0);
if (output.getStdout().indexOf(successMessage) < 0) {
throw new Exception("output missing '" + successMessage + "'");
}
}
示例2: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] a) throws Exception {
String testArgs = String.format(
"-javaagent:NoPremainAgent.jar -classpath %s DummyMain",
System.getProperty("test.classes", "."));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = ProcessTools.executeProcess(pb);
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());
output.stderrShouldContain("java.lang.NoSuchMethodException");
if (0 == output.getExitValue()) {
throw new RuntimeException("Expected error but got exit value 0");
}
}
示例3: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] a) throws Exception {
String testArgs = String.format(
"-javaagent:%s/Agent.jar -classpath %s DummyMain",
System.getProperty("test.src"),
System.getProperty("test.classes", "."));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = ProcessTools.executeProcess(pb);
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());
output.shouldHaveExitValue(0);
output.stdoutShouldContain("premain running");
output.stdoutShouldContain("Hello from DummyMain!");
}
示例4: runTest
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
* Runs a test in a separate JVM.
* command line like:
* {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
*
* {defaultopts} are the default java options set by the framework.
* Default GC options in {defaultopts} may be removed.
* This is used when the test specifies its own GC options.
*
* @param main Name of the main class.
* @param clearGcOpts true if the default GC options should be removed.
* @param testOpts java options specified by the test.
*/
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
throws Throwable {
List<String> opts = new ArrayList<>();
opts.add(JDKToolFinder.getJDKTool("java"));
opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
opts.add("-cp");
opts.add(System.getProperty("test.class.path", "test.class.path"));
opts.add("-Xlog:gc*=debug");
if (clearGcOpts) {
opts = Utils.removeGcOpts(opts);
}
opts.addAll(Arrays.asList(testOpts));
opts.add(main);
OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
output.shouldHaveExitValue(0);
if (output.getStdout().indexOf(successMessage) < 0) {
throw new Exception("output missing '" + successMessage + "'");
}
}
示例5: jstack
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
launcher.addVMArg("-XX:+UsePerfData");
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);
}
}
processBuilder.command(launcher.getCommand());
System.out.println(processBuilder.command().stream().collect(Collectors.joining(" ")));
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;
}
示例6: jstack
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
launcher.addVMArg("-XX:+UsePerfData");
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);
}
}
launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
processBuilder.command(launcher.getCommand());
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;
}
示例7: executeCmd
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static String executeCmd(String... toolArgs) throws Throwable {
JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
for (String s : toolArgs) {
cmd.addToolArg(s);
}
OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
if (output == null || output.getStdout() == null) {
throw new Exception("Output was null. Process did not finish correctly.");
}
if (output.getExitValue() == 0) {
throw new Exception("Process exit code was 0, but error was expected.");
}
return output.getStdout();
}
示例8: createNormalZip
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
void createNormalZip() throws Throwable {
createFiles();
String[] cmd = { jar, "c0Mf", "normal.zip", "a", "b" };
ProcessBuilder pb = new ProcessBuilder(cmd);
OutputAnalyzer a = ProcessTools.executeProcess(pb);
a.shouldHaveExitValue(0);
a.stdoutShouldMatch("\\A\\Z");
a.stderrShouldMatch("\\A\\Z");
deleteFiles();
}
示例9: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
for(int i=0; i<50; i++) {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-javaagent:DummyAgent.jar", "TestDaemonThread", ".");
OutputAnalyzer analyzer = ProcessTools.executeProcess(pb);
analyzer.shouldNotContain("ASSERTION FAILED");
analyzer.shouldHaveExitValue(0);
}
}
示例10: startMeWithArgs
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static void startMeWithArgs(){
/*
* big tests not for regular execution on all platforms:
* run main/othervm -Xmx8g TimSortStackSize2 1073741824
* run main/othervm -Xmx16g TimSortStackSize2 2147483644
*/
try {
Boolean compressedOops = WhiteBox.getWhiteBox()
.getBooleanVMFlag("UseCompressedOops");
final String xmsValue = "-Xms" +
((compressedOops == null || compressedOops) ? "385" : "770")
+ "m";
System.out.println( "compressedOops: " + compressedOops
+ "; Test will be started with \"" + xmsValue + "\"");
ProcessBuilder processBuilder = ProcessTools
.createJavaProcessBuilder(Utils.addTestJavaOpts(xmsValue,
"TimSortStackSize2", "67108864"
)
);
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
} catch( Exception e ){
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例11: executeJava
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
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);
OutputAnalyzer ob = ProcessTools.executeProcess(pb);
System.out.println("Java Process " + getMainArgsIdentifier() + " stderr:"
+ ob.getStderr());
System.err.println("Java Process " + getMainArgsIdentifier() + " stdout:"
+ ob.getStdout());
}
示例12: runVM
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
protected OutputAnalyzer runVM() throws Exception {
String[] options = this.options();
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options);
OutputAnalyzer out = ProcessTools.executeProcess(pb);
System.out.println(out.getStdout());
System.err.println(out.getStderr());
return out;
}
示例13: doTest
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private int doTest(String... args) throws Exception {
for (int i = 0; i < MAX_GET_FREE_PORT_TRIES; ++i) {
initTestEnvironment();
List<String> command = new ArrayList<>();
command.addAll(Utils.getVmOptions());
command.add("-Dtest.src=" + TEST_SRC);
command.add("-Dtest.rmi.port=" + port);
command.addAll(Arrays.asList(args));
command.add("-cp");
command.add(TEST_CLASS_PATH);
command.add(className);
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(command.toArray(new String[command.size()]));
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 output.getExitValue();
}
}
throw new Error("Cannot find free port");
}
示例14: doTest
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private int doTest() throws Exception {
for (int i = 0; i < MAX_GET_FREE_PORT_TRIES; ++i) {
final String pp = "-Dcom.sun.management.jmxremote.port=" + jdk.testlibrary.Utils.getFreePort();
List<String> command = new ArrayList<>();
command.addAll(jdk.testlibrary.Utils.getVmOptions());
command.add(mp);
command.add(pp);
command.add("-cp");
command.add(TEST_CLASSES);
command.add(className);
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
command.toArray(new String[command.size()]));
System.out.println("test cmdline: " + Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println("test output:");
System.out.println(output.getOutput());
if ((output.getExitValue() == 0) ||
!output.getOutput().contains("Exception thrown by the agent : " +
"java.rmi.server.ExportException: Port already in use")) {
return output.getExitValue();
}
}
return -1;
}
示例15: assertCanList
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
void assertCanList(String zipFileName) throws Throwable {
String[] cmd = { jar, "tf", zipFileName };
ProcessBuilder pb = new ProcessBuilder(cmd);
OutputAnalyzer a = ProcessTools.executeProcess(pb);
a.shouldHaveExitValue(0);
StringBuilder expected = new StringBuilder();
for (File file : files)
expected.append(file.getName()).append(System.lineSeparator());
a.stdoutShouldMatch(expected.toString());
a.stderrShouldMatch("\\A\\Z");
}