Java Code Examples for jdk.testlibrary.Utils

The following examples show how to use jdk.testlibrary.Utils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static void testConnect(int port, int rmiPort) throws Exception {
    EOFException lastException = null;
    // factor adjusted timeout (5 seconds) for the RMI to become available
    long timeout = System.currentTimeMillis() + Utils.adjustTimeout(5000);
    do {
        try {
            doTestConnect(port, rmiPort);
            lastException = null;
        } catch (EOFException e) {
            lastException = e;
            System.out.println("Error establishing RMI connection. Retrying in 500ms.");
            Thread.sleep(500);
        }
    } while (lastException != null && System.currentTimeMillis() < timeout);

    if (lastException != null) {
        // didn't manage to get the RMI running in time
        // rethrow the exception
        throw lastException;
    }
}
 
Example 2
Source Project: jdk8u-dev-jdk   Source File: RunUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "'");
    }
}
 
Example 3
Source Project: openjdk-jdk9   Source File: JstatdTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example 4
Source Project: hottub   Source File: RunUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "'");
    }
}
 
Example 5
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example 6
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example 7
Source Project: jdk8u-jdk   Source File: PremainClassTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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!");
}
 
Example 8
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");
    }
}
 
Example 9
/**
 * 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;
}
 
Example 10
Source Project: jdk8u_jdk   Source File: DynamicLauncher.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example 11
private static JMXConnector connect(JMXServiceURL addr) {
    final long timeout = Utils.adjustTimeout(100);

    JMXConnector connector = null;
    while (connector == null) {
        try {
            connector = JMXConnectorFactory.connect(addr);
        } catch (IOException e) {
            System.out.println("Connection error. Retrying after delay...");
            delay(timeout);
        } catch (Exception otherException) {
            System.out.println("Unexpected exception while connecting " + otherException);
            throw new RuntimeException(otherException);
        }
    }
    return connector;
}
 
Example 12
Source Project: hottub   Source File: ClipboardInterVMTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example 13
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example 14
Source Project: jdk8u-jdk   Source File: RunUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "'");
    }
}
 
Example 15
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example 16
Source Project: jdk8u-jdk   Source File: DynamicLauncher.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example 17
Source Project: openjdk-jdk8u   Source File: JstatdTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example 18
Source Project: TencentKona-8   Source File: JstatdTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example 19
Source Project: openjdk-8   Source File: NoPremainAgentTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 20
Source Project: jdk8u60   Source File: NoPremainAgentTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 21
Source Project: jdk8u60   Source File: PremainClassTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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!");
}
 
Example 22
Source Project: hottub   Source File: JstatdTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
Example 23
Source Project: jdk8u60   Source File: RunUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "'");
    }
}
 
Example 24
Source Project: jdk8u60   Source File: DynamicLauncher.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
Example 25
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
Example 26
Source Project: jdk8u_jdk   Source File: RunUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "'");
    }
}
 
Example 27
Source Project: openjdk-8   Source File: PremainClassTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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!");
}
 
Example 28
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");
    }
}
 
Example 29
Source Project: openjdk-jdk8u-backup   Source File: RunUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "'");
    }
}
 
Example 30
Source Project: jdk8u_jdk   Source File: TestJcmdDefaults.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
    File file = new File(TEST_SRC, "usage.out");
    List<String> fileOutput = Utils.fileAsList(file);
    List<String> outputAsLines = output.asLines();
    assertTrue(outputAsLines.containsAll(fileOutput),
            "The ouput should contain all content of " + file.getAbsolutePath());
}