OpenJDK / portola / portola
changeset 28098:fbc3debb3d50
8066106: sun/tools/jps/TestJpsClass.java failed to remove stale attach pid file
Reviewed-by: jbachorik
author | ykantser |
---|---|
date | Mon, 01 Dec 2014 09:49:44 +0100 |
parents | fa1a96810647 |
children | 44dfaff3cc59 |
files | jdk/test/lib/testlibrary/OutputAnalyzerTest.java jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java jdk/test/sun/tools/jps/JpsHelper.java |
diffstat | 3 files changed, 57 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/test/lib/testlibrary/OutputAnalyzerTest.java Fri Nov 28 16:56:45 2014 +0100 +++ b/jdk/test/lib/testlibrary/OutputAnalyzerTest.java Mon Dec 01 09:49:44 2014 +0100 @@ -112,8 +112,10 @@ } String stdoutPattern = "[a]"; + String stdoutByLinePattern = "a*"; String stderrPattern = "[b]"; String nonExistingPattern = "[c]"; + String byLinePattern = "[ab]*"; // Should match try { @@ -148,6 +150,19 @@ // expected } + if (output.shouldMatchByLine(byLinePattern) != 1) { + throw new Exception("shouldMatchByLine() should find one line"); + } + try { + output.shouldMatchByLine(nonExistingPattern); + throw new Exception("shouldMatchByLine() failed to throw exception"); + } catch (RuntimeException e) { + // expected + } + if (output.stdoutShouldMatchByLine(stdoutByLinePattern) != 1) { + throw new Exception("stdoutShouldMatchByLine() should find one line"); + } + // Should not match try { output.shouldNotMatch(nonExistingPattern);
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java Fri Nov 28 16:56:45 2014 +0100 +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java Mon Dec 01 09:49:44 2014 +0100 @@ -25,13 +25,9 @@ import static jdk.testlibrary.Asserts.*; -import java.io.ByteArrayOutputStream; - import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -414,8 +410,12 @@ * @return Contents of the output buffer as list of strings */ public List<String> asLines() { + return asLines(getOutput()); + } + + private List<String> asLines(String buffer) { List<String> l = new ArrayList<>(); - String[] a = getOutput().split(Utils.NEW_LINE); + String[] a = buffer.split(Utils.NEW_LINE); for (String string : a) { l.add(string); } @@ -445,6 +445,13 @@ } /** + * @see #stdoutShouldMatchByLine(String, String, String) + */ + public int stdoutShouldMatchByLine(String pattern) { + return stdoutShouldMatchByLine(null, null, pattern); + } + + /** * @see #shouldMatchByLine(String, String, String) */ public int shouldMatchByLineFrom(String from, String pattern) { @@ -474,7 +481,30 @@ * @return Count of lines which match the {@code pattern} */ public int shouldMatchByLine(String from, String to, String pattern) { - List<String> lines = asLines(); + return shouldMatchByLine(getOutput(), from, to, pattern); + } + + /** + * Verify that the stdout contents of output buffer matches the + * {@code pattern} line by line. The whole stdout could be matched or + * just a subset of it. + * + * @param from + * The line from where stdout will be matched. + * Set {@code from} to null for matching from the first line. + * @param to + * The line until where stdout will be matched. + * Set {@code to} to null for matching until the last line. + * @param pattern + * Matching pattern + * @return Count of lines which match the {@code pattern} + */ + public int stdoutShouldMatchByLine(String from, String to, String pattern) { + return shouldMatchByLine(getStdout(), from, to, pattern); + } + + private int shouldMatchByLine(String buffer, String from, String to, String pattern) { + List<String> lines = asLines(buffer); int fromIndex = 0; if (from != null) { @@ -500,4 +530,5 @@ return matchedCount; } + }
--- a/jdk/test/sun/tools/jps/JpsHelper.java Fri Nov 28 16:56:45 2014 +0100 +++ b/jdk/test/sun/tools/jps/JpsHelper.java Mon Dec 01 09:49:44 2014 +0100 @@ -168,10 +168,8 @@ } /** - * Verify jps output 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. + * Verify jps stdout contains only pids and programs' name information. + * jps stderr may contain VM warning messages which will be ignored. * * The output can look like: * 35536 Jps @@ -180,8 +178,10 @@ */ public static void verifyJpsOutput(OutputAnalyzer output, String regex) throws Exception { output.shouldHaveExitValue(0); - int matchedCount = output.shouldMatchByLineFrom(regex, regex); + int matchedCount = output.stdoutShouldMatchByLine(regex); assertGreaterThan(matchedCount , 0, "Found no lines matching pattern: " + regex); + output.stderrShouldNotMatch("[E|e]xception"); + output.stderrShouldNotMatch("[E|e]rror"); } /**