• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ProcessTools类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: executeKeytoolCommand

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static OutputAnalyzer executeKeytoolCommand(String[] command,
        int exitCode) {
    String[] keytoolCmd = new String[command.length + 1];
    OutputAnalyzer output = null;
    try {
        keytoolCmd[0] = JDKToolFinder.getJDKTool(KEYTOOL);
        System.arraycopy(command, 0, keytoolCmd, 1, command.length);
        output = ProcessTools.executeCommand(keytoolCmd);
        output.shouldHaveExitValue(exitCode);
        out.println("Executed keytool command sucessfully:"
                + Arrays.toString(keytoolCmd));
    } catch (Throwable e) {
        e.printStackTrace(System.err);
        throw new RuntimeException("Keytool Command execution failed : "
                + Arrays.toString(keytoolCmd), e);
    }
    return output;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:Utils.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 = new OutputAnalyzer(pb.start());
    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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数: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 = 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


示例4: 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 = new OutputAnalyzer(pb.start());
    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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ZeroArgPremainAgentTest.java


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


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


示例7: doSomething

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Runs the test application "JMXStartStopDoSomething"
 * @param name Test run name
 * @param args Additional arguments
 * @return Returns a {@linkplain Something} instance representing the run
 * @throws IOException
 * @throws InterruptedException
 * @throws TimeoutException
 */
private static Something doSomething(String name, String ... args)
throws Exception {
    List<String> pbArgs = new ArrayList<>(Arrays.asList(
        "-cp",
        System.getProperty("test.class.path")
    ));
    pbArgs.addAll(Arrays.asList(args));
    pbArgs.add("JMXStartStopDoSomething");

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        pbArgs.toArray(new String[pbArgs.size()])
    );
    Something s = new Something(pb, name);
    s.start();
    return s;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:JMXStartStopTest.java


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


示例9: 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(jar.getAbsolutePath());
    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,代码来源:TestJpsJar.java


示例10: 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", "?");
    String testClassPath = System.getProperty("test.class.path", "?");

    List<String> cmd = new ArrayList<>();
    cmd.addAll(JpsHelper.getVmArgs());
    cmd.add("-Dtest.jdk=" + testJdk);
    cmd.add("-Dtest.src=" + testSrc);
    cmd.add("-cp");
    cmd.add(testClassPath);
    cmd.add("JpsBase");
    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,代码行数:20,代码来源:TestJpsClass.java


示例11: parsePid

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Parse pid from jps output
 */
private String parsePid(String tool, OutputAnalyzer output) throws Exception {
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    String pid = null;
    int count = 0;
    String processName = tool;
    if (tool == "rmiregistry") {
        processName = "registryimpl";
    }

    Pattern toolInJpsPattern =
            Pattern.compile("^\\d+\\s{1}" + processName + "\\s{1}.*-dparent\\.pid\\." + ProcessTools.getProcessId() + ".*");
    for (String line : lines) {
        if (toolInJpsPattern.matcher(line.toLowerCase()).matches()) {
            pid = line.split(" ")[0];
            count++;
        }
    }
    if (count > 1) {
        throw new Exception("Expected one " + tool
                + " process, got " + count + ". Test will be canceled.");
    }

    return pid;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:JstatdTest.java


示例12: getJstatdCmd

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Depending on test settings command line can look like:
 *
 * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy
 * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port
 * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -n serverName
 * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port -n serverName
 */
private String[] getJstatdCmd() throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
    launcher.addVMArg("-XX:+UsePerfData");
    String testSrc = System.getProperty("test.src");
    File policy = new File(testSrc, "all.policy");
    assertTrue(policy.exists() && policy.isFile(),
            "Security policy " + policy.getAbsolutePath() + " does not exist or not a file");
    launcher.addVMArg("-Djava.security.policy=" + policy.getAbsolutePath());
    // -Dparent.pid.<pid> will help to identify jstad process started by this test
    launcher.addVMArg("-Dparent.pid." + ProcessTools.getProcessId());
    if (port != null) {
        launcher.addToolArg("-p");
        launcher.addToolArg(port);
    }
    if (serverName != null) {
        launcher.addToolArg("-n");
        launcher.addToolArg(serverName);
    }

    String[] cmd = launcher.getCommand();
    log("Start jstatd", cmd);
    return cmd;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:JstatdTest.java


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


示例14: 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(" ")) {
        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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ExclusiveBind.java


示例15: launchTests

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path and
 * the -Djava.io.tmpdir property.
 */
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";

    String[] tmpDirArg = null;
    if (clientTmpDir != null) {
        tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
    }

    // Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
    String[] args = RunnerUtil.concat(
            tmpDirArg,
            new String[] {
                "-classpath",
                classpath,
                "TempDirTest$TestMain",
                Integer.toString(pid) });
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:TempDirTest.java


示例16: runTests

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Runs the actual tests in the nested class TestMain.
 * We need to run the tests in a separate process,
 * because we need to add to the classpath.
 */
private static void runTests() throws Throwable {
    final String sep = File.separator;
    String testClassPath = System.getProperty("test.class.path", "");
    String testClasses = System.getProperty("test.classes", "") + sep;
    String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;

    // Need to add SimpleProvider.jar and tools.jar to classpath.
    String classpath =
            testClassPath + File.pathSeparator +
            testClasses + "SimpleProvider.jar" + File.pathSeparator +
            jdkLib + "tools.jar";

    String[] args = {
            "-classpath",
            classpath,
            "ProviderTest$TestMain" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:ProviderTest.java


示例17: stopApplication

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Will stop the running Application.
 * First tries to shutdown nicely by connecting to the shut down port.
 * If that fails, the process will be killed hard with stopProcess().
 *
 * If the nice shutdown fails, then an Exception is thrown and the test should fail.
 *
 * @param port The shut down port.
 * @param processThread The process to stop.
 */
public static void stopApplication(int port, ProcessThread processThread) throws Throwable {
    if (processThread == null) {
        System.out.println("RunnerUtil.stopApplication ignored since proc is null");
        return;
    }
    try {
        System.out.println("RunnerUtil.stopApplication waiting to for shutdown");
        OutputAnalyzer output = ProcessTools.executeTestJvm(
                "-classpath",
                System.getProperty("test.class.path", "."),
                "Shutdown",
                Integer.toString(port));
        // Verify that both the Shutdown command and the Application finished ok.
        output.shouldHaveExitValue(0);
        processThread.joinAndThrow();
        processThread.getOutput().shouldHaveExitValue(0);
    } catch (Throwable t) {
        System.out.println("RunnerUtil.stopApplication failed. Will kill it hard: " + t);
        processThread.stopProcess();
        throw t;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:RunnerUtil.java


示例18: runTests

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:BasicTests.java


示例19: runJava

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
static void runJava(String[] args) {
    if (args == null || args.length < 3) {
        throw new IllegalArgumentException("wrong parameters");
    }

    List<String> cmds = new ArrayList<>();
    cmds.add(JAVA);
    StringBuilder sb = new StringBuilder();
    cmds.add("-classpath");
    for (int i=2; i<args.length; i++) {
        sb.append(args[i]).append(PS);
    }
    cmds.add(sb.toString());
    if (JAVA_OPTS != null && !JAVA_OPTS.isEmpty()) {
        Collections.addAll(cmds, JAVA_OPTS.trim().split("\\s+"));
    }
    cmds.add("-Djava.security.manager");
    cmds.add("-Djava.security.policy=" + TEST_SOURCES + FS + args[1]);
    cmds.add(args[0]);
    try {
        ProcessTools.executeCommand(cmds.toArray(new String[cmds.size()]))
                .shouldHaveExitValue(0);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:NestedActions.java


示例20: expectProviders

import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
 * Test that the resolution binds services that resolves additional
 * modules
 */
private void expectProviders(String... args) throws Exception {
    int exitValue = ProcessTools.executeTestJava(args)
            .outputTo(System.out)
            .errorTo(System.out)
            .stdoutShouldContain("root java.base")
            .stdoutShouldContain("root java.compiler")
            .stdoutShouldContain("root jdk.compiler")
            .stdoutShouldContain("root java.compiler")
            .stdoutShouldContain("jdk.compiler requires java.compiler")
            .stdoutShouldContain("java.base binds jdk.compiler")
            .stdoutShouldContain("java.base binds jdk.jdeps")
            .stdoutShouldContain("java.base binds jdk.zipfs")
            .stdoutShouldContain("java.compiler binds jdk.compiler")
            .stdoutShouldContain("jdk.jdeps requires jdk.compiler")
            .getExitValue();
    assertTrue(exitValue == 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ShowModuleResolutionTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FileSaverDescriptor类代码示例发布时间:2022-05-22
下一篇:
Java READDIR3Request类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap