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


Java ProcessTools.startProcess方法代码示例

本文整理汇总了Java中jdk.testlibrary.ProcessTools.startProcess方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessTools.startProcess方法的具体用法?Java ProcessTools.startProcess怎么用?Java ProcessTools.startProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.testlibrary.ProcessTools的用法示例。


在下文中一共展示了ProcessTools.startProcess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public synchronized void start() throws InterruptedException, IOException, TimeoutException {
    if (started.compareAndSet(false, true)) {
        try {
            p = ProcessTools.startProcess(
                "JMXStartStopDoSomething",
                pb,
                (line) -> {
                    if (line.toLowerCase().startsWith("pid:")) {
                        pid = Integer.parseInt(line.split("\\:")[1]);
                    }
                    return line.equals("main enter");
                },
                5,
                TimeUnit.SECONDS
            );
        } catch (TimeoutException e) {
            p.destroy();
            p.waitFor();
            throw e;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:JMXStartStopTest.java

示例2: jcmd

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
 * Run the "jcmd" command
 * @param target The target application name (or PID)
 * @param c {@linkplain Consumer} instance; may be null
 * @param command Command with parameters; space separated string
 * @throws IOException
 * @throws InterruptedException
 */
private static void jcmd(String target, final Consumer<String> c, String ... command) throws IOException, InterruptedException {
    dbg_print("[jcmd] " + (command.length > 0 ? command[0] : "list"));

    JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jcmd");
    l.addToolArg(target);
    for(String cmd : command) {
        l.addToolArg(cmd);
    }
    Process p = ProcessTools.startProcess(
        "jcmd",
        new ProcessBuilder(l.getCommand()),
        c
    );

    p.waitFor();
    dbg_print("[jcmd] --------");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:JMXStartStopTest.java

示例3: launch

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static Process launch(String address, String class_name) throws Exception {
    String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
        "-agentlib:jdwp=transport=dt_socket" +
        ",server=y" + ",suspend=y" + ",address=" + address,
        class_name
    });

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);

    final AtomicBoolean success = new AtomicBoolean();
    Process p = ProcessTools.startProcess(
        class_name,
        pb,
        (line) -> {
            // The first thing that will get read is
            //    Listening for transport dt_socket at address: xxxxx
            // which shows the debuggee is ready to accept connections.
            success.set(line.contains("Listening for transport dt_socket at address:"));
            return true;
        },
        Integer.MAX_VALUE,
        TimeUnit.MILLISECONDS
    );

    return success.get() ? p : null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:BadHandshakeTest.java

示例4: 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

示例5: run

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        process = ProcessTools.startProcess(getName(), pb, predicate, 10, TimeUnit.SECONDS);
        latch.countDown();
        process.waitFor();
    } catch (Exception e) {
        throw new RuntimeException("Test failed", e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:JMXInterfaceBindingTest.java

示例6: runClientSide

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
 * Runs AuthorizationTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String args[], String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine(args);
    opts.add("-serviceUrl");
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("AuthorizationTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );

    } finally {
        if (p.isAlive()) {
            p.destroyForcibly();
        }
        return exitCode;
    }

 }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:AuthorizationTest.java

示例7: runClientSide

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:MXBeanWeirdParamTest.java

示例8: traceTest

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
 * Runs LowMemoryTest$TestMain with the passed options and redirects subprocess
 * standard I/O to the current (parent) process. This provides a trace of what
 * happens in the subprocess while it is runnning (and before it terminates).
 *
 * @param prefixName the prefix string for redirected outputs
 * @param testOpts java options specified by the test.
 */
private static void traceTest(String prefixName,
                              String... testOpts)
            throws Throwable {

    // Building command-line
    List<String> opts = buildCommandLine(testOpts);

    // We activate all tracing in subprocess
    opts.add("trace");

    // Launch separate JVM subprocess
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    System.out.println("\n========= Tracing of subprocess " + prefixName + " =========");
    Process p = ProcessTools.startProcess(prefixName, pb);

    // Handling end of subprocess
    try {
        int exitCode = p.waitFor();
        if (exitCode != 0) {
            throw new RuntimeException(
                "Subprocess unexpected exit value of [" + exitCode + "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        throw new RuntimeException("Parent process interrupted with exception : \n " + e + " :" );
    }


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

示例9: startTestApp

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
@BeforeMethod
public final void startTestApp() throws Exception {
    testApp = ProcessTools.startProcess(
        TEST_APP_NAME, testAppPb,
        (Predicate<String>)l->l.trim().equals("main enter")
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:JMXStatusTest.java

示例10: start

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public synchronized void start() throws InterruptedException, IOException, TimeoutException {
    if (started.compareAndSet(false, true)) {
        try {
            AtomicBoolean error = new AtomicBoolean(false);
            p = ProcessTools.startProcess(
                    TEST_APP_NAME + "{" + name + "}",
                    pb,
                    (line) -> {
                        boolean ok = line.equals("main enter");
                        error.set(line.contains("BindException"));

                        return ok || error.get();
                    }
            );
            if (error.get()) {
                throw new BindException("Starting process failed due to " +
                                        "the requested port not being available");
            }
            pid = p.pid();
        } catch (TimeoutException e) {
            if (p != null) {
                p.destroy();
                p.waitFor();
            }
            throw e;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:JMXStartStopTest.java

示例11: startTestApp

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
@BeforeMethod
public void startTestApp() throws Exception {
    testApp = ProcessTools.startProcess(
        TEST_APP_NAME, testAppPb,
        (Predicate<String>)l->l.trim().equals("main enter")
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:JMXStatusPerfCountersTest.java

示例12: launch

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
private static LaunchResult launch(String address, String class_name) throws Exception {
    String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
        "-agentlib:jdwp=transport=dt_socket" +
        ",server=y" + ",suspend=y" + ",address=" + address,
        class_name
    });

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);

    final AtomicBoolean success = new AtomicBoolean();
    final AtomicBoolean bindFailed = new AtomicBoolean();
    Process p = ProcessTools.startProcess(
        class_name,
        pb,
        (line) -> {
            // 'Listening for transport dt_socket at address: xxxxx'
            // indicates the debuggee is ready to accept connections
            if (line.contains("Listening for transport dt_socket at address:")) {
                success.set(true);
                return true;
            }
            // 'Address already in use' indicates
            // the debuggee has failed to start due to busy port.
            if (line.contains("Address already in use")) {
                bindFailed.set(true);
                return true;
            }
            return false;
        },
        Integer.MAX_VALUE,
        TimeUnit.MILLISECONDS
    );

    return new LaunchResult(success.get() ? p : null,
            bindFailed.get());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:BadHandshakeTest.java

示例13: main

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess(
            "process1",
            process1,
            line -> line.equals("Listening for transport dt_socket at address: " + address),
            Math.round(5000 * Utils.TIMEOUT_FACTOR),
            TimeUnit.MILLISECONDS
    );

    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:ExclusiveBind.java

示例14: runClientSide

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
/**
 * Runs SecurityTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String args[], String serviceUrlStr) throws Exception {

    System.out.println("SecurityTest::runClientSide: Start") ;

    // Building command-line
    List<String> opts = buildCommandLine(args);
    opts.add("-serviceUrl");
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("SecurityTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );

    } finally {
        if (p.isAlive()) {
            p.destroyForcibly();
        }

        System.out.println("SecurityTest::runClientSide: Done") ;

        return exitCode;
    }

 }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:SecurityTest.java

示例15: main

import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-cp",
        System.getProperty("test.class.path"),
        "-XX:+UsePerfData",
        Application.class.getName()
    );
    AtomicBoolean error = new AtomicBoolean(false);
    Process app = ProcessTools.startProcess(
        "application",
        pb,
        line -> {
            if (line.equals(READY)) {
                return true;
            } else if (line.equals(ERROR)) {
                error.set(true);
                return true;
            }
            return false;
        },
        10,
        TimeUnit.SECONDS
    );
    if (error.get()) {
        throw new Error("Unable to start the monitored application.");
    }

    String pidStr = String.valueOf(app.pid());
    JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat");
    l.addToolArg("-compiler");
    l.addToolArg(pidStr);
    l.addToolArg("100");

    ProcessBuilder jstatDef = new ProcessBuilder(l.getCommand());
    Process jstat = ProcessTools.startProcess(
        "jstat",
        jstatDef,
        line -> {
            if (line.trim().toLowerCase().startsWith("compiled")) {
                return true;
            }
            return false;
        },
        10,
        TimeUnit.SECONDS
    );

    app.getOutputStream().write(0);
    app.getOutputStream().flush();

    if (app.waitFor() != 0) {
        throw new Error("Error detected upon exiting the monitored application with active jstat");
    }
    if (jstat.waitFor() != 0) {
        throw new Error("Error detected in jstat when monitored application has exited prematurely");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:JStatInterval.java


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