Search in sources :

Example 1 with JDKToolLauncher

use of jdk.testlibrary.JDKToolLauncher in project jdk8u_jdk by JetBrains.

the class JMXStartStopTest method jcmd.

/**
     * 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] --------");
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher)

Example 2 with JDKToolLauncher

use of jdk.testlibrary.JDKToolLauncher in project jdk8u_jdk by JetBrains.

the class NativeErrors method executeCmd.

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();
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer) MissingResourceException(java.util.MissingResourceException)

Example 3 with JDKToolLauncher

use of jdk.testlibrary.JDKToolLauncher in project jdk8u_jdk by JetBrains.

the class JpsHelper method jps.

/**
     * Start jps utility with VM args and tool arguments
     */
public static OutputAnalyzer jps(List<String> vmArgs, List<String> toolArgs) throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
    if (vmArgs != null) {
        for (String vmArg : vmArgs) {
            launcher.addVMArg(vmArg);
        }
    }
    if (toolArgs != null) {
        for (String toolArg : toolArgs) {
            launcher.addToolArg(toolArg);
        }
    }
    ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
    System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
    System.out.println(output.getOutput());
    return output;
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 4 with JDKToolLauncher

use of jdk.testlibrary.JDKToolLauncher in project jdk8u_jdk by JetBrains.

the class JstatdTest method runJps.

/**
     * Depending on test settings command line can look like:
     *
     * jps -J-XX:+UsePerfData hostname
     * jps -J-XX:+UsePerfData hostname:port
     * jps -J-XX:+UsePerfData hostname/serverName
     * jps -J-XX:+UsePerfData hostname:port/serverName
     */
private OutputAnalyzer runJps() throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
    launcher.addVMArg("-XX:+UsePerfData");
    // Run jps with -v flag to obtain -Dparent.pid.<pid>
    launcher.addToolArg("-v");
    launcher.addToolArg(getDestination());
    String[] cmd = launcher.getCommand();
    log("Start jps", cmd);
    ProcessBuilder processBuilder = new ProcessBuilder(cmd);
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
    System.out.println(output.getOutput());
    return output;
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 5 with JDKToolLauncher

use of jdk.testlibrary.JDKToolLauncher in project jdk8u_jdk by JetBrains.

the class JstatdTest method getJstatdCmd.

/**
     * 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;
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) File(java.io.File)

Aggregations

JDKToolLauncher (jdk.testlibrary.JDKToolLauncher)12 OutputAnalyzer (jdk.testlibrary.OutputAnalyzer)5 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 MissingResourceException (java.util.MissingResourceException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.testng.annotations.Test)1