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


Java ProcessTools.executeProcess方法代码示例

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

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

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

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

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

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

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

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

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

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

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

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


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