Search in sources :

Example 6 with JDKToolLauncher

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

the class JstatdTest method runJstat.

/**
     * Depending on test settings command line can look like:
     *
     * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname 250 5
     * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname:port 250 5
     * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname/serverName 250 5
     * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname:port/serverName 250 5
     */
private OutputAnalyzer runJstat() throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstat");
    launcher.addVMArg("-XX:+UsePerfData");
    launcher.addVMArg("-Duser.language=en");
    launcher.addToolArg("-gcutil");
    launcher.addToolArg(jstatdPid + "@" + getDestination());
    launcher.addToolArg(Integer.toString(JSTAT_GCUTIL_INTERVAL_MS));
    launcher.addToolArg(Integer.toString(JSTAT_GCUTIL_SAMPLES));
    String[] cmd = launcher.getCommand();
    log("Start jstat", 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 7 with JDKToolLauncher

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

the class MultiDead method parentProcess.

private static void parentProcess() throws Throwable {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java").addToolArg("MultiDead").addToolArg("child");
    ProcessBuilder pb = new ProcessBuilder(launcher.getCommand());
    AtomicReference<Process> child = new AtomicReference<>();
    AtomicBoolean stopFlag = new AtomicBoolean(false);
    Thread th = new Thread(() -> {
        for (int i = 0; i < CHILDREN_COUNT; ++i) {
            System.out.println("child #" + (i + 1) + " of " + CHILDREN_COUNT);
            long start = System.nanoTime();
            try {
                child.set(pb.start());
                child.get().waitFor();
                if (stopFlag.get()) {
                    break;
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (System.nanoTime() - start > MILLISECONDS.toNanos(CHILD_TIMEOUT)) {
                System.err.println("Machine is too slow, " + "skipping the test...");
                break;
            }
        }
    });
    th.start();
    th.join(TIMEOUT);
    stopFlag.set(true);
    if (th.isAlive()) {
        if (child.get() != null) {
            child.get().destroyForcibly();
        }
        throw new RuntimeException("Failed to complete on time.");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 8 with JDKToolLauncher

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

the class JaxbMarshallTest method compileXjcGeneratedClasses.

// Compile java classes with javac tool
void compileXjcGeneratedClasses() throws Exception {
    JDKToolLauncher javacLauncher = JDKToolLauncher.createUsingTestJDK("javac");
    javacLauncher.addToolArg(xjcResultDir.resolve("ObjectFactory.java").toString());
    javacLauncher.addToolArg(xjcResultDir.resolve("TypesLongList.java").toString());
    javacLauncher.addToolArg(xjcResultDir.resolve("package-info.java").toString());
    System.out.println("Compiling xjc generated classes: " + Arrays.asList(javacLauncher.getCommand()));
    ProcessBuilder pb = new ProcessBuilder(javacLauncher.getCommand());
    pb.inheritIO();
    pb.directory(testWorkDir.toFile());
    Process p = pb.start();
    p.waitFor();
    p.destroy();
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher)

Example 9 with JDKToolLauncher

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

the class JaxbMarshallTest method runXjc.

// Compile schema file into java classes definitions
void runXjc(String xsdFileName) throws Exception {
    // Prepare process builder to run schemagen tool and save its output
    JDKToolLauncher xjcLauncher = JDKToolLauncher.createUsingTestJDK("xjc");
    xjcLauncher.addToolArg(xsdFileName);
    System.out.println("Executing xjc command: " + Arrays.asList(xjcLauncher.getCommand()));
    ProcessBuilder pb = new ProcessBuilder(xjcLauncher.getCommand());
    // Set xjc work directory with the input java file
    pb.directory(testWorkDir.toFile());
    pb.inheritIO();
    Process p = pb.start();
    p.waitFor();
    p.destroy();
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher)

Example 10 with JDKToolLauncher

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

the class TestJstatdUsage method testUsage.

private static void testUsage(String option) throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
    launcher.addToolArg(option);
    ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
    output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]");
    output.shouldHaveExitValue(1);
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

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