Java Code Examples for jdk.test.lib.process.OutputAnalyzer#stdoutShouldMatch()

The following examples show how to use jdk.test.lib.process.OutputAnalyzer#stdoutShouldMatch() . 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
Source File: TestDeprecatedPrintFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void testXloggc() throws Exception {
    String fileName = "gc-test.log";
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xloggc:" + fileName, "DoGC");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead.");
    output.shouldNotContain("PrintGCDetails");
    output.shouldNotContain("PrintGC");
    output.stdoutShouldNotMatch("\\[info.*\\]\\[gc *\\]");
    output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
    output.shouldHaveExitValue(0);
    String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining());
    System.out.println("lines: " + lines);
    OutputAnalyzer outputLog = new OutputAnalyzer(lines, "");
    outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");
    outputLog.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
}
 
Example 2
Source File: TestOnOutOfMemoryError.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length == 1) {
        // This should guarantee to throw:
        //  java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        Object[] oa = new Object[Integer.MAX_VALUE];
        return;
    }

    // else this is the main test
    String msg = "Test Succeeded";
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
       "-XX:OnOutOfMemoryError=echo " + msg,
       TestOnOutOfMemoryError.class.getName(),
       "throwOOME");

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    /* Actual output should look like this:
       #
       # java.lang.OutOfMemoryError: Requested array size exceeds VM limit
       # -XX:OnOutOfMemoryError="echo Test Succeeded"
       #   Executing /bin/sh -c "echo Test Succeeded"...
       Test Succeeded
       Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
       at OOME.main(OOME.java:3)

       So we don't want to match on the "# Executing ..." line, and they
       both get written to stdout.
    */
    output.shouldContain("Requested array size exceeds VM limit");
    output.stdoutShouldMatch("^" + msg); // match start of line only
    System.out.println("PASSED");
}
 
Example 3
Source File: TestOnError.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (!Platform.isDebugBuild()) {
        System.out.println("Test requires a non-product build - skipping");
        return;
    }

    String msg = "Test Succeeded";

    // Execute the VM so that a
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
       "-XX:-TransmitErrorReport",
       "-XX:-CreateCoredumpOnCrash",
       "-XX:ErrorHandlerTest=12", // trigger potential SEGV
       "-XX:OnError=echo " + msg,
       TestOnError.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    /* Actual output will include:
       #
       # -XX:OnError="echo Test Succeeded"
       #   Executing /bin/sh -c "echo Test Succeeded"...
       Test Succeeded

       So we don't want to match on the "# Executing ..." line, and they
       both get written to stdout.
    */
    output.stdoutShouldMatch("^" + msg); // match start of line only
    System.out.println("PASSED");
}
 
Example 4
Source File: TestDeprecatedPrintFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void testXloggcWithPrintGCDetails() throws Exception {
    String fileName = "gc-test.log";
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", "-Xloggc:" + fileName, "DoGC");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");
    output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead.");
    output.shouldNotContain("PrintGC is deprecated");
    output.stdoutShouldNotMatch("\\[info.*\\]\\[gc *\\]");
    output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
    output.shouldHaveExitValue(0);
    String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining());
    OutputAnalyzer outputLog = new OutputAnalyzer(lines, "");
    outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");
    outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc\\,");
}
 
Example 5
Source File: TestDeprecatedPrintFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void testPrintGCDetails() throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", "DoGC");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");
    output.shouldNotContain("PrintGC is deprecated");
    output.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");
    output.stdoutShouldMatch("\\[info.*\\]\\[gc\\,");
    output.shouldHaveExitValue(0);
}
 
Example 6
Source File: TestDeprecatedPrintFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void testPrintGC() throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGC", "DoGC");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead.");
    output.shouldNotContain("PrintGCDetails");
    output.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");
    output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
    output.shouldHaveExitValue(0);
}
 
Example 7
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsScheduled(OutputAnalyzer output, String name, String delay) {
    output.stdoutShouldMatch(
            "^\\s*Recording\\s+" + name + "\\s+scheduled to start in " + delay);
}
 
Example 8
Source File: TestDefaultLogOutput.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:badTag");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.stdoutShouldMatch("\\[error *\\]\\[logging *\\]");
    output.shouldHaveExitValue(1);
}
 
Example 9
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertMonitorWaitThresholdIsSet(OutputAnalyzer output) throws Exception {
    output.stdoutShouldMatch("\\s+\\W{1}" + EventNames.JavaMonitorWait + "\\W{1}" +
            NEW_LINE + ".*threshold=1 ms.*");
}
 
Example 10
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertThreadSleepThresholdIsSet(OutputAnalyzer output) throws Exception {
    output.stdoutShouldMatch("\\s+\\W{1}" + EventNames.ThreadSleep + "\\W{1}" +
            NEW_LINE + ".*threshold=1 ms.*");
}
 
Example 11
Source File: JcmdAsserts.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsUnstarted(OutputAnalyzer output,
        String name, String duration) {
    output.stdoutShouldMatch("^Recording \\d+: name=" + name
            + " duration=" + duration + " .*\\W{1}unstarted\\W{1}");
}
 
Example 12
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsStopped(OutputAnalyzer output, String name, String duration) {
    output.stdoutShouldMatch("^Recording \\d+: name=" + name
            + " duration=" + duration + " .*\\W{1}stopped\\W{1}");
}
 
Example 13
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsStopped(OutputAnalyzer output, String name) {
    output.stdoutShouldMatch("^Recording \\d+: name=" + name
            + " .*\\W{1}stopped\\W{1}");
}
 
Example 14
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsUnstarted(OutputAnalyzer output,
        String name, String duration) {
    output.stdoutShouldMatch("^Recording \\d+: name=" + name
            + " duration=" + duration + " .*\\W{1}unstarted\\W{1}");
}
 
Example 15
Source File: JcmdAsserts.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void assertMonitorWaitThresholdIsSet(OutputAnalyzer output) throws Exception {
    output.stdoutShouldMatch("\\s+\\W{1}" + EventNames.JavaMonitorWait + "\\W{1}" +
            NEW_LINE + ".*threshold=1 ms.*");
}
 
Example 16
Source File: JcmdAsserts.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void assertThreadSleepThresholdIsSet(OutputAnalyzer output) throws Exception {
    output.stdoutShouldMatch("\\s+\\W{1}" + EventNames.ThreadSleep + "\\W{1}" +
            NEW_LINE + ".*threshold=1 ms.*");
}
 
Example 17
Source File: JcmdAsserts.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsScheduled(OutputAnalyzer output, String name, String delay) {
    output.stdoutShouldMatch(
            "^\\s*Recording\\s+" + name + "\\s+scheduled to start in " + delay);
}
 
Example 18
Source File: JcmdAsserts.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsStopped(OutputAnalyzer output, String name, String duration) {
    output.stdoutShouldMatch("^Recording \\d+: name=" + name
            + " duration=" + duration + " .*\\W{1}stopped\\W{1}");
}
 
Example 19
Source File: JcmdAsserts.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsStopped(OutputAnalyzer output, String name) {
    output.stdoutShouldMatch("^Recording \\d+: name=" + name
            + " .*\\W{1}stopped\\W{1}");
}