本文整理汇总了Java中jdk.testlibrary.ProcessTools.createJavaProcessBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessTools.createJavaProcessBuilder方法的具体用法?Java ProcessTools.createJavaProcessBuilder怎么用?Java ProcessTools.createJavaProcessBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.testlibrary.ProcessTools
的用法示例。
在下文中一共展示了ProcessTools.createJavaProcessBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 = new OutputAnalyzer(pb.start());
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!");
}
示例2: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
String testJdk = System.getProperty("test.jdk", "?");
String testSrc = System.getProperty("test.src", "?");
File jar = JpsHelper.buildJar("JpsBase");
List<String> cmd = new ArrayList<>();
cmd.addAll(JpsHelper.getVmArgs());
cmd.add("-Dtest.jdk=" + testJdk);
cmd.add("-Dtest.src=" + testSrc);
cmd.add("-jar");
cmd.add("." + File.separator + jar.getName());
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}
示例3: launch
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static Process launch(String address, String class_name) throws Exception {
String args[] = new String[]{
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
+ address,
class_name
};
args = VMConnection.insertDebuggeeVMOptions(args);
ProcessBuilder launcher = ProcessTools.createJavaProcessBuilder(args);
System.out.println(launcher.command().stream().collect(Collectors.joining(" ", "Starting: ", "")));
Process p = ProcessTools.startProcess(
class_name,
launcher,
RunToExit::checkForError,
RunToExit::isTransportListening,
0,
TimeUnit.NANOSECONDS
);
return p;
}
示例4: 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");
}
}
示例5: prepareLauncher
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static ProcessBuilder prepareLauncher(String address, boolean suspend, String class_name) throws Exception {
List<String> args = new ArrayList<>();
for(String dbgOption : VMConnection.getDebuggeeVMOptions().split(" ")) {
if (!dbgOption.trim().isEmpty()) {
args.add(dbgOption);
}
}
String lib = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=";
if (suspend) {
lib += "y";
} else {
lib += "n";
}
lib += ",address=" + address;
args.add(lib);
args.add(class_name);
return ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
}
示例6: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] a) throws Exception {
String testArgs = String.format(
"-javaagent:ZeroArgPremainAgent.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");
}
}
示例7: setupClass
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
@BeforeClass
public static void setupClass() throws Exception {
testAppPb = ProcessTools.createJavaProcessBuilder(
"-XX:+UsePerfData",
"-cp", System.getProperty("test.class.path"),
TEST_APP_NAME
);
}
示例8: startApplication
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
* The Application process must be run concurrently with our tests since
* the tests will attach to the Application.
* We will run the Application process in a separate thread.
*
* The Application must be started with flag "-Xshare:off" for the Retransform
* test in TestBasics to pass on all platforms.
*
* The Application will write its pid and shutdownPort in the given outFile.
*/
public static ProcessThread startApplication(String... additionalOpts) throws Throwable {
String classpath = System.getProperty("test.class.path", ".");
String[] myArgs = concat(additionalOpts, new String [] {
"-XX:+UsePerfData", "-XX:+EnableDynamicAgentLoading",
"-Dattach.test=true", "-classpath", classpath, "Application"
});
String[] args = Utils.addTestJavaOpts(myArgs);
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
ProcessThread pt = new ProcessThread("runApplication", (line) -> line.equals(Application.READY_MSG), pb);
pt.start();
return pt;
}
示例9: 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;
}
示例10: runVM
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
protected OutputAnalyzer runVM() throws Exception {
String[] options = this.options();
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options);
OutputAnalyzer out = new OutputAnalyzer(pb.start());
System.out.println(out.getStdout());
System.err.println(out.getStderr());
return out;
}
示例11: runJMXBindingTest
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private ProcessThread runJMXBindingTest(String address, boolean useSSL) {
List<String> args = new ArrayList<>();
args.add("-classpath");
args.add(TEST_CLASSPATH);
args.add("-Dcom.sun.management.jmxremote.host=" + address);
args.add("-Dcom.sun.management.jmxremote.port=" + JMX_PORT);
args.add("-Dcom.sun.management.jmxremote.rmi.port=" + RMI_PORT);
args.add("-Dcom.sun.management.jmxremote.authenticate=false");
args.add("-Dcom.sun.management.jmxremote.ssl=" + Boolean.toString(useSSL));
if (useSSL) {
args.add("-Dcom.sun.management.jmxremote.registry.ssl=true");
args.add("-Djavax.net.ssl.keyStore=" + KEYSTORE_LOC);
args.add("-Djavax.net.ssl.trustStore=" + TRUSTSTORE_LOC);
args.add("-Djavax.net.ssl.keyStorePassword=password");
args.add("-Djavax.net.ssl.trustStorePassword=trustword");
}
args.add(TEST_CLASS);
args.add(address);
args.add(Integer.toString(JMX_PORT));
args.add(Integer.toString(RMI_PORT));
args.add(Boolean.toString(useSSL));
try {
ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[] {}));
System.out.println(ProcessTools.getCommandLine(builder));
ProcessThread jvm = new ProcessThread("JMX-Tester-" + address, JMXInterfaceBindingTest::isJMXAgentResponseAvailable, builder);
return jvm;
} catch (Exception e) {
throw new RuntimeException("Test failed", e);
}
}
示例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: test
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
@Test(dataProvider = "options")
public void test(List<String> args, List<String> expected) throws Exception {
// launch a test program
// $ java <runtime-arguments> -classpath <cpath> RuntimeArguments <expected>
Stream<String> options = Stream.concat(args.stream(),
Stream.of("-classpath", TEST_CLASSES, "RuntimeArguments"));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Stream.concat(options, expected.stream())
.toArray(String[]::new)
);
ProcessTools.executeProcess(pb).shouldHaveExitValue(0);
}
示例15: setup
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
@BeforeTest
public final void setup() throws Exception {
List<String> args = new ArrayList<>();
args.add("-cp");
args.add(System.getProperty("test.class.path"));
args.add("-XX:+UsePerfData");
args.addAll(getCustomVmArgs());
args.add(TEST_APP_NAME);
testAppPb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
jcmd = new ManagementAgentJcmd(TEST_APP_NAME, false);
}