8244993: Revert changes to OutputAnalyzer stderrShouldBeEmptyIgnoreVMWarnings() that allow version strings

Reviewed-by: dholmes, cjplummer
This commit is contained in:
Daniil Titov 2020-05-28 15:58:59 -07:00
parent 6df2a95d17
commit 7045a46250
8 changed files with 27 additions and 67 deletions

View File

@ -47,7 +47,7 @@ public class RemovingUnixDomainSocketTest {
private static void runJCmd(long pid) throws InterruptedException, IOException {
JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
jcmd.addVMArgs(Utils.getTestJavaOpts());
jcmd.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion"));
jcmd.addToolArg(Long.toString(pid));
jcmd.addToolArg("VM.version");
@ -65,8 +65,8 @@ public class RemovingUnixDomainSocketTest {
"jcmd stderr: [" + out.getStderr() + "]\n" +
"jcmd exitValue = " + out.getExitValue());
out.shouldHaveExitValue(0)
.stderrShouldBeEmptyIgnoreVMWarnings();
out.shouldHaveExitValue(0);
out.stderrShouldBeEmptyIgnoreVMWarnings();
}
public static void main(String... args) throws Exception {

View File

@ -58,7 +58,7 @@ public class ClhsdbJstackXcompStress {
for (int i = 0; i < MAX_ITERATIONS; i++) {
JDKToolLauncher launcher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion", "-Xcomp"));
launcher.addToolArg("jstack");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));

View File

@ -44,7 +44,7 @@ public class JhsdbThreadInfoTest {
System.out.println("Started LingeredApp with pid " + app.getPid());
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion"));
jhsdbLauncher.addToolArg("jstack");
jhsdbLauncher.addToolArg("--pid");

View File

@ -46,7 +46,7 @@ public class TestJhsdbJstackLock {
System.out.println ("Started LingeredApp with pid " + app.getPid());
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion"));
launcher.addToolArg("jstack");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));

View File

@ -46,7 +46,7 @@ public class DebugdConnectTest {
private static OutputAnalyzer runJHSDB(String command, String id) throws IOException, InterruptedException {
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion", "-Xcomp"));
jhsdbLauncher.addToolArg(command);
jhsdbLauncher.addToolArg("--connect");
if (id != null) {

View File

@ -90,7 +90,8 @@ public class TestJcmdDefaults {
* @param output The generated output from the jcmd.
*/
private static void matchListedProcesses(OutputAnalyzer output) {
output.shouldMatchByLineIgnoreVMWarnings(JCMD_LIST_REGEX);
output.stdoutShouldMatchByLine(JCMD_LIST_REGEX);
output.stderrShouldBeEmptyIgnoreVMWarnings();
}
private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {

View File

@ -152,8 +152,8 @@ public class TestJcmdSanity {
* @throws Exception
*/
private static void matchPerfCounters(OutputAnalyzer output) {
output.shouldMatchByLineIgnoreVMWarnings(PERF_COUNTER_REGEX, null,
PERF_COUNTER_REGEX);
output.stdoutShouldMatchByLine(PERF_COUNTER_REGEX, null, PERF_COUNTER_REGEX);
output.stderrShouldBeEmptyIgnoreVMWarnings();
}
private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {

View File

@ -38,14 +38,7 @@ import java.util.regex.Pattern;
public final class OutputAnalyzer {
private static final String JVM_WARNING_MSG = ".* VM warning:.*";
private static final String JAVA_VERSION_MSG = "^java version .*|^Java\\(TM\\).*|^Java HotSpot\\(TM\\).*|" +
"^openjdk version .*|^OpenJDK .*";
private static final String JAVA_WARNINGS_AND_VERSION = JVM_WARNING_MSG + "|" + JAVA_VERSION_MSG;
private static final Pattern JAVA_WARNINGS_AND_VERSION_PATTERN =
Pattern.compile(JAVA_WARNINGS_AND_VERSION.replaceAll("\\|", "\\\\R|") + "\\R",
Pattern.MULTILINE);
private static final String jvmwarningmsg = ".* VM warning:.*";
private final OutputBuffer buffer;
/**
@ -141,13 +134,13 @@ public final class OutputAnalyzer {
/**
* Verify that the stderr contents of output buffer is empty,
* after filtering out the HotSpot warning and Java version messages.
* after filtering out the Hotspot warning messages
*
* @throws RuntimeException
* If stderr was not empty
*/
public OutputAnalyzer stderrShouldBeEmptyIgnoreVMWarnings() {
if (!JAVA_WARNINGS_AND_VERSION_PATTERN.matcher(getStderr()).replaceAll("").isEmpty()) {
if (!getStderr().replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
@ -570,15 +563,9 @@ public final class OutputAnalyzer {
return Arrays.asList(buffer.split("\\R"));
}
private List<String> asLinesWithoutVMWarnings(String buffer) {
return Arrays.stream(buffer.split("\\R"))
.filter(Pattern.compile(JAVA_WARNINGS_AND_VERSION).asPredicate().negate())
.collect(Collectors.toList());
}
/**
* Verifies that the stdout and stderr contents of output buffer are empty, after
* filtering out the HotSpot warning and Java version messages.
* filtering out the HotSpot warning messages.
*
* @throws RuntimeException If the stdout and stderr are not empty
*/
@ -589,19 +576,22 @@ public final class OutputAnalyzer {
reportDiagnosticSummary();
throw new RuntimeException("stdout was not empty");
}
stderrShouldBeEmptyIgnoreVMWarnings();
if (!stderr.replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer matches the pattern,
* after filtering out the HotSpot warning and Java version messages.
* after filtering out the Hotespot warning messages
*
* @param pattern
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer stderrShouldMatchIgnoreVMWarnings(String pattern) {
String stderr = JAVA_WARNINGS_AND_VERSION_PATTERN.matcher(getStderr()).replaceAll("");
String stderr = getStderr().replaceAll(jvmwarningmsg + "\\R", "");
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
if (!matcher.find()) {
reportDiagnosticSummary();
@ -613,28 +603,16 @@ public final class OutputAnalyzer {
/**
* Returns the contents of the output buffer (stdout and stderr), without those
* JVM warning and Java version messages, as list of strings. Output is split
* by newlines.
* JVM warning msgs, as list of strings. Output is split by newlines.
*
* @return Contents of the output buffer as list of strings
*/
public List<String> asLinesWithoutVMWarnings() {
return Arrays.stream(getOutput().split("\\R"))
.filter(Pattern.compile(JAVA_WARNINGS_AND_VERSION).asPredicate().negate())
.filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
.collect(Collectors.toList());
}
/**
* Verify that the stdout and stderr contents of output buffer match the
* {@code pattern} line by line ignoring HotSpot warning and version messages.
*
* @param pattern
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLineIgnoreVMWarnings(String pattern) {
return shouldMatchByLine(getOutput(), null, null, pattern, true);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
@ -678,25 +656,7 @@ public final class OutputAnalyzer {
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern, false);
}
/**
* Verify that the stdout and stderr contents of output buffer match the
* {@code pattern} line by line ignoring HotSpot warnings and version messages.
* The whole output could be matched or just a subset of it.
*
* @param from
* The line (excluded) from where output will be matched.
* Set {@code from} to null for matching from the first line.
* @param to
* The line (excluded) until where output will be matched.
* Set {@code to} to null for matching until the last line.
* @param pattern
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLineIgnoreVMWarnings(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern, true);
return shouldMatchByLine(getOutput(), from, to, pattern);
}
/**
@ -714,12 +674,11 @@ public final class OutputAnalyzer {
* Matching pattern
*/
public OutputAnalyzer stdoutShouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getStdout(), from, to, pattern, false);
return shouldMatchByLine(getStdout(), from, to, pattern);
}
private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern,
boolean ignoreVMWarnings) {
List<String> lines = ignoreVMWarnings ? asLinesWithoutVMWarnings() : asLines(buffer);
private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern) {
List<String> lines = asLines(buffer);
int fromIndex = 0;
if (from != null) {