Java Code Examples for jdk.testlibrary.OutputAnalyzer#shouldMatch()

The following examples show how to use jdk.testlibrary.OutputAnalyzer#shouldMatch() . 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: Test.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void checkVerifying(OutputAnalyzer analyzer, int expectedExitCode,
        String... warnings) {
    analyzer.shouldHaveExitValue(expectedExitCode);
    int count = 0;
    for (String warning : warnings) {
        if (warning.startsWith("!")) {
            analyzer.shouldNotContain(warning.substring(1));
        } else {
            count++;
            analyzer.shouldContain(warning);
        }
    }
    if (count > 0) {
        analyzer.shouldMatch(WARNING_OR_ERROR);
    }
    if (expectedExitCode == 0) {
        analyzer.shouldContain(JAR_VERIFIED);
    } else {
        analyzer.shouldContain(JAR_VERIFIED_WITH_SIGNER_ERRORS);
    }
}
 
Example 2
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected void checkVerifying(OutputAnalyzer analyzer, int expectedExitCode,
        String... warnings) {
    analyzer.shouldHaveExitValue(expectedExitCode);
    int count = 0;
    for (String warning : warnings) {
        if (warning.startsWith("!")) {
            analyzer.shouldNotContain(warning.substring(1));
        } else {
            count++;
            analyzer.shouldContain(warning);
        }
    }
    if (count > 0) {
        analyzer.shouldMatch(WARNING_OR_ERROR);
    }
    if (expectedExitCode == 0) {
        analyzer.shouldContain(JAR_VERIFIED);
    } else {
        analyzer.shouldContain(JAR_VERIFIED_WITH_SIGNER_ERRORS);
    }
}
 
Example 3
Source File: JcmdHelper.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void waitUntilRunning(String name) throws Exception {
    long timeoutAt = System.currentTimeMillis() + 10000;
    while (true) {
        OutputAnalyzer output = jcmdCheck(name, false);
        try {
            // The expected output can look like this:
            // Recording: recording=1 name="Recording 1" (running)
            output.shouldMatch("^Recording: recording=\\d+\\s+name=\"" + name
                    + "\".*\\W{1}running\\W{1}");
            return;
        } catch (RuntimeException e) {
            if (System.currentTimeMillis() > timeoutAt) {
                Asserts.fail("Recording not started: " + name);
            }
            Thread.sleep(100);
        }
    }
}
 
Example 4
Source File: JcmdHelper.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void waitUntilRunning(String name) throws Exception {
    long timeoutAt = System.currentTimeMillis() + 10000;
    while (true) {
        OutputAnalyzer output = jcmdCheck(name, false);
        try {
            // The expected output can look like this:
            // Recording: recording=1 name="Recording 1" (running)
            output.shouldMatch("^Recording: recording=\\d+\\s+name=\"" + name
                    + "\".*\\W{1}running\\W{1}");
            return;
        } catch (RuntimeException e) {
            if (System.currentTimeMillis() > timeoutAt) {
                Asserts.fail("Recording not started: " + name);
            }
            Thread.sleep(100);
        }
    }
}
 
Example 5
Source File: Test.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void checkSigning(OutputAnalyzer analyzer, String... warnings) {
    analyzer.shouldHaveExitValue(0);
    int count = 0;
    for (String warning : warnings) {
        if (warning.startsWith("!")) {
            analyzer.shouldNotContain(warning.substring(1));
        } else {
            count++;
            analyzer.shouldContain(warning);
        }
    }
    if (count > 0) {
        analyzer.shouldMatch(WARNING_OR_ERROR);
    }
    analyzer.shouldContain(JAR_SIGNED);
}
 
Example 6
Source File: TestJpsSanity.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testJpsUnknownHost() throws Exception {
    String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C.invalid";
    OutputAnalyzer output = JpsHelper.jps(invalidHostName);
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldMatch(".*(RMI Registry not available at|Unknown host\\:) " + invalidHostName + ".*");
}
 
Example 7
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertCommercialUnlocked(OutputAnalyzer output) {
    output.shouldMatch("Commercial Features (now|already) unlocked");
}
 
Example 8
Source File: JpsBase.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int pid = ProcessTools.getProcessId();

    List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
    for (List<JpsHelper.JpsArg> combination : combinations) {
        OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
        output.shouldHaveExitValue(0);

        boolean isQuiet = false;
        boolean isFull = false;
        String pattern;
        for (JpsHelper.JpsArg jpsArg : combination) {
            switch (jpsArg) {
            case q:
                // If '-q' is specified output should contain only a list of local VM identifiers:
                // 30673
                isQuiet = true;
                JpsHelper.verifyJpsOutput(output, "^\\d+$");
                output.shouldContain(Integer.toString(pid));
                break;
            case l:
                // If '-l' is specified output should contain the full package name for the application's main class
                // or the full path name to the application's JAR file:
                // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                isFull = true;
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                output.shouldMatch(pattern);
                break;
            case m:
                // If '-m' is specified output should contain the arguments passed to the main method:
                // 30673 JpsBase monkey ...
                for (String arg : args) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case v:
                // If '-v' is specified output should contain VM arguments:
                // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
                for (String vmArg : JpsHelper.getVmArgs()) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case V:
                // If '-V' is specified output should contain VM flags:
                // 30673 JpsBase +DisableExplicitGC ...
                pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
                output.shouldMatch(pattern);
                break;
            }

            if (isQuiet) {
                break;
            }
        }

        if (!isQuiet) {
            // Verify output line by line.
            // Output should only contain lines with pids after the first line with pid.
            JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
            if (!isFull) {
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                if (combination.isEmpty()) {
                    // If no arguments are specified output should only contain
                    // pid and process name
                    pattern += "$";
                } else {
                    pattern += ".*";
                }
                output.shouldMatch(pattern);
            }
        }
    }
}
 
Example 9
Source File: TestJpsSanity.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsLong() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-l");
    output.shouldMatch("^[0-9]+ jdk\\.jcmd/sun\\.tools\\.jps\\.Jps$");
}
 
Example 10
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertStoppedAndWrittenTo(OutputAnalyzer output, String name, File file) {
    output.shouldMatch("^Stopped recording \"" + name + "\"" + ".*written to:");
    output.shouldContain(file.getAbsolutePath());
}
 
Example 11
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertRecordingIsRunning(OutputAnalyzer output, String name) {
    output.shouldMatch(".*" + name + ".*running");
}
 
Example 12
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertFileNotFoundException(OutputAnalyzer output, String name) {
    output.shouldMatch("Could not write recording \"" + name + "\" to file.*");
}
 
Example 13
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertCommercialUnlocked(OutputAnalyzer output) {
    output.shouldMatch("Commercial Features (now|already) unlocked");
}
 
Example 14
Source File: JpsBase.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int pid = ProcessTools.getProcessId();

    List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
    for (List<JpsHelper.JpsArg> combination : combinations) {
        OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
        output.shouldHaveExitValue(0);

        boolean isQuiet = false;
        boolean isFull = false;
        String pattern;
        for (JpsHelper.JpsArg jpsArg : combination) {
            switch (jpsArg) {
            case q:
                // If '-q' is specified output should contain only a list of local VM identifiers:
                // 30673
                isQuiet = true;
                JpsHelper.verifyJpsOutput(output, "^\\d+$");
                output.shouldContain(Integer.toString(pid));
                break;
            case l:
                // If '-l' is specified output should contain the full package name for the application's main class
                // or the full path name to the application's JAR file:
                // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                isFull = true;
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                output.shouldMatch(pattern);
                break;
            case m:
                // If '-m' is specified output should contain the arguments passed to the main method:
                // 30673 JpsBase monkey ...
                for (String arg : args) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case v:
                // If '-v' is specified output should contain VM arguments:
                // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
                for (String vmArg : JpsHelper.getVmArgs()) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case V:
                // If '-V' is specified output should contain VM flags:
                // 30673 JpsBase +DisableExplicitGC ...
                pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
                output.shouldMatch(pattern);
                break;
            }

            if (isQuiet) {
                break;
            }
        }

        if (!isQuiet) {
            // Verify output line by line.
            // Output should only contain lines with pids after the first line with pid.
            JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
            if (!isFull) {
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                if (combination.isEmpty()) {
                    // If no arguments are specified output should only contain
                    // pid and process name
                    pattern += "$";
                } else {
                    pattern += ".*";
                }
                output.shouldMatch(pattern);
            }
        }
    }
}
 
Example 15
Source File: JpsBase.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int pid = ProcessTools.getProcessId();

    List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
    for (List<JpsHelper.JpsArg> combination : combinations) {
        OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
        output.shouldHaveExitValue(0);

        boolean isQuiet = false;
        boolean isFull = false;
        String pattern;
        for (JpsHelper.JpsArg jpsArg : combination) {
            switch (jpsArg) {
            case q:
                // If '-q' is specified output should contain only a list of local VM identifiers:
                // 30673
                isQuiet = true;
                JpsHelper.verifyJpsOutput(output, "^\\d+$");
                output.shouldContain(Integer.toString(pid));
                break;
            case l:
                // If '-l' is specified output should contain the full package name for the application's main class
                // or the full path name to the application's JAR file:
                // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                isFull = true;
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                output.shouldMatch(pattern);
                break;
            case m:
                // If '-m' is specified output should contain the arguments passed to the main method:
                // 30673 JpsBase monkey ...
                for (String arg : args) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case v:
                // If '-v' is specified output should contain VM arguments:
                // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
                for (String vmArg : JpsHelper.getVmArgs()) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case V:
                // If '-V' is specified output should contain VM flags:
                // 30673 JpsBase +DisableExplicitGC ...
                pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
                output.shouldMatch(pattern);
                break;
            }

            if (isQuiet) {
                break;
            }
        }

        if (!isQuiet) {
            // Verify output line by line.
            // Output should only contain lines with pids after the first line with pid.
            JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
            if (!isFull) {
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                if (combination.isEmpty()) {
                    // If no arguments are specified output should only contain
                    // pid and process name
                    pattern += "$";
                } else {
                    pattern += ".*";
                }
                output.shouldMatch(pattern);
            }
        }
    }
}
 
Example 16
Source File: JpsBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int pid = ProcessTools.getProcessId();

    List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
    for (List<JpsHelper.JpsArg> combination : combinations) {
        OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
        output.shouldHaveExitValue(0);

        boolean isQuiet = false;
        boolean isFull = false;
        String pattern;
        for (JpsHelper.JpsArg jpsArg : combination) {
            switch (jpsArg) {
            case q:
                // If '-q' is specified output should contain only a list of local VM identifiers:
                // 30673
                isQuiet = true;
                JpsHelper.verifyJpsOutput(output, "^\\d+$");
                output.shouldContain(Integer.toString(pid));
                break;
            case l:
                // If '-l' is specified output should contain the full package name for the application's main class
                // or the full path name to the application's JAR file:
                // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                isFull = true;
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                output.shouldMatch(pattern);
                break;
            case m:
                // If '-m' is specified output should contain the arguments passed to the main method:
                // 30673 JpsBase monkey ...
                for (String arg : args) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case v:
                // If '-v' is specified output should contain VM arguments:
                // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
                for (String vmArg : JpsHelper.getVmArgs()) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case V:
                // If '-V' is specified output should contain VM flags:
                // 30673 JpsBase +DisableExplicitGC ...
                pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
                output.shouldMatch(pattern);
                break;
            }

            if (isQuiet) {
                break;
            }
        }

        if (!isQuiet) {
            // Verify output line by line.
            // Output should only contain lines with pids after the first line with pid.
            JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
            if (!isFull) {
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                if (combination.isEmpty()) {
                    // If no arguments are specified output should only contain
                    // pid and process name
                    pattern += "$";
                } else {
                    pattern += ".*";
                }
                output.shouldMatch(pattern);
            }
        }
    }
}
 
Example 17
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertStoppedAndWrittenTo(OutputAnalyzer output, String name, File file) {
    output.shouldMatch("^Stopped recording \"" + name + "\"" + ".*written to:");
    output.shouldContain(file.getAbsolutePath());
}
 
Example 18
Source File: JpsBase.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int pid = ProcessTools.getProcessId();

    List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
    for (List<JpsHelper.JpsArg> combination : combinations) {
        OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
        output.shouldHaveExitValue(0);

        boolean isQuiet = false;
        boolean isFull = false;
        String pattern;
        for (JpsHelper.JpsArg jpsArg : combination) {
            switch (jpsArg) {
            case q:
                // If '-q' is specified output should contain only a list of local VM identifiers:
                // 30673
                isQuiet = true;
                JpsHelper.verifyJpsOutput(output, "^\\d+$");
                output.shouldContain(Integer.toString(pid));
                break;
            case l:
                // If '-l' is specified output should contain the full package name for the application's main class
                // or the full path name to the application's JAR file:
                // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                isFull = true;
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                output.shouldMatch(pattern);
                break;
            case m:
                // If '-m' is specified output should contain the arguments passed to the main method:
                // 30673 JpsBase monkey ...
                for (String arg : args) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case v:
                // If '-v' is specified output should contain VM arguments:
                // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
                for (String vmArg : JpsHelper.getVmArgs()) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case V:
                // If '-V' is specified output should contain VM flags:
                // 30673 JpsBase +DisableExplicitGC ...
                pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
                output.shouldMatch(pattern);
                break;
            }

            if (isQuiet) {
                break;
            }
        }

        if (!isQuiet) {
            // Verify output line by line.
            // Output should only contain lines with pids after the first line with pid.
            JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
            if (!isFull) {
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                if (combination.isEmpty()) {
                    // If no arguments are specified output should only contain
                    // pid and process name
                    pattern += "$";
                } else {
                    pattern += ".*";
                }
                output.shouldMatch(pattern);
            }
        }
    }
}
 
Example 19
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertJfrUsed(OutputAnalyzer output) {
    output.shouldMatch("Flight Recorder has been used");
}
 
Example 20
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertJfrNotUsed(OutputAnalyzer output) {
    output.shouldMatch("Flight Recorder has not been used");
}