You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by pr...@apache.org on 2018/12/06 01:09:51 UTC
[geode] branch develop updated: GEODE-6100: Cleanup suspect string
logic for better readability (#2920)
This is an automated email from the ASF dual-hosted git repository.
prhomberg pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 8ba2b34 GEODE-6100: Cleanup suspect string logic for better readability (#2920)
8ba2b34 is described below
commit 8ba2b3442cc5c187bbd43df14c754e6d686eb2f1
Author: Patrick Rhomberg <pr...@pivotal.io>
AuthorDate: Wed Dec 5 17:09:42 2018 -0800
GEODE-6100: Cleanup suspect string logic for better readability (#2920)
---
.../geode/test/dunit/internal/DUnitLauncher.java | 41 +--
.../geode/test/greplogs/ExpectedStrings.java | 211 +++++++------
.../apache/geode/test/greplogs/LogConsumer.java | 349 ++++++++++++---------
3 files changed, 308 insertions(+), 293 deletions(-)
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/DUnitLauncher.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/DUnitLauncher.java
index 0303bc4..4ed724b 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/DUnitLauncher.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/DUnitLauncher.java
@@ -32,7 +32,6 @@ import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.InetAddress;
-import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.rmi.AlreadyBoundException;
@@ -41,6 +40,7 @@ import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.List;
import java.util.Properties;
+import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
@@ -127,7 +127,7 @@ public class DUnitLauncher {
// TODO - this is hacky way to test for a hydra environment - see
// if there is registered test configuration object.
Class<?> clazz = Class.forName("hydra.TestConfig");
- Method getInstance = clazz.getMethod("getInstance", new Class[0]);
+ Method getInstance = clazz.getMethod("getInstance");
getInstance.invoke(null);
return true;
} catch (Exception e) {
@@ -174,7 +174,7 @@ public class DUnitLauncher {
return "localhost[" + locatorPort + "]";
}
- private static void launch() throws URISyntaxException, AlreadyBoundException, IOException,
+ private static void launch() throws AlreadyBoundException, IOException,
InterruptedException, NotBoundException {
DUNIT_SUSPECT_FILE = new File(SUSPECT_FILENAME);
DUNIT_SUSPECT_FILE.delete();
@@ -197,35 +197,7 @@ public class DUnitLauncher {
// restrict membership ports to be outside of AvailablePort's range
System.setProperty(DistributionConfig.RESTRICT_MEMBERSHIP_PORT_RANGE, "true");
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- // System.out.println("shutting down DUnit JVMs");
- // for (int i=0; i<NUM_VMS; i++) {
- // try {
- // processManager.getStub(i).shutDownVM();
- // } catch (Exception e) {
- // System.out.println("exception shutting down vm_"+i+": " + e);
- // }
- // }
- // // TODO - hasLiveVMs always returns true
- // System.out.print("waiting for JVMs to exit");
- // long giveUp = System.currentTimeMillis() + 5000;
- // while (giveUp > System.currentTimeMillis()) {
- // if (!processManager.hasLiveVMs()) {
- // return;
- // }
- // System.out.print(".");
- // System.out.flush();
- // try {
- // Thread.sleep(1000);
- // } catch (InterruptedException e) {
- // break;
- // }
- // }
- // System.out.println("\nkilling any remaining JVMs");
- processManager.killVMs();
- }
- });
+ Runtime.getRuntime().addShutdownHook(new Thread(processManager::killVMs));
// Create a VM for the locator
processManager.launchVM(LOCATOR_VM_NUM);
@@ -350,9 +322,8 @@ public class DUnitLauncher {
public static void closeAndCheckForSuspects() {
if (isLaunched()) {
- final boolean skipLogMsgs = ExpectedStrings.skipLogMsgs("dunit");
- final List<?> expectedStrings = ExpectedStrings.create("dunit");
- final LogConsumer logConsumer = new LogConsumer(skipLogMsgs, expectedStrings, "log4j", 5);
+ final List<Pattern> expectedStrings = ExpectedStrings.create("dunit");
+ final LogConsumer logConsumer = new LogConsumer(true, expectedStrings, "log4j", 5);
final StringBuilder suspectStringBuilder = new StringBuilder();
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/greplogs/ExpectedStrings.java b/geode-dunit/src/main/java/org/apache/geode/test/greplogs/ExpectedStrings.java
index 325a1ea..68501d7 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/greplogs/ExpectedStrings.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/greplogs/ExpectedStrings.java
@@ -23,16 +23,12 @@ public class ExpectedStrings {
private ExpectedStrings() {}
public static boolean skipLogMsgs(String type) {
- if (type.equals("junit") || type.equals("java") || type.equals("query")
- || type.equals("dunit")) {
- return true;
- } else {
- return false;
- }
+ return type.equals("junit") || type.equals("java") || type.equals("query")
+ || type.equals("dunit");
}
- public static List create(String type) {
- List expected = new ArrayList();
+ public static List<Pattern> create(String type) {
+ List<Pattern> expected = new ArrayList<>();
expected.add(Pattern.compile("@todo"));
expected.add(Pattern.compile("Random seed"));
@@ -65,7 +61,7 @@ public class ExpectedStrings {
expected.add(Pattern.compile("Invoked MembershipNotifierHook"));
expected.add(Pattern.compile("java.io.IOException: Connection reset by peer"));
expected.add(Pattern.compile("client connections exceeds the licensed limit"));
- // Exclude this since the only tests with securty enabled, expect to see
+ // Exclude this since the only tests with security enabled, expect to see
// these and if they don't then the test fails
expected.add(Pattern.compile("NotAuthorizedException"));
expected.add(Pattern.compile("above critical heap threshold"));
@@ -88,99 +84,110 @@ public class ExpectedStrings {
// expected.add(Pattern.compile("Minimum system requirements not met. Unexpected behavior may
// result in additional errors."));
- if (type.equals("junit") || type.equals("java") || type.equals("query")) {
- expected.add(Pattern.compile("TEST EXCEPTION"));
- expected.add(Pattern.compile("testLogLevels"));
- expected.add(Pattern.compile("On iteration"));
- expected.add(Pattern.compile("signal count"));
- // Remove when davidw fixes
- expected.add(Pattern.compile("Expected"));
- // below here for gfx unit tests
- expected.add(Pattern.compile("Valid documents must have a"));
- expected.add(Pattern.compile("Loaded java.lang.ClassCastException"));
- expected.add(Pattern.compile("Loaded java.io.InvalidClassException"));
- expected.add(Pattern.compile("Loaded java.lang.NullPointerException"));
- expected.add(Pattern.compile("Loaded java.lang.ArrayIndexOutOfBoundsException"));
- expected.add(Pattern.compile("Loaded java.lang.IndexOutOfBoundsException"));
- expected.add(Pattern.compile("SucessfulTest:"));
- expected.add(Pattern.compile("SQLException: Database 'newDB' not found"));
- expected.add(Pattern.compile("SQLException: Database 'newDB1' not found"));
- expected.add(Pattern.compile("IGNORE_EXCEPTION_test"));
- expected.add(Pattern.compile("Unsupported at this time"));
- expected.add(Pattern.compile("DiskAccessException occurred as expected"));
- expected.add(Pattern.compile("Oplog::createOplog:Exception in preblowing the file"));
- } else if (type.equals("dunit")) {
- expected.add(Pattern.compile("INCOMPATIBLE_ROOT"));
- expected.add(Pattern.compile("connecting to locator"));
- expected.add(Pattern.compile("ItsOkayForMyClassNotToBeFound"));
- expected.add(Pattern.compile("Test Exception"));
- expected.add(Pattern.compile("make sure exceptions from close callbacks"));
- expected.add(Pattern.compile("Please ignore"));
- expected.add(Pattern.compile("I have been thrown from TestFunction"));
- expected.add(Pattern.compile("No admin on"));
- expected.add(Pattern.compile("nonExistentMethod"));
- expected.add(Pattern.compile("Expected exception"));
- expected.add(Pattern.compile("ConnectionPoolTestNonSerializable"));
- expected.add(Pattern.compile("One or more DUnit tests failed"));
- expected.add(Pattern.compile("ReplyException"));
- expected.add(Pattern.compile("fine 2"));
- expected.add(Pattern.compile("TESTING A VERY UNIQUE"));
- expected.add(Pattern.compile("-01-01"));
- expected.add(Pattern.compile("testNBRegionDestructionDuringGetInitialImage"));
- expected.add(Pattern.compile("SQLException: Database 'newDB' not found"));
- expected.add(Pattern.compile("SQLException: Failed to start database 'newDB'"));
- expected.add(Pattern.compile("SQLException: Database 'newDB1' not found"));
- expected.add(Pattern.compile("INCORRECT_localhost"));
- expected.add(Pattern.compile(
- "WARNING: Failed to check connection: java.net.ConnectException: Connection refused"));
- expected.add(
- Pattern.compile("WARNING: Failed to call the method close..:java.rmi.ConnectException:"));
- expected.add(Pattern.compile(
- "WARNING: Failed to restart: java.rmi.NoSuchObjectException: no such object in table"));
- expected.add(Pattern.compile(
- "WARNING: Failed to restart: java.rmi.ConnectException: Connection refused to host: .* nested exception is:"));
- expected.add(Pattern
- .compile("UnitTests terminating abnormally after a client had a fatal task error"));
- expected.add(Pattern.compile("Doing stack dump on all"));
- expected.add(Pattern.compile("Unit test result: FAILED ==> Unsuccessfully ran JUnit tests"));
- expected.add(Pattern.compile("IGNORE_EXCEPTION_test"));
- expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
- expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
- expected.add(Pattern.compile("Redundancy has dropped below"));
- expected.add(Pattern.compile("Could not find any server to host redundant client"));
- expected.add(Pattern.compile("Could not find any server to host primary client"));
- expected.add(Pattern.compile("Could not find any server to create redundant client"));
- expected.add(Pattern.compile("Could not find any server to create primary client"));
- expected.add(Pattern.compile("Pool unexpected closed socket on server"));
- expected.add(Pattern.compile("SocketTimeoutException"));
- expected.add(Pattern.compile("Could not initialize a primary queue on startup"));
- expected.add(Pattern.compile(
- "java.lang.IllegalArgumentException: Sample timestamp must be greater than previous timestamp"));
- // The following 2 strings are ignored due to bug 52042
- expected.add(Pattern.compile("failed accepting client connection"));
- expected.add(Pattern.compile("Acceptor received unknown communication"));
- } else if (type.equals("smoke")) {
- expected.add(Pattern.compile("Doing stack dump on all"));
- expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
- expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
- expected.add(Pattern.compile("Could not find Spring Shell library"));
- } else if (type.equals("perf")) {
- expected.add(Pattern.compile("Doing stack dump on all"));
- expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
- expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
- } else if (type.equals("moresmoke")) {
- expected.add(Pattern.compile(" expected error"));
- expected.add(Pattern.compile("Doing stack dump on all"));
- expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
- expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
- } else {
- expected.add(Pattern.compile("runbattery\\(\\) returned false"));
- expected.add(Pattern.compile(" expected error"));
- expected.add(Pattern.compile("Doing stack dump on all"));
- expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
- expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
- expected.add(Pattern.compile("HydraTask_initializeExpectException"));
- expected.add(Pattern.compile("java.net.ConnectException: Connection refused"));
+ switch (type) {
+ case "junit":
+ case "java":
+ case "query":
+ expected.add(Pattern.compile("TEST EXCEPTION"));
+ expected.add(Pattern.compile("testLogLevels"));
+ expected.add(Pattern.compile("On iteration"));
+ expected.add(Pattern.compile("signal count"));
+ // Remove when davidw fixes
+ expected.add(Pattern.compile("Expected"));
+ // below here for gfx unit tests
+ expected.add(Pattern.compile("Valid documents must have a"));
+ expected.add(Pattern.compile("Loaded java.lang.ClassCastException"));
+ expected.add(Pattern.compile("Loaded java.io.InvalidClassException"));
+ expected.add(Pattern.compile("Loaded java.lang.NullPointerException"));
+ expected.add(Pattern.compile("Loaded java.lang.ArrayIndexOutOfBoundsException"));
+ expected.add(Pattern.compile("Loaded java.lang.IndexOutOfBoundsException"));
+ expected.add(Pattern.compile("SucessfulTest:"));
+ expected.add(Pattern.compile("SQLException: Database 'newDB' not found"));
+ expected.add(Pattern.compile("SQLException: Database 'newDB1' not found"));
+ expected.add(Pattern.compile("IGNORE_EXCEPTION_test"));
+ expected.add(Pattern.compile("Unsupported at this time"));
+ expected.add(Pattern.compile("DiskAccessException occurred as expected"));
+ expected.add(Pattern.compile("Oplog::createOplog:Exception in preblowing the file"));
+ break;
+ case "dunit":
+ expected.add(Pattern.compile("INCOMPATIBLE_ROOT"));
+ expected.add(Pattern.compile("connecting to locator"));
+ expected.add(Pattern.compile("ItsOkayForMyClassNotToBeFound"));
+ expected.add(Pattern.compile("Test Exception"));
+ expected.add(Pattern.compile("make sure exceptions from close callbacks"));
+ expected.add(Pattern.compile("Please ignore"));
+ expected.add(Pattern.compile("I have been thrown from TestFunction"));
+ expected.add(Pattern.compile("No admin on"));
+ expected.add(Pattern.compile("nonExistentMethod"));
+ expected.add(Pattern.compile("Expected exception"));
+ expected.add(Pattern.compile("ConnectionPoolTestNonSerializable"));
+ expected.add(Pattern.compile("One or more DUnit tests failed"));
+ expected.add(Pattern.compile("ReplyException"));
+ expected.add(Pattern.compile("fine 2"));
+ expected.add(Pattern.compile("TESTING A VERY UNIQUE"));
+ expected.add(Pattern.compile("-01-01"));
+ expected.add(Pattern.compile("testNBRegionDestructionDuringGetInitialImage"));
+ expected.add(Pattern.compile("SQLException: Database 'newDB' not found"));
+ expected.add(Pattern.compile("SQLException: Failed to start database 'newDB'"));
+ expected.add(Pattern.compile("SQLException: Database 'newDB1' not found"));
+ expected.add(Pattern.compile("INCORRECT_localhost"));
+ expected.add(Pattern.compile(
+ "WARNING: Failed to check connection: java.net.ConnectException: Connection refused"));
+ expected.add(
+ Pattern
+ .compile("WARNING: Failed to call the method close..:java.rmi.ConnectException:"));
+ expected.add(Pattern.compile(
+ "WARNING: Failed to restart: java.rmi.NoSuchObjectException: no such object in table"));
+ expected.add(Pattern.compile(
+ "WARNING: Failed to restart: java.rmi.ConnectException: Connection refused to host: .* nested exception is:"));
+ expected.add(Pattern
+ .compile("UnitTests terminating abnormally after a client had a fatal task error"));
+ expected.add(Pattern.compile("Doing stack dump on all"));
+ expected
+ .add(Pattern.compile("Unit test result: FAILED ==> Unsuccessfully ran JUnit tests"));
+ expected.add(Pattern.compile("IGNORE_EXCEPTION_test"));
+ expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
+ expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
+ expected.add(Pattern.compile("Redundancy has dropped below"));
+ expected.add(Pattern.compile("Could not find any server to host redundant client"));
+ expected.add(Pattern.compile("Could not find any server to host primary client"));
+ expected.add(Pattern.compile("Could not find any server to create redundant client"));
+ expected.add(Pattern.compile("Could not find any server to create primary client"));
+ expected.add(Pattern.compile("Pool unexpected closed socket on server"));
+ expected.add(Pattern.compile("SocketTimeoutException"));
+ expected.add(Pattern.compile("Could not initialize a primary queue on startup"));
+ expected.add(Pattern.compile(
+ "java.lang.IllegalArgumentException: Sample timestamp must be greater than previous timestamp"));
+ // The following 2 strings are ignored due to bug 52042
+ expected.add(Pattern.compile("failed accepting client connection"));
+ expected.add(Pattern.compile("Acceptor received unknown communication"));
+ break;
+ case "smoke":
+ expected.add(Pattern.compile("Doing stack dump on all"));
+ expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
+ expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
+ expected.add(Pattern.compile("Could not find Spring Shell library"));
+ break;
+ case "perf":
+ expected.add(Pattern.compile("Doing stack dump on all"));
+ expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
+ expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
+ break;
+ case "moresmoke":
+ expected.add(Pattern.compile(" expected error"));
+ expected.add(Pattern.compile("Doing stack dump on all"));
+ expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
+ expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
+ break;
+ default:
+ expected.add(Pattern.compile("runbattery\\(\\) returned false"));
+ expected.add(Pattern.compile(" expected error"));
+ expected.add(Pattern.compile("Doing stack dump on all"));
+ expected.add(Pattern.compile("SIGQUIT received, dumping threads"));
+ expected.add(Pattern.compile("Sleeping \\d+ seconds between stack dumps"));
+ expected.add(Pattern.compile("HydraTask_initializeExpectException"));
+ expected.add(Pattern.compile("java.net.ConnectException: Connection refused"));
+ break;
}
return expected;
}
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/greplogs/LogConsumer.java b/geode-dunit/src/main/java/org/apache/geode/test/greplogs/LogConsumer.java
index c3e32e3..dd1ac42 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/greplogs/LogConsumer.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/greplogs/LogConsumer.java
@@ -21,7 +21,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LogConsumer {
- private final List expectedExceptions = new ArrayList();
+ private final List<Pattern> expectedExceptions = new ArrayList<>();
private boolean skipLogMsgs = false;
private boolean infoMsgFlag = false;
private int eatLines = 0;
@@ -29,11 +29,11 @@ public class LogConsumer {
private int tmpErrLines = 0;
private boolean saveFlag = false;
private int savelinenum = 0;
- private final List testExpectStrs;
- StringBuilder all = null;
+ private final List<Pattern> testExpectStrs;
+ private StringBuilder all = null;
private int lineNumber;
private String fileName;
- HashMap individalErrorCount = new HashMap();
+ private HashMap<String, Integer> individualErrorCount = new HashMap<>();
private final int repeatLimit;
private static final Pattern ExpectedExceptionPattern =
@@ -68,7 +68,8 @@ public class LogConsumer {
- public LogConsumer(boolean skipLogMsgs, List testExpectStrs, String fileName, int repeatLimit) {
+ public LogConsumer(boolean skipLogMsgs, List<Pattern> testExpectStrs, String fileName,
+ int repeatLimit) {
super();
this.skipLogMsgs = skipLogMsgs;
this.testExpectStrs = testExpectStrs;
@@ -77,159 +78,204 @@ public class LogConsumer {
}
public StringBuilder consume(CharSequence line) {
- {
- lineNumber++;
- Matcher m = ExpectedExceptionPattern.matcher(line);
- if (m.find()) {
- if (m.group(1).equals("add")) {
- expectedExceptions.add(Pattern.compile(m.group(2)));
- } else {
- // assume add and remove are the only choices
- expectedExceptions.remove(Pattern.compile(m.group(2)));
- }
- return null;
- }
+ lineNumber++;
+
+ // IgnoredException injects lines into the log to start or end ignore periods.
+ // Process those lines, then exit.
+ Matcher expectedExceptionMatcher = ExpectedExceptionPattern.matcher(line);
+ if (expectedExceptionMatcher.find()) {
+ expectedExceptionMatcherHandler(expectedExceptionMatcher);
+ return null;
}
- if (skipLogMsgs) {
- if (infoMsgFlag) {
- if (logPattern.matcher(line).find()) {
- infoMsgFlag = false;
- } else if (blankPattern.matcher(line).matches()) {
- infoMsgFlag = false;
- return null;
- } else {
- return null;
- }
- }
- if (skipLevelPattern.matcher(line).find()) {
- infoMsgFlag = true;
- return null;
- }
+
+ // We may optionally skip info-level logs
+ if (skipLogMsgs && skipThisLogMsg(line)) {
+ return null;
}
+ // In some case, we want to skip an extra line.
if (eatLines != 0) {
eatLines--;
return null;
- } else {
- if (saveFlag || fatalOrErrorPattern.matcher(line).find()) {
- if (!saveFlag) {
- saveFlag = true;
- tmpErrFlag = true;
- if (checkExpectedStrs(line, expectedExceptions)) {
- saveFlag = false;
- tmpErrFlag = false;
- tmpErrLines = 0;
- }
- if (tmpErrFlag) {
- tmpErrLines = 1;
- all = new StringBuilder(line);
- all.append("\n");
- savelinenum = lineNumber;
- }
- } else {
- if (causedByPattern.matcher(line).find()) {
- // This code used to stop appending if a causedBy was seen.
- // But we want the causedBy stack trace to also be included
- // in the suspect StringBuilder.
- // The main thing is we do not want to call checkExpectedStrs
- // with this "caused by" line.
- } else if (checkExpectedStrs(line, expectedExceptions)) {
- // reset the counters and throw it all away if it matches
- // one of the registered expected strings
- tmpErrFlag = false;
- tmpErrLines = 0;
- saveFlag = false;
- }
-
- // We save all the lines up to the next blank line so we're
- // looking for a blank line here
- if (blankPattern.matcher(line).matches()) {
- // we found a blank line so print the suspect string
- // and reset the savetag flag
- saveFlag = false;
- Matcher m = shortErrPattern.matcher(all.toString());
- if (m.matches()) {
- String shortName = m.group(1);
- Integer i = (Integer) individalErrorCount.get(shortName);
- Integer occurances = new Integer((i == null) ? 1 : i.intValue() + 1);
- individalErrorCount.put(shortName, occurances);
- return enforceErrorLimit(occurances.intValue(), all.toString(),
- // reader.getLineNumber(),
- savelinenum, fileName);
-
- } else {
- // error in determining shortName, wing it
- return enforceErrorLimit(1, all.toString(), lineNumber, fileName);
- }
- }
-
- // we're still saving lines to append them on to all which contains
- // all the lines we're trying to save
- if (tmpErrFlag) {
- if (tmpErrLines < ERROR_BUFFER_LIMIT) {
- tmpErrLines++;
- all.append(line).append("\n");
- }
- if (tmpErrLines == ERROR_BUFFER_LIMIT) {
- tmpErrLines++; // increment to prevent this line from repeating
- all.append("GrepLogs: ERROR_BUFFER_LIMIT limit reached,")
- .append(" the error was too long to display completely.\n");
- }
-
- }
+ }
+
+ if (saveFlag || fatalOrErrorPattern.matcher(line).find()) {
+ if (!saveFlag) {
+ setInstanceVariablesForSomeReason(line);
+ } else {
+ if (!causedByPattern.matcher(line).find() && checkExpectedStrs(line, expectedExceptions)) {
+ // reset the counters and throw it all away if it matches
+ // one of the registered expected strings
+ tmpErrFlag = false;
+ tmpErrLines = 0;
+ saveFlag = false;
}
- // unique condition for when cache server see log exception and
- // logging level is set to fine. Message looks like this:
- // [fine 2005/10/25 17:53:13.586 PDT gemfire2 Server connection from
- // hobbes.gemstone.com:34466-0xf4 nid=0x23e40f1] Server connection from
- // hobbes.gemstone.com:34466: Wrote exception:
- // org.apache.geode.cache.EntryNotFoundException: remote-destroy-key
- // also now handles a JMX WARNING
- } else if (wroteExceptionPattern.matcher(line).find()
- || rmiWarnPattern.matcher(line).find()) {
- // Eat only the single EntryNotFound Exception
- eatLines = 1;
- // if we are here then the line didn't have severe or error in it and
- // didn't meet any special cases that require eating lines
- // Check for other kinds of exceptions. This is by no means inclusive
- // of all types of exceptions that could occur and some ARE missed.
- } else if (exceptionPattern.matcher(line).find() || javaLangErrorPattern.matcher(line).find()
- || (misformatedI18nMessagePattern.matcher(line).find()
- && !(skipLevelPattern.matcher(line).find()
- && rvvBitSetMessagePattern.matcher(line).find()))) {
- if (!checkExpectedStrs(line, expectedExceptions)) {
- // it's the Exception colon that we want to find
- // along with the next six words and define to shortline
- // shortline is only used for the unique sting to count the
- // number of times an exception match occurs. This is so
- // we can suppress further printing if we hit the limit
- Matcher m2 = exceptionPattern2.matcher(line);
- Matcher m3 = exceptionPattern3.matcher(line);
- Matcher m4 = exceptionPattern4.matcher(line);
- String shortName = null;
-
- if (m2.find()) {
- shortName = m2.group(1);
- } else if (m3.find()) {
- shortName = m3.group(1);
- } else if (m4.find()) {
- shortName = m4.group(1);
- }
- if (shortName != null) {
- Integer i = (Integer) individalErrorCount.get(shortName);
- Integer occurances = new Integer((i == null) ? 1 : i.intValue() + 1);
- individalErrorCount.put(shortName, occurances);
- return enforceErrorLimit(occurances.intValue(), line + "\n", lineNumber, fileName);
- } else {
- return enforceErrorLimit(1, line + "\n", lineNumber, fileName);
- }
+
+ // We save all the lines up to the next blank line so we're
+ // looking for a blank line here
+ if (blankPattern.matcher(line).matches()) {
+ return enforceErrorLimitsAtShortErrMatcher();
}
+
+ // we're still saving lines to append them on to all which contains
+ // all the lines we're trying to save
+ if (tmpErrFlag) {
+ addErrLinesToAll(line);
+ }
+ }
+ } else if (isWroteOrRMIWarn(line)) {
+ handleWroteOrRMIWarn();
+ return null;
+ } else if (isExceptionErrorOrSomeSpecialCase(line)) {
+ if (!checkExpectedStrs(line, expectedExceptions)) {
+ return enforceErrorLimitOnShortName(line);
}
}
return null;
}
+ private void handleWroteOrRMIWarn() {
+ // unique condition for when cache server see log exception and
+ // logging level is set to fine. Message looks like this:
+ // [fine 2005/10/25 17:53:13.586 PDT gemfire2 Server connection from
+ // hobbes.gemstone.com:34466-0xf4 nid=0x23e40f1] Server connection from
+ // hobbes.gemstone.com:34466: Wrote exception:
+ // org.apache.geode.cache.EntryNotFoundException: remote-destroy-key
+ // also now handles a JMX WARNING
+
+ // if we are here then the line didn't have severe or error in it and
+ // didn't meet any special cases that require eating lines
+ // Check for other kinds of exceptions. This is by no means inclusive
+ // of all types of exceptions that could occur and some ARE missed.
+
+ // Eat only the single EntryNotFound Exception
+ eatLines = 1;
+ }
+
+ private boolean isWroteOrRMIWarn(CharSequence line) {
+ return wroteExceptionPattern.matcher(line).find() || rmiWarnPattern.matcher(line).find();
+ }
+
+ private StringBuilder enforceErrorLimitOnShortName(CharSequence line) {
+ // it's the Exception colon that we want to find
+ // along with the next six words and define to shortline
+ // shortline is only used for the unique sting to count the
+ // number of times an exception match occurs. This is so
+ // we can suppress further printing if we hit the limit
+ String shortName = getShortName(line);
+ if (shortName != null) {
+ Integer i = individualErrorCount.get(shortName);
+ int occurrences = (i == null) ? 1 : i + 1;
+ individualErrorCount.put(shortName, occurrences);
+ return enforceErrorLimit(occurrences, line + "\n", lineNumber, fileName);
+ } else {
+ return enforceErrorLimit(1, line + "\n", lineNumber, fileName);
+ }
+ }
+
+ private boolean isExceptionErrorOrSomeSpecialCase(CharSequence line) {
+ return exceptionPattern.matcher(line).find()
+ || javaLangErrorPattern.matcher(line).find()
+ || (misformatedI18nMessagePattern.matcher(line).find()
+ && !(skipLevelPattern.matcher(line).find()
+ && rvvBitSetMessagePattern.matcher(line).find()));
+ }
+
+ private void addErrLinesToAll(CharSequence line) {
+ if (tmpErrLines < ERROR_BUFFER_LIMIT) {
+ tmpErrLines++;
+ all.append(line).append("\n");
+ }
+ if (tmpErrLines == ERROR_BUFFER_LIMIT) {
+ tmpErrLines++; // increment to prevent this line from repeating
+ all.append("GrepLogs: ERROR_BUFFER_LIMIT limit reached,")
+ .append(" the error was too long to display completely.\n");
+ }
+ }
+
+ private StringBuilder enforceErrorLimitsAtShortErrMatcher() {
+ // we found a blank line so print the suspect string and reset the savetag flag
+ saveFlag = false;
+ Matcher shortErrMatcher = shortErrPattern.matcher(all.toString());
+ if (shortErrMatcher.matches()) {
+ String shortName = shortErrMatcher.group(1);
+ Integer i = individualErrorCount.get(shortName);
+ int occurrences = (i == null) ? 1 : i + 1;
+ individualErrorCount.put(shortName, occurrences);
+ return enforceErrorLimit(occurrences, all.toString(), savelinenum, fileName);
+
+ } else {
+ // error in determining shortName, wing it
+ return enforceErrorLimit(1, all.toString(), lineNumber, fileName);
+ }
+ }
+
+ private void setInstanceVariablesForSomeReason(CharSequence line) {
+ saveFlag = true;
+ tmpErrFlag = true;
+ if (checkExpectedStrs(line, expectedExceptions)) {
+ saveFlag = false;
+ tmpErrFlag = false;
+ tmpErrLines = 0;
+ }
+ if (tmpErrFlag) {
+ tmpErrLines = 1;
+ all = new StringBuilder(line);
+ all.append("\n");
+ savelinenum = lineNumber;
+ }
+ }
+
+ private String getShortName(CharSequence line) {
+ Matcher m2 = exceptionPattern2.matcher(line);
+ if (m2.find()) {
+ return m2.group(1);
+ }
+
+ Matcher m3 = exceptionPattern3.matcher(line);
+ if (m3.find()) {
+ return m3.group(1);
+ }
+
+ Matcher m4 = exceptionPattern4.matcher(line);
+ if (m4.find()) {
+ return m4.group(1);
+ }
+
+ return null;
+ }
+
+ /** This method returns true if this line should be skipped. */
+ private boolean skipThisLogMsg(CharSequence line) {
+ if (infoMsgFlag) {
+ if (logPattern.matcher(line).find()) {
+ infoMsgFlag = false;
+ } else if (blankPattern.matcher(line).matches()) {
+ infoMsgFlag = false;
+ return true;
+ } else {
+ return true;
+ }
+ }
+
+ if (skipLevelPattern.matcher(line).find()) {
+ infoMsgFlag = true;
+ return true;
+ }
+
+ return false;
+ }
+
+ private void expectedExceptionMatcherHandler(Matcher expectedExceptionMatcher) {
+ if (expectedExceptionMatcher.group(1).equals("add")) {
+ expectedExceptions.add(Pattern.compile(expectedExceptionMatcher.group(2)));
+ } else {
+ // assume add and remove are the only choices
+ expectedExceptions.remove(Pattern.compile(expectedExceptionMatcher.group(2)));
+ }
+ }
+
public StringBuilder close() {
if (saveFlag) {
// Bug fix for severe that occurs at the end of a log file. Since we
@@ -243,18 +289,9 @@ public class LogConsumer {
return null;
}
- private boolean checkExpectedStrs(CharSequence line, List expectedExceptions) {
- for (int i = 0; i < expectedExceptions.size(); i++) {
- Pattern p = (Pattern) expectedExceptions.get(i);
- if (p.matcher(line).find())
- return true;
- }
- for (int i = 0; i < testExpectStrs.size(); i++) {
- Pattern p = (Pattern) testExpectStrs.get(i);
- if (p.matcher(line).find())
- return true;
- }
- return false;
+ private boolean checkExpectedStrs(CharSequence line, List<Pattern> expectedExceptions) {
+ return expectedExceptions.stream().anyMatch(expected -> expected.matcher(line).find())
+ || testExpectStrs.stream().anyMatch(testExpected -> testExpected.matcher(line).find());
}
private StringBuilder enforceErrorLimit(int hits, String line, int linenum, String filename) {