当前位置: 首页>>代码示例>>Java>>正文


Java ProcessTools.createJavaProcessBuilder方法代码示例

本文整理汇总了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!");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:PremainClassTest.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestJpsJarRelative.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:RunToExit.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:NoPremainAgentTest.java

示例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()]));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ExclusiveBind.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ZeroArgPremainAgentTest.java

示例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
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:JMXStatusPerfCountersTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:RunnerUtil.java

示例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;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:AbstractFilePermissionTest.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:DynamicLauncher.java

示例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);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:JMXInterfaceBindingTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:DynamicLauncher.java

示例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");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:RmiRegistrySslTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:RuntimeArguments.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JMXStatusTest.java


注:本文中的jdk.testlibrary.ProcessTools.createJavaProcessBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。