This is an automated email from the ASF dual-hosted git repository. klund pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
commit 145276390ed69cbee715f12c069116e6f2720b5d Author: Kirk Lund <kl...@apache.org> AuthorDate: Fri Nov 2 15:31:42 2018 -0700 GEODE-2644: Cleanup logging related files Cleanup files that helped fix logging related test failures or helped with reviewing and understanding code while working on GEODE-2644. * Remove warnings and improve code cleanliness * Improve testing and failure messages --- .../DeprecatedAgentLauncherIntegrationTest.java | 11 +- ...llingWithDistributedSystemIntegrationTest.java} | 33 +-- .../logging/MergeLogFilesIntegrationTest.java | 2 +- .../apache/geode/internal/DistributionLocator.java | 1 - .../geode/internal/logging/DateFormatter.java | 15 +- .../geode/internal/logging/GemFireFormatter.java | 37 +--- .../geode/internal/logging/GemFireHandler.java | 24 +-- .../geode/internal/logging/LocalLogWriter.java | 4 +- .../geode/internal/logging/LogFileParser.java | 164 ++++++--------- .../geode/internal/logging/LogWriterImpl.java | 16 +- .../geode/internal/logging/LoggingThread.java | 7 +- .../internal/logging/LoggingThreadFactory.java | 14 +- .../geode/internal/logging/LoggingThreadGroup.java | 83 +++----- .../logging/LoggingUncaughtExceptionHandler.java | 36 ++-- .../geode/internal/logging/MergeLogFiles.java | 222 +++++++++------------ .../apache/geode/internal/logging/SortLogFile.java | 59 +++--- .../internal/logging/StandardErrorPrinter.java | 6 +- .../internal/logging/StandardOutputPrinter.java | 6 +- .../log4j/message/GemFireParameterizedMessage.java | 15 +- .../GemFireParameterizedMessageFactory.java | 4 +- .../geode/internal/logging/LogWriterImplTest.java | 3 + .../internal/logging/LoggingThreadFactoryTest.java | 6 + .../geode/internal/logging/LoggingThreadTest.java | 7 + .../LoggingUncaughtExceptionHandlerTest.java | 7 +- .../geode/internal/logging/SortLogFileTest.java | 2 +- .../internal/logging/log4j/FastLoggerTest.java | 2 +- .../log4j/HexThreadIdPatternConverterTest.java | 4 + .../apache/geode/test/process/ProcessWrapper.java | 2 +- .../security/LogNoPasswordDistributedTest.java} | 2 +- 29 files changed, 345 insertions(+), 449 deletions(-) diff --git a/geode-core/src/integrationTest/java/org/apache/geode/admin/jmx/internal/DeprecatedAgentLauncherIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/admin/jmx/internal/DeprecatedAgentLauncherIntegrationTest.java index 3d144a7..b7c80dc 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/admin/jmx/internal/DeprecatedAgentLauncherIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/admin/jmx/internal/DeprecatedAgentLauncherIntegrationTest.java @@ -14,6 +14,7 @@ */ package org.apache.geode.admin.jmx.internal; +import static java.lang.System.lineSeparator; import static org.apache.geode.admin.jmx.AgentConfig.DEFAULT_PROPERTY_FILE; import static org.apache.geode.admin.jmx.internal.AgentConfigImpl.AGENT_PROPSFILE_PROPERTY_NAME; import static org.apache.geode.admin.jmx.internal.AgentLauncher.AGENT_PROPS; @@ -23,11 +24,13 @@ import static org.apache.geode.admin.jmx.internal.AgentLauncher.RUNNING; import static org.apache.geode.admin.jmx.internal.AgentLauncher.SHUTDOWN; import static org.apache.geode.admin.jmx.internal.AgentLauncher.STARTING; import static org.apache.geode.admin.jmx.internal.AgentLauncher.VMARGS; +import static org.apache.geode.test.awaitility.GeodeAwaitility.getTimeout; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeFalse; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Properties; @@ -45,6 +48,8 @@ import org.apache.geode.test.process.ProcessWrapper; public class DeprecatedAgentLauncherIntegrationTest { + private static final long TIMEOUT = getTimeout().getValueInMS(); + private String classpath; @Rule @@ -294,7 +299,11 @@ public class DeprecatedAgentLauncherIntegrationTest { if (processOutputPattern != null) { agentProcess.waitForOutputToMatch(processOutputPattern); } - agentProcess.waitFor(); + assertThat(agentProcess.waitFor(TIMEOUT)).as("Expecting process started with:" + lineSeparator() + + " " + Arrays.asList(args) + lineSeparator() + "with output:" + lineSeparator() + " " + + agentProcess.getOutput(true) + lineSeparator() + "to terminate with exit code: 0" + + lineSeparator() + "but waitFor is still waiting after timeout: " + TIMEOUT + " seconds.") + .isEqualTo(0); } } diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogRollingWithDistributedSystemIntegrationTest.java similarity index 91% rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogRollingWithDistributedSystemIntegrationTest.java index 5b2b77f..90c77e9 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogRollingWithDistributedSystemIntegrationTest.java @@ -42,12 +42,12 @@ import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.test.junit.categories.LoggingTest; /** - * Integration tests for log rolling with cache lifecycle. + * Integration tests for log rolling with {@link DistributedSystem} lifecycle. * * @since GemFire 6.5 */ @Category(LoggingTest.class) -public class CacheLogRollingIntegrationTest { +public class LogRollingWithDistributedSystemIntegrationTest { private static final int MAX_LOG_STATEMENTS = 100000; private static final String SECURITY_PREFIX = "security_"; @@ -84,9 +84,9 @@ public class CacheLogRollingIntegrationTest { @Test public void testSimpleStartRestartWithRolling() { Properties config = createConfig(); - config.put(LOG_FILE, logFile.getAbsolutePath()); - config.put(LOG_FILE_SIZE_LIMIT, "1"); - config.put(LOG_DISK_SPACE_LIMIT, "200"); + config.setProperty(LOG_FILE, logFile.getAbsolutePath()); + config.setProperty(LOG_FILE_SIZE_LIMIT, "1"); + config.setProperty(LOG_DISK_SPACE_LIMIT, "200"); system = DistributedSystem.connect(config); system.disconnect(); @@ -98,7 +98,8 @@ public class CacheLogRollingIntegrationTest { File newRolledLogFile = childFile(mainInt - 1, 1); assertThat(newMetaFile).doesNotExist(); - assertThat(newRolledLogFile).doesNotExist(); + assertThat(newRolledLogFile).as("mainInt=" + mainInt + ", newMetaFile=" + newMetaFile + + ", newRolledLogFile=" + newRolledLogFile).doesNotExist(); system = DistributedSystem.connect(config); @@ -112,8 +113,8 @@ public class CacheLogRollingIntegrationTest { @Test public void testStartWithRollingThenRestartWithRolling() throws Exception { Properties config = createConfig(); - config.put(LOG_FILE, logFile.getAbsolutePath()); - config.put(LOG_FILE_SIZE_LIMIT, "1"); + config.setProperty(LOG_FILE, logFile.getAbsolutePath()); + config.setProperty(LOG_FILE_SIZE_LIMIT, "1"); system = DistributedSystem.connect(config); @@ -139,8 +140,8 @@ public class CacheLogRollingIntegrationTest { @Test public void testLogFileLayoutAndRolling() throws Exception { Properties config = createConfig(); - config.put(LOG_FILE, logFile.getAbsolutePath()); - config.put(LOG_FILE_SIZE_LIMIT, "1"); + config.setProperty(LOG_FILE, logFile.getAbsolutePath()); + config.setProperty(LOG_FILE_SIZE_LIMIT, "1"); system = DistributedSystem.connect(config); @@ -150,9 +151,9 @@ public class CacheLogRollingIntegrationTest { @Test public void testSecurityLogFileLayoutAndRolling() throws Exception { Properties config = createConfig(); - config.put(LOG_FILE, logFile.getAbsolutePath()); - config.put(LOG_FILE_SIZE_LIMIT, "1"); - config.put(SECURITY_LOG_FILE, securityLogFile.getAbsolutePath()); + config.setProperty(LOG_FILE, logFile.getAbsolutePath()); + config.setProperty(LOG_FILE_SIZE_LIMIT, "1"); + config.setProperty(SECURITY_LOG_FILE, securityLogFile.getAbsolutePath()); system = DistributedSystem.connect(config); @@ -162,8 +163,8 @@ public class CacheLogRollingIntegrationTest { @Test public void with_logFileSizeLimit_should_createMetaLogFile() { Properties config = createConfig(); - config.put(LOG_FILE, logFile.getAbsolutePath()); - config.put(LOG_FILE_SIZE_LIMIT, "1"); + config.setProperty(LOG_FILE, logFile.getAbsolutePath()); + config.setProperty(LOG_FILE_SIZE_LIMIT, "1"); system = DistributedSystem.connect(config); @@ -178,7 +179,7 @@ public class CacheLogRollingIntegrationTest { @Test public void without_logFileSizeLimit_shouldNot_createMetaLogFile() { Properties config = createConfig(); - config.put(LOG_FILE, logFile.getAbsolutePath()); + config.setProperty(LOG_FILE, logFile.getAbsolutePath()); system = DistributedSystem.connect(config); diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java index ba2a293..39fb22d 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java @@ -44,7 +44,7 @@ import org.apache.geode.test.dunit.ThreadUtils; import org.apache.geode.test.junit.categories.LoggingTest; /** - * This class tests the functionality of the (new multi-threaded) {@link MergeLogFiles} utility. + * Integration tests for (new multi-threaded) {@link MergeLogFiles} utility. */ @Category(LoggingTest.class) public class MergeLogFilesIntegrationTest { diff --git a/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java b/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java index a0a31d5..ca5bebd 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java @@ -115,7 +115,6 @@ public class DistributionLocator { } SystemFailure.loadEmergencyClasses(); - // log.info(Banner.getString(args)); final int port = parsePort(args[0]); InetAddress address = null; boolean peerLocator = true; diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/DateFormatter.java b/geode-core/src/main/java/org/apache/geode/internal/logging/DateFormatter.java index 6df52fa..1cb2b26 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/DateFormatter.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/DateFormatter.java @@ -20,7 +20,6 @@ import java.util.Date; /** * Defines the common date format for GemFire and provides DateFormat instances. - * */ public class DateFormatter { @@ -29,7 +28,7 @@ public class DateFormatter { */ public static final String FORMAT_STRING = "yyyy/MM/dd HH:mm:ss.SSS z"; - private static final DateFormat timeFormatter = createDateFormat(); + private static final DateFormat TIME_FORMATTER = createDateFormat(); /** * Creates a SimpleDateFormat using {@link #FORMAT_STRING}. @@ -39,7 +38,7 @@ public class DateFormatter { * format concurrently, it must be synchronized externally. */ public static DateFormat createDateFormat() { - return new SimpleDateFormat(DateFormatter.FORMAT_STRING); + return new SimpleDateFormat(FORMAT_STRING); } /** @@ -64,11 +63,11 @@ public class DateFormatter { * @param d a Date to format as a timestamp String. * @return a String representation of the current time. */ - public static String formatDate(Date d) { + public static String formatDate(final Date d) { try { - synchronized (timeFormatter) { + synchronized (TIME_FORMATTER) { // Need sync: see bug 21858 - return timeFormatter.format(d); + return TIME_FORMATTER.format(d); } } catch (Exception e1) { // Fix bug 21857 @@ -87,5 +86,7 @@ public class DateFormatter { /** * Do not instantiate this class. */ - private DateFormatter() {} + private DateFormatter() { + // do not instantiate this class + } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireFormatter.java b/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireFormatter.java index 06f4c82..e2eac93 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireFormatter.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireFormatter.java @@ -14,33 +14,28 @@ */ package org.apache.geode.internal.logging; +import java.io.IOException; import java.io.PrintWriter; +import java.io.StringWriter; import java.text.DateFormat; import java.util.Date; import java.util.logging.Formatter; import java.util.logging.LogRecord; -import org.apache.geode.LogWriter; - /** * Implementation of the standard JDK formatter that formats a message in GemFire's log format. */ public class GemFireFormatter extends Formatter { - /** - * Use the log writer to use some of its formatting code. - */ - private final LogWriter logWriter; - private final DateFormat dateFormat = DateFormatter.createDateFormat(); - public GemFireFormatter(LogWriter logWriter) { - this.logWriter = logWriter; + public GemFireFormatter() { + // nothing } @Override - public String format(LogRecord record) { - java.io.StringWriter sw = new java.io.StringWriter(); + public String format(final LogRecord record) { + StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println(); @@ -61,18 +56,6 @@ public class GemFireFormatter extends Formatter { pw.print(" msgSN="); pw.print(record.getSequenceNumber()); - // if (record.getLoggerName() != null) { - // pw.print(' '); - // pw.print(record.getLoggerName()); - // } - // if (record.getSourceClassName() != null) { - // pw.print(' '); - // pw.print(record.getSourceClassName()); - // } - // if (record.getSourceMethodName() != null) { - // pw.print(' '); - // pw.print(record.getSourceMethodName()); - // } pw.print(") "); String msg = record.getMessage(); @@ -81,8 +64,7 @@ public class GemFireFormatter extends Formatter { LogWriterImpl.formatText(pw, msg, 40); } catch (RuntimeException e) { pw.println(msg); - pw.println( - "Ignoring the following exception:"); + pw.println("Ignoring the following exception:"); e.printStackTrace(pw); } } else { @@ -94,9 +76,8 @@ public class GemFireFormatter extends Formatter { pw.close(); try { sw.close(); - } catch (java.io.IOException ignore) { + } catch (IOException ignore) { } - String result = sw.toString(); - return result; + return sw.toString(); } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireHandler.java b/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireHandler.java index bef89be..3766c74 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireHandler.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/GemFireHandler.java @@ -35,13 +35,13 @@ public class GemFireHandler extends Handler { public GemFireHandler(LogWriter logWriter) { this.logWriter = logWriter; - this.setFormatter(new GemFireFormatter(logWriter)); + setFormatter(new GemFireFormatter()); } @Override public void close() { // clear the reference to GFE LogWriter - this.logWriter = null; + logWriter = null; } @Override @@ -49,25 +49,25 @@ public class GemFireHandler extends Handler { // nothing needed } - private String getMessage(LogRecord record) { - final StringBuilder b = new StringBuilder(); - b.append('(').append("tid=" + record.getThreadID()) - .append(" msgId=" + record.getSequenceNumber()).append(") "); + private String getMessage(final LogRecord record) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append('(').append("tid=").append(record.getThreadID()) + .append(" msgId=").append(record.getSequenceNumber()).append(") "); if (record.getMessage() != null) { - b.append(getFormatter().formatMessage(record)); + stringBuilder.append(getFormatter().formatMessage(record)); } - return b.toString(); + return stringBuilder.toString(); } @Override - public void publish(LogRecord record) { + public void publish(final LogRecord record) { if (isLoggable(record)) { try { - if (this.logWriter instanceof LogWriterLogger) { - ((LogWriterLogger) this.logWriter).log(record.getLevel().intValue(), getMessage(record), + if (logWriter instanceof LogWriterLogger) { + ((LogWriterLogger) logWriter).log(record.getLevel().intValue(), getMessage(record), record.getThrown()); } else { - ((LogWriterImpl) this.logWriter).put(record.getLevel().intValue(), getMessage(record), + ((LogWriterImpl) logWriter).put(record.getLevel().intValue(), getMessage(record), record.getThrown()); } } catch (GemFireException ex) { diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LocalLogWriter.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LocalLogWriter.java index 4e42032..325a0dc 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LocalLogWriter.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LocalLogWriter.java @@ -17,9 +17,11 @@ package org.apache.geode.internal.logging; import java.io.PrintStream; import java.io.PrintWriter; +import org.apache.geode.LogWriter; + /** - * Implementation of {@link org.apache.geode.LogWriter} that will write to a local stream. + * Implementation of {@link LogWriter} that will write to a local stream. * <p> * Note this class is no longer needed. It can be replaced by PureLogWriter. */ diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LogFileParser.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LogFileParser.java index efcfe61..4a325a8 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LogFileParser.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LogFileParser.java @@ -24,17 +24,19 @@ import java.io.StringWriter; import java.text.DateFormat; import java.text.ParseException; import java.util.Date; +import java.util.StringTokenizer; +import org.apache.geode.LogWriter; import org.apache.geode.internal.ExitCode; /** - * Parses a log file written by a {@link org.apache.geode.LogWriter} into - * {@link LogFileParser.LogEntry}s. It behaves sort of like an {@link java.util.StringTokenizer}. - * + * Parses a log file written by a {@link LogWriter} into {@link LogFileParser.LogEntry}s. It + * behaves sort of like an {@link StringTokenizer}. * * @since GemFire 3.0 */ public class LogFileParser { + private static final boolean TRIM_TIMESTAMPS = Boolean.getBoolean("mergelogs.TRIM_TIMESTAMPS"); private static final boolean NEWLINE_AFTER_HEADER = @@ -45,8 +47,6 @@ public class LogFileParser { /** Text that signifies the start of a JRockit-style thread dump */ private static final String FULL_THREAD_DUMP = "===== FULL THREAD DUMP ==============="; - /////////////////////// Instance Fields /////////////////////// - /** The name of the log file being parsed */ private final String logFileName; @@ -54,14 +54,11 @@ public class LogFileParser { private final String extLogFileName; /** The buffer to read the log file from */ - private BufferedReader br; + private final BufferedReader br; /** Are there more entries to parser? */ private boolean hasMoreEntries; - /** The pattern used to match the first line of a log entry */ - // private Pattern pattern; - /** The timestamp of the entry being parsed */ private String timestamp; @@ -78,9 +75,7 @@ public class LogFileParser { private final StringBuffer whiteFileName; /** whether to suppress blank lines in output */ - private boolean suppressBlanks; - - ////////////////////// Constructors ////////////////////// + private final boolean suppressBlanks; /** * Creates a new <code>LogFileParser</code> that reads a log from a given @@ -91,7 +86,7 @@ public class LogFileParser { * <code>logFileName</code> is <code>null</code> nothing will be appended. * @param br Where to read the log from */ - public LogFileParser(String logFileName, BufferedReader br) { + public LogFileParser(final String logFileName, final BufferedReader br) { this(logFileName, br, false, false); } @@ -106,47 +101,43 @@ public class LogFileParser { * containing file names. * @param suppressBlanks whether to suppress blank lines */ - public LogFileParser(String logFileName, BufferedReader br, boolean tabOut, - boolean suppressBlanks) { + public LogFileParser(final String logFileName, final BufferedReader br, final boolean tabOut, + final boolean suppressBlanks) { this.logFileName = logFileName; this.br = br; - this.hasMoreEntries = true; - // this.pattern = - // Pattern.compile("\\[\\w+ (\\d\\d\\d\\d/\\d\\d/\\d\\d \\d\\d:\\d\\d:\\d\\d\\.\\d\\d\\d) .*"); - this.timestamp = null; - this.sb = new StringBuffer(); + hasMoreEntries = true; + timestamp = null; + sb = new StringBuffer(); this.suppressBlanks = suppressBlanks; - this.whiteFileName = new StringBuffer(); + whiteFileName = new StringBuffer(); if (tabOut) { int numTabs = (logFileName.length() + 2) / 8; for (int i = 0; i < numTabs; i++) { whiteFileName.append('\t'); } - for (int i = ((logFileName.length() + 2) % 8); i > 0; i--) { + for (int i = (logFileName.length() + 2) % 8; i > 0; i--) { whiteFileName.append(' '); } } if (this.logFileName != null) { - this.extLogFileName = this.logFileName + ": "; + extLogFileName = this.logFileName + ": "; } else { - this.extLogFileName = null; + extLogFileName = null; } } - //////////////////// Instance Methods //////////////////// - /** * Returns whether or not there are any more entries in the file to be parser. */ public boolean hasMoreEntries() { - return this.hasMoreEntries; + return hasMoreEntries; } /** * copy the timestamp out of a log entry, if there is one, and return it. if there isn't a * timestamp, return null */ - private String getTimestamp(String line) { + private String getTimestamp(final String line) { int llen = line.length(); String result = null; if (llen > 10) { @@ -157,58 +148,39 @@ public class LogFileParser { } // now look for gemfire's log format if (line.charAt(0) == '[') { - if ((line.charAt(1) == 'i' && line.charAt(2) == 'n' - && line.charAt(3) == 'f' /* - * && line.charAt(4) == 'o' - */) || - - (line.charAt(1) == 'f' && line.charAt(2) == 'i' - && line.charAt(3) == 'n' /* - * && line.charAt(4) == 'e' - */) + if (line.charAt(1) == 'i' && line.charAt(2) == 'n' + && line.charAt(3) == 'f' || + + line.charAt(1) == 'f' && line.charAt(2) == 'i' + && line.charAt(3) == 'n' || - (line.charAt(1) == 'w' && line.charAt(2) == 'a' - && line.charAt(3) == 'r' /* - * && line.charAt(4) == 'n' && line.charAt(5) == 'i' && - * line.charAt(6) == 'n' && line.charAt(7) == 'g' - */) + line.charAt(1) == 'w' && line.charAt(2) == 'a' + && line.charAt(3) == 'r' || - (line.charAt(1) == 'd' && line.charAt(2) == 'e' - && line.charAt(3) == 'b'/* - * && line.charAt(4) == 'u' && line.charAt(5) == 'g' - */) + line.charAt(1) == 'd' && line.charAt(2) == 'e' + && line.charAt(3) == 'b' || - (line.charAt(1) == 't' && line.charAt(2) == 'r' - && line.charAt(3) == 'a' /* - * && line.charAt(4) == 'c' && line.charAt(5) == 'e' - */) + line.charAt(1) == 't' && line.charAt(2) == 'r' + && line.charAt(3) == 'a' || - (line.charAt(1) == 's' && line.charAt(2) == 'e' - && line.charAt(3) == 'v' /* - * && line.charAt(4) == 'e' && line.charAt(5) == 'r' && - * line.charAt(6) == 'e' - */) + line.charAt(1) == 's' && line.charAt(2) == 'e' + && line.charAt(3) == 'v' || - (line.charAt(1) == 'c' && line.charAt(2) == 'o' - && line.charAt(3) == 'n' /* - * && line.charAt(4) == 'f' && line.charAt(5) == 'i' && - * line.charAt(6) == 'g' - */) + line.charAt(1) == 'c' && line.charAt(2) == 'o' + && line.charAt(3) == 'n' || - (line.charAt(1) == 'e' && line.charAt(2) == 'r' - && line.charAt(3) == 'r' /* - * && line.charAt(4) == 'o' && line.charAt(5) == 'r' - */) + line.charAt(1) == 'e' && line.charAt(2) == 'r' + && line.charAt(3) == 'r' || - (line.charAt(1) == 's' && line.charAt(2) == 'e' && line.charAt(3) == 'c' - && line.charAt(4) == 'u' && line.charAt(5) == 'r')) { + line.charAt(1) == 's' && line.charAt(2) == 'e' && line.charAt(3) == 'c' + && line.charAt(4) == 'u' && line.charAt(5) == 'r') { int sidx = 4; while (sidx < llen && line.charAt(sidx) != ' ') { sidx++; @@ -237,13 +209,12 @@ public class LogFileParser { } int llen = lineStr.length(); int lend = llen; - if (this.suppressBlanks || this.firstEntry) { + if (suppressBlanks || firstEntry) { // trim the end of the line while (lend > 1 && Character.isWhitespace(lineStr.charAt(lend - 1))) { lend--; } if (lend == 0) { - // System.out.println(this.logFileName + ": skipping line '" + lineStr + "'"); continue; } } @@ -295,18 +266,18 @@ public class LogFileParser { } if (timestamp != null) { - entry = new LogEntry(timestamp, sb.toString(), this.suppressBlanks); + entry = new LogEntry(timestamp, sb.toString(), suppressBlanks); } timestamp = nextTimestamp; - if (!this.firstEntry) { + if (!firstEntry) { sb = new StringBuffer(500); } else { - this.firstEntry = false; + firstEntry = false; } - if (this.extLogFileName != null) { - sb.append(this.extLogFileName); + if (extLogFileName != null) { + sb.append(extLogFileName); } } else if (line.indexOf(FULL_THREAD_DUMP) != -1) { @@ -331,8 +302,8 @@ public class LogFileParser { lineStr = dump; sb = new StringBuffer(); - if (this.extLogFileName != null) { - sb.append(this.extLogFileName); + if (extLogFileName != null) { + sb.append(extLogFileName); } sb.append("[dump "); sb.append(timestamp); @@ -343,7 +314,7 @@ public class LogFileParser { sb.append(dump); } } else { - sb.append(this.whiteFileName); + sb.append(whiteFileName); } sb.append(line); @@ -369,23 +340,21 @@ public class LogFileParser { pw.flush(); sb.insert(0, LINE_SEPARATOR + LINE_SEPARATOR); sb.insert(0, sw.toString().trim()); - sb.insert(0, this.extLogFileName); + sb.insert(0, extLogFileName); } // Place the final log entry entry = new LastLogEntry(timestamp, sb.toString()); - this.sb = null; - this.hasMoreEntries = false; + sb = null; + hasMoreEntries = false; return entry; } - ////////////////////// Main Program /////////////////////// - /** * Main program that simply parses a log file and prints out the entries. It is used for testing * purposes. */ - public static void main(String[] args) throws Throwable { + public static void main(final String[] args) throws Exception { if (args.length < 1) { System.err.println("** Missing log file name"); ExitCode.FATAL.doSystemExit(); @@ -401,30 +370,25 @@ public class LogFileParser { } } - - ////////////////////// Inner Classes ////////////////////// - /** * A parsed entry in a log file. Note that we maintain the entry's timestamp as a - * <code>String</code>. {@link java.text.DateFormat#parse(java.lang.String) Parsing} it was too + * <code>String</code>. {@link DateFormat#parse(String) Parsing} it was too * expensive. */ static class LogEntry { /** Timestamp of the log entry */ - private String timestamp; + private final String timestamp; /** The contents of the log entry */ - private String contents; + private final String contents; /** whether extraneous blank lines are being suppressed */ private boolean suppressBlanks; - //////////////////// Constructors //////////////////// - /** * Creates a new log entry with the given timestamp and contents */ - public LogEntry(String timestamp, String contents) { + public LogEntry(final String timestamp, final String contents) { this.timestamp = timestamp; this.contents = contents; } @@ -432,19 +396,17 @@ public class LogFileParser { /** * Creates a new log entry with the given timestamp and contents */ - public LogEntry(String timestamp, String contents, boolean suppressBlanks) { + public LogEntry(final String timestamp, final String contents, final boolean suppressBlanks) { this.timestamp = timestamp; this.contents = contents.trim(); this.suppressBlanks = suppressBlanks; } - //////////////////// Instance Methods //////////////////// - /** * Returns the timestamp of this log entry */ public String getTimestamp() { - return this.timestamp; + return timestamp; } /** @@ -453,15 +415,15 @@ public class LogFileParser { * @see #writeTo */ String getContents() { - return this.contents; + return contents; } /** * Writes the contents of this log entry to a <code>PrintWriter</code>. */ - public void writeTo(PrintWriter pw) { - pw.println(this.contents); - if (!this.suppressBlanks) { + public void writeTo(final PrintWriter pw) { + pw.println(contents); + if (!suppressBlanks) { pw.println(""); } pw.flush(); @@ -480,7 +442,8 @@ public class LogFileParser { * extra <code>boolean</code> field in each {@link LogFileParser.LogEntry}. */ static class LastLogEntry extends LogEntry { - public LastLogEntry(String timestamp, String contents) { + + public LastLogEntry(final String timestamp, final String contents) { super(timestamp, contents); } @@ -489,5 +452,4 @@ public class LogFileParser { return true; } } - } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LogWriterImpl.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LogWriterImpl.java index 094c0e2..e3140b2 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LogWriterImpl.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LogWriterImpl.java @@ -22,7 +22,6 @@ import java.text.BreakIterator; import java.text.DateFormat; import java.util.Arrays; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Handler; @@ -192,14 +191,13 @@ public abstract class LogWriterImpl implements InternalLogWriter { public static String join(List<?> list, String joinString) { StringBuilder result = new StringBuilder(80); boolean firstTime = true; - Iterator it = list.iterator(); - while (it.hasNext()) { + for (Object object : list) { if (firstTime) { firstTime = false; } else { result.append(joinString); } - result.append(it.next()); + result.append(object); } return result.toString(); } @@ -319,7 +317,7 @@ public abstract class LogWriterImpl implements InternalLogWriter { */ @Override public void severe(Throwable throwable) { - this.severe("", throwable); + severe("", throwable); } /** @@ -417,7 +415,7 @@ public abstract class LogWriterImpl implements InternalLogWriter { */ @Override public void error(Throwable throwable) { - this.error("", throwable); + error("", throwable); } /** @@ -515,7 +513,7 @@ public abstract class LogWriterImpl implements InternalLogWriter { */ @Override public void warning(Throwable throwable) { - this.warning("", throwable); + warning("", throwable); } /** @@ -613,7 +611,7 @@ public abstract class LogWriterImpl implements InternalLogWriter { */ @Override public void info(Throwable throwable) { - this.info("", throwable); + info("", throwable); } /** @@ -711,7 +709,7 @@ public abstract class LogWriterImpl implements InternalLogWriter { */ @Override public void config(Throwable throwable) { - this.config("", throwable); + config("", throwable); } /** diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThread.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThread.java index 87b2d35..3c89a5b 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThread.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThread.java @@ -27,7 +27,7 @@ public class LoggingThread extends Thread { * * @param name the name of the thread */ - public LoggingThread(String name) { + public LoggingThread(final String name) { this(name, null); } @@ -38,7 +38,7 @@ public class LoggingThread extends Thread { * @param name the name of the thread * @param runnable what the thread will run */ - public LoggingThread(String name, Runnable runnable) { + public LoggingThread(final String name, final Runnable runnable) { this(name, true, runnable); } @@ -50,9 +50,10 @@ public class LoggingThread extends Thread { * @param isDaemon true if thread will be marked as a daemon * @param runnable what the thread will run */ - public LoggingThread(String name, boolean isDaemon, Runnable runnable) { + public LoggingThread(final String name, final boolean isDaemon, final Runnable runnable) { super(runnable, name); setDaemon(isDaemon); + // TODO: fix escaping reference of this LoggingUncaughtExceptionHandler.setOnThread(this); } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadFactory.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadFactory.java index e90257d..a9967a3 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadFactory.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadFactory.java @@ -40,7 +40,7 @@ public class LoggingThreadFactory implements ThreadFactory { private final AtomicInteger threadCount = new AtomicInteger(1); public interface ThreadInitializer { - public void initialize(Thread thread); + void initialize(Thread thread); } public interface CommandWrapper { @@ -48,7 +48,7 @@ public class LoggingThreadFactory implements ThreadFactory { * Invoke the current method passing it a runnable that it can * decide to call when it wants. */ - public void invoke(Runnable runnable); + void invoke(Runnable runnable); } /** @@ -111,20 +111,20 @@ public class LoggingThreadFactory implements ThreadFactory { } private String getUniqueName() { - return this.baseName + threadCount.getAndIncrement(); + return baseName + threadCount.getAndIncrement(); } @Override public Thread newThread(Runnable runnable) { Runnable commandToRun; - if (this.commandWrapper != null) { - commandToRun = () -> this.commandWrapper.invoke(runnable); + if (commandWrapper != null) { + commandToRun = () -> commandWrapper.invoke(runnable); } else { commandToRun = runnable; } Thread thread = new LoggingThread(getUniqueName(), isDaemon, commandToRun); - if (this.threadInitializer != null) { - this.threadInitializer.initialize(thread); + if (threadInitializer != null) { + threadInitializer.initialize(thread); } return thread; } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadGroup.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadGroup.java index 6b06c71..54e4601 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadGroup.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingThreadGroup.java @@ -14,6 +14,8 @@ */ package org.apache.geode.internal.logging; +import static org.apache.geode.internal.logging.InternalLogWriter.ALL_LEVEL; + import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -37,12 +39,10 @@ import org.apache.geode.internal.Assert; public class LoggingThreadGroup extends ThreadGroup { /** A "local" log writer that logs exceptions to standard error */ - private static final StandardErrorPrinter stderr = - new StandardErrorPrinter(InternalLogWriter.ALL_LEVEL); + private static final StandardErrorPrinter stderr = new StandardErrorPrinter(ALL_LEVEL); /** A set of all created LoggingThreadGroups */ - private static final Collection<LoggingThreadGroup> loggingThreadGroups = - new ArrayList<LoggingThreadGroup>(); + private static final Collection<LoggingThreadGroup> loggingThreadGroups = new ArrayList<>(); /** * Returns a <code>ThreadGroup</code> whose {@link ThreadGroup#uncaughtException} method logs to @@ -62,7 +62,6 @@ public class LoggingThreadGroup extends ThreadGroup { * @param logWriter A <code>InternalLogWriter</code> to log uncaught exceptions to. It is okay for * this argument to be <code>null</code>. * - * author David Whitlock * @since GemFire 3.0 */ public static LoggingThreadGroup createThreadGroup(final String name, @@ -73,7 +72,7 @@ public class LoggingThreadGroup extends ThreadGroup { synchronized (loggingThreadGroups) { for (Iterator<LoggingThreadGroup> iter = loggingThreadGroups.iterator(); iter.hasNext();) { - LoggingThreadGroup group2 = (LoggingThreadGroup) iter.next(); + LoggingThreadGroup group2 = iter.next(); if (group2.isDestroyed()) { // Clean is this iterator out iter.remove(); @@ -113,7 +112,6 @@ public class LoggingThreadGroup extends ThreadGroup { * @param logger A <code>InternalLogWriter</code> to log uncaught exceptions to. It is okay for * this argument to be <code>null</code>. * - * author David Whitlock * @since GemFire 3.0 */ public static LoggingThreadGroup createThreadGroup(final String name, final Logger logger) { @@ -123,7 +121,7 @@ public class LoggingThreadGroup extends ThreadGroup { synchronized (loggingThreadGroups) { for (Iterator<LoggingThreadGroup> iter = loggingThreadGroups.iterator(); iter.hasNext();) { - LoggingThreadGroup group2 = (LoggingThreadGroup) iter.next(); + LoggingThreadGroup group2 = iter.next(); if (group2.isDestroyed()) { // Clean is this iterator out iter.remove(); @@ -155,36 +153,12 @@ public class LoggingThreadGroup extends ThreadGroup { return group; } - // /** - // * @deprecated Only for use by hydra for backwards compatability reasons. - // * Returns a <code>ThreadGroup</code> whose {@link - // * ThreadGroup#uncaughtException} method logs to both {#link - // * System#err} and the given <code>LogWriterI18n</code>. - // * - // * @param name - // * The name of the <code>ThreadGroup</code> - // * @param logger - // * A <code>LogWriter</code> to log uncaught exceptions to. It - // * is okay for this argument to be <code>null</code>. - // * - // * author kbanks - // * @since GemFire 6.0 - // */ - // @Deprecated public static LoggingThreadGroup createThreadGroup(final String name, - // final LogWriter logger) { - // return createThreadGroup(name, - // logger != null ? logger.convertToLogWriterI18n() : null); - // } - public static void cleanUpThreadGroups() { synchronized (loggingThreadGroups) { - LoggingThreadGroup group; - Iterator<?> itr = loggingThreadGroups.iterator(); - while (itr.hasNext()) { - group = (LoggingThreadGroup) itr.next(); - if (!group.getName().equals(InternalDistributedSystem.SHUTDOWN_HOOK_NAME) - && !group.getName().equals("GemFireConnectionFactory Shutdown Hook")) { - group.cleanup(); + for (LoggingThreadGroup loggingThreadGroup : loggingThreadGroups) { + if (!loggingThreadGroup.getName().equals(InternalDistributedSystem.SHUTDOWN_HOOK_NAME) + && !loggingThreadGroup.getName().equals("GemFireConnectionFactory Shutdown Hook")) { + loggingThreadGroup.cleanup(); } } } @@ -246,14 +220,14 @@ public class LoggingThreadGroup extends ThreadGroup { this.logger = logger; } - private Object dispatchLock = new Object(); + private final Object dispatchLock = new Object(); /** * Logs an uncaught exception to a log writer */ @Override public void uncaughtException(final Thread t, final Throwable ex) { - synchronized (this.dispatchLock) { + synchronized (dispatchLock) { if (ex instanceof VirtualMachineError) { SystemFailure.setFailure((VirtualMachineError) ex); // don't throw } @@ -266,27 +240,22 @@ public class LoggingThreadGroup extends ThreadGroup { "Uncaught exception in thread %s this message can be disregarded if it occurred during an Application Server shutdown. The Exception message was: %s"; final Object[] msgArgs = new Object[] {t, ex.getLocalizedMessage()}; stderr.info(String.format(msg, msgArgs)); - if (this.logger != null) { - this.logger.info(String.format(msg, msgArgs)); + if (logger != null) { + logger.info(String.format(msg, msgArgs)); } - if (this.logWriter != null) { - this.logWriter.info(String.format(msg, msgArgs)); + if (logWriter != null) { + logWriter.info(String.format(msg, msgArgs)); } } else { stderr.severe(String.format("Uncaught exception in thread %s", t), ex); - if (this.logger != null) { - this.logger.fatal(String.format("Uncaught exception in thread %s", t), ex); + if (logger != null) { + logger.fatal(String.format("Uncaught exception in thread %s", t), ex); } - if (this.logWriter != null) { - this.logWriter.severe(String.format("Uncaught exception in thread %s", t), ex); + if (logWriter != null) { + logWriter.severe(String.format("Uncaught exception in thread %s", t), ex); } } - // if (!(ex instanceof RuntimeException) && (ex instanceof Exception)) { - // something's fishy - checked exceptions shouldn't get here - // this.logger.severe("stack trace showing origin of uncaught checked exception", new - // Exception("stack trace"); - // } - this.uncaughtExceptionsCount++; + uncaughtExceptionsCount++; } } @@ -295,8 +264,8 @@ public class LoggingThreadGroup extends ThreadGroup { * clear number of uncaught exceptions */ public void clearUncaughtExceptionsCount() { - synchronized (this.dispatchLock) { - this.uncaughtExceptionsCount = 0; + synchronized (dispatchLock) { + uncaughtExceptionsCount = 0; } } @@ -304,7 +273,7 @@ public class LoggingThreadGroup extends ThreadGroup { * Returns the number of uncaught exceptions that occurred in threads in this thread group. */ public long getUncaughtExceptionsCount() { - synchronized (this.dispatchLock) { + synchronized (dispatchLock) { return uncaughtExceptionsCount; } } @@ -318,7 +287,7 @@ public class LoggingThreadGroup extends ThreadGroup { // the logwriter holds onto a distribution config, which holds onto // the InternalDistributedSystem, which holds onto the // DistributionManager, which holds onto ... you get the idea - this.logger = null; - this.logWriter = null; + logger = null; + logWriter = null; } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandler.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandler.java index d8edf2e..8f19db4 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandler.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandler.java @@ -16,6 +16,8 @@ */ package org.apache.geode.internal.logging; +import static org.apache.geode.distributed.internal.InternalDistributedSystem.SHUTDOWN_HOOK_NAME; + import java.lang.Thread.UncaughtExceptionHandler; import java.text.MessageFormat; import java.util.concurrent.atomic.AtomicInteger; @@ -23,14 +25,13 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.logging.log4j.Logger; import org.apache.geode.SystemFailure; -import org.apache.geode.distributed.internal.InternalDistributedSystem; /** - * This class delegates to a static singleton that handles all - * exceptions not caught by any thread created in geode. - * So all interactions with it are done with static methods. + * This class delegates to a static singleton that handles all exceptions not caught by any thread + * created in geode. So all interactions with it are done with static methods. */ public class LoggingUncaughtExceptionHandler { + private static final Implementation handler = new Implementation(LogService.getLogger(), error -> SystemFailure.setFailure(error)); @@ -41,7 +42,7 @@ public class LoggingUncaughtExceptionHandler { /** * Sets the logging uncaught exception handler on the given thread. */ - public static void setOnThread(Thread thread) { + public static void setOnThread(final Thread thread) { handler.setOnThread(thread); } @@ -58,41 +59,42 @@ public class LoggingUncaughtExceptionHandler { } // non-private for unit testing - interface FailureSettor { + interface FailureSetter { + void setFailure(VirtualMachineError error); } // non-private for unit testing static class Implementation implements UncaughtExceptionHandler { + private final Logger logger; - private final FailureSettor failureSettor; + private final FailureSetter failureSetter; private final AtomicInteger uncaughtExceptionsCount = new AtomicInteger(); - Implementation(Logger logger, FailureSettor failureSettor) { + Implementation(final Logger logger, final FailureSetter failureSetter) { this.logger = logger; - this.failureSettor = failureSettor; + this.failureSetter = failureSetter; } @Override - public void uncaughtException(Thread t, Throwable ex) { - if (ex instanceof VirtualMachineError) { - this.failureSettor.setFailure((VirtualMachineError) ex); + public void uncaughtException(final Thread t, final Throwable e) { + if (e instanceof VirtualMachineError) { + failureSetter.setFailure((VirtualMachineError) e); } // Solution to treat the shutdown hook error as a special case. // Do not change the hook's thread name without also changing it here. - if ((ex instanceof NoClassDefFoundError) - && (t.getName().equals(InternalDistributedSystem.SHUTDOWN_HOOK_NAME))) { + if (e instanceof NoClassDefFoundError && t.getName().equals(SHUTDOWN_HOOK_NAME)) { logger.info( "Uncaught exception in thread {} this message can be disregarded if it occurred during an Application Server shutdown. The Exception message was: {}", - t, ex); + t, e); } else { String message = MessageFormat.format("Uncaught exception in thread {0}", t); - logger.fatal(message, ex); + logger.fatal(message, e); } uncaughtExceptionsCount.incrementAndGet(); } - void setOnThread(Thread thread) { + void setOnThread(final Thread thread) { thread.setUncaughtExceptionHandler(this); } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/MergeLogFiles.java b/geode-core/src/main/java/org/apache/geode/internal/logging/MergeLogFiles.java index 48701ed..647a5e2 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/MergeLogFiles.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/MergeLogFiles.java @@ -41,15 +41,15 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import org.apache.geode.LogWriter; import org.apache.geode.SystemFailure; import org.apache.geode.internal.Assert; import org.apache.geode.internal.ExitCode; /** * This program merges entries from multiple GemFire log files (those written using a - * {@link org.apache.geode.LogWriter} together, sorting them by their timestamp. Note that - * this program assumes that the entries in the individual log files are themselves sorted by - * timestamp. + * {@link LogWriter} together, sorting them by their timestamp. Note that this program assumes that + * the entries in the individual log files are themselves sorted by timestamp. * <p> * * MergeLogFiles has several command line options:<br> @@ -92,17 +92,16 @@ import org.apache.geode.internal.ExitCode; * @see SortLogFile * @see LogFileParser * - * - * * @since GemFire 2.0 (-pids, -threads, -align, and -noblanks added in 5.1) */ public class MergeLogFiles { - private static PrintStream out = System.out; - private static PrintStream err = System.err; + + private static final PrintStream out = System.out; + private static final PrintStream err = System.err; /** * Merges the log files from a given set of <code>InputStream</code>s into a - * <code>PrinWriter</code>. + * <code>PrintWriter</code>. * * @param logFiles The log files to be merged * @param mergedFile Where the merged logs are printed to @@ -112,13 +111,14 @@ public class MergeLogFiles { * @throws IllegalArgumentException If the length of <code>logFiles</code> is not the same as the * length of <code>logFileNames</code> */ - public static boolean mergeLogFiles(Map<String, InputStream> logFiles, PrintWriter mergedFile) { + public static boolean mergeLogFiles(final Map<String, InputStream> logFiles, + final PrintWriter mergedFile) { return mergeLogFiles(logFiles, mergedFile, false, false, false, new LinkedList()); } /** * Merges the log files from a given set of <code>InputStream</code>s into a - * <code>PrinWriter</code>. + * <code>PrintWriter</code>. * * @param logFiles The log files to be merged * @param mergedFile Where the merged logs are printed to @@ -130,20 +130,17 @@ public class MergeLogFiles { * @throws IllegalArgumentException If the length of <code>logFiles</code> is not the same as the * length of <code>logFileNames</code> */ - public static boolean mergeLogFiles(Map<String, InputStream> logFiles, - PrintWriter mergedFile, boolean tabOut, boolean suppressBlanks, boolean multithreaded, - List<String> patterns) { - return Sorter.mergeLogFiles(logFiles, mergedFile, tabOut, suppressBlanks, - multithreaded, patterns); + public static boolean mergeLogFiles(final Map<String, InputStream> logFiles, + final PrintWriter mergedFile, final boolean tabOut, final boolean suppressBlanks, + final boolean multithreaded, final List<String> patterns) { + return Sorter.mergeLogFiles(logFiles, mergedFile, tabOut, suppressBlanks, multithreaded, + patterns); } - - // ////////////////// Main Program //////////////////// - /** * Prints usage information about this program */ - private static void usage(String s) { + private static void usage(final String s) { // note that we don't document the -pids switch because it is tailored // to how hydra works and would not be useful for customers err.println(LINE_SEPARATOR + "** " + s + LINE_SEPARATOR); @@ -161,18 +158,15 @@ public class MergeLogFiles { + "Suppress output of blank lines"); err.println("-threaded " + "Use multithreading to take advantage of multiple CPUs"); - // err.println("-regex pattern Case-insensitive search for a regular expression."); - // err.println(" May be used multiple times. Use Java regular "); - // err.println(" expression syntax (see java.util.regex.Pattern)."); - err.println(""); + err.println(); err.println( "Merges multiple GemFire log files and sorts them by timestamp."); err.println( "The merged log file is written to System.out (or a file)."); - err.println(""); + err.println(); err.println( "If a directory is specified, all .log files in that directory are merged."); - err.println(""); + err.println(); ExitCode.FATAL.doSystemExit(); } @@ -182,7 +176,7 @@ public class MergeLogFiles { * @param dirName directory to search * @return all of the .log files found (Files) */ - static ArrayList<File> getLogFiles(String dirName) { + static ArrayList<File> getLogFiles(final String dirName) { ArrayList<File> result = new ArrayList<>(); File dir = new File(dirName); @@ -198,7 +192,7 @@ public class MergeLogFiles { return result; } - public static void main(String[] args) throws IOException { + public static void main(final String... args) throws IOException { File mergeFile = null; ArrayList files = new ArrayList(); List nickNames = null; @@ -207,7 +201,7 @@ public class MergeLogFiles { boolean tabOut = false; boolean suppressBlanks = false; boolean multithreaded = false; - List<String> patterns = new LinkedList(); + List<String> patterns = new LinkedList<>(); // Parse command line for (int i = 0; i < args.length; i++) { @@ -305,7 +299,7 @@ public class MergeLogFiles { File file = (File) files.get(i); String logFileName; - if (findPIDs && (nickNames.get(i) != null)) { + if (findPIDs && nickNames.get(i) != null) { if (file.getCanonicalPath().toLowerCase().endsWith("gz")) { logFileName = nickNames.get(i) + ".gz"; } else { @@ -337,8 +331,6 @@ public class MergeLogFiles { ExitCode.NORMAL.doSystemExit(); } - ////////////////////// Inner Classes ////////////////////// - /** * hydra log files usually have the process's PID in their path name. This method extracts the PID * number and assigns the corresponding File a nickname using the PID and the position of the File @@ -348,18 +340,15 @@ public class MergeLogFiles { * gemfire_1043/system.log --> 1043-2<br> * gemfire_1043/system_01_00.log --> 1043-3<br> */ - private static ArrayList findPIDs(ArrayList files, PrintWriter output) { + private static ArrayList findPIDs(final ArrayList files, final PrintWriter output) { int pidTable[] = new int[files.size()]; int pidTableCounter[] = new int[pidTable.length]; ArrayList nickNames = new ArrayList(); char sep = File.separatorChar; - // System.out.println("findPids() invoked"); - for (Iterator it = files.iterator(); it.hasNext();) { File f = (File) it.next(); String name = f.getPath(); - // System.out.println("considering " + name); String slashdotslash = "" + sep + "." + sep; int startIdx = name.lastIndexOf(slashdotslash); @@ -376,11 +365,9 @@ public class MergeLogFiles { startIdx--; char c = name.charAt(startIdx); if (!('0' <= c && c <= '9')) { - // System.out.println("no number found in directory name"); startIdx = 0; } else { - // see if this is a hydra-generated test directory name, like - // parReg-0504-161349 + // see if this is a hydra-generated test directory name, like parReg-0504-161349 int testIdx = startIdx - 1; while (testIdx > 0 && '0' <= name.charAt(testIdx) && name.charAt(testIdx) <= '9') { testIdx--; @@ -388,7 +375,6 @@ public class MergeLogFiles { if (testIdx < 1 || name.charAt(testIdx) == '-') { startIdx = 0; } - // System.out.println("using directory name: '" + name.substring(0, startIdx+1) + "'"); } } @@ -403,26 +389,21 @@ public class MergeLogFiles { } else if (startIdx > 3 && name.charAt(startIdx) == 'g' && name.charAt(startIdx - 1) == 'o' && name.charAt(startIdx - 2) == 'l' && name.charAt(startIdx - 3) == '.') { startIdx -= 4; - // System.out.println("using file name: '" + name.substring(0,startIdx+1) + "'"); } - // else { - // System.out.println("could not find a PID"); - // } } - // find the string of numbers at the end of the test area and use it - // as a PID - String PID = null; + // find the string of numbers at the end of the test area and use it as a PID + String PID; for (int i = startIdx; i >= 0; i--) { char c = name.charAt(i); // System.out.println("charAt("+i+")="+c); if (!('0' <= c && c <= '9')) { - if (i < (name.length() - 1)) { // have a number + if (i < name.length() - 1) { // have a number // there's a number - assume it's a PID if it's not zero PID = name.substring(i + 1, startIdx + 1); // System.out.println("parsing '" + PID + "'"); try { - int iPID = Integer.valueOf(PID).intValue(); + int iPID = Integer.valueOf(PID); if (iPID > 0) { // System.out.println("Found PID " + iPID); int p = 0; @@ -461,6 +442,7 @@ public class MergeLogFiles { /** interface for threaded and non-threaded reader classes */ interface Reader { + LogFileParser.LogEntry peek(); LogFileParser.LogEntry poll(); @@ -472,37 +454,23 @@ public class MergeLogFiles { int getUniqueId(); } - /** * Thread that reads an entry from a GemFire log file and adds it a bounded queue. The entries are * consumed by a {@link MergeLogFiles.Sorter}. */ static class NonThreadedReader implements Reader { - /** The maximum size of the entry queue */ - // private static int QUEUE_CAPACITY = 1000; - - //////////////////// Instance Methods //////////////////// - /** The log file */ private BufferedReader logFile; /** The name of the log file */ - private String logFileName; + private final String logFileName; - /** whether to suppress blank lines */ - // private boolean suppressBlanks; - - /** whether to align non-timestamped lines with timestamped lines */ - // private boolean tabOut; - - private LogFileParser parser; + private final LogFileParser parser; private LogFileParser.LogEntry nextEntry; - private List<Pattern> patterns; - - //////////////////// Constructors //////////////////// + private final List<Pattern> patterns; /** * Creates a new <code>Reader</code> that reads from the given log file with the given name. @@ -510,9 +478,9 @@ public class MergeLogFiles { * * @param patterns java regular expressions that an entry must match one or more of */ - public NonThreadedReader(InputStream logFile, String logFileName, ThreadGroup group, - boolean tabOut, boolean suppressBlanks, List<Pattern> patterns) { - // super(group, "Reader for " + ((logFileName != null) ? logFileName : logFile.toString())); + public NonThreadedReader(final InputStream logFile, final String logFileName, + final ThreadGroup group, final boolean tabOut, final boolean suppressBlanks, + final List<Pattern> patterns) { if (logFileName.endsWith(".gz")) { try { this.logFile = new BufferedReader(new InputStreamReader(new GZIPInputStream(logFile))); @@ -525,25 +493,26 @@ public class MergeLogFiles { } this.logFileName = logFileName; this.patterns = patterns; - // this.suppressBlanks = suppressBlanks; - // this.tabOut = tabOut; - this.parser = new LogFileParser(this.logFileName, this.logFile, tabOut, suppressBlanks); + parser = new LogFileParser(this.logFileName, this.logFile, tabOut, suppressBlanks); } /** returns the file name being read */ + @Override public String getFileName() { - return this.logFileName; + return logFileName; } /** unique identifier, used for sorting instead of file name */ private int uniqueId; /** set the unique identifier for this reader */ - public void setUniqueId(int id) { + @Override + public void setUniqueId(final int id) { uniqueId = id; } /** retrieve the unique identifier for this reader */ + @Override public int getUniqueId() { return uniqueId; } @@ -554,8 +523,9 @@ public class MergeLogFiles { * * @return <code>null</code> if interrupted while waiting */ + @Override public synchronized LogFileParser.LogEntry peek() { - while (this.nextEntry == null) { + while (nextEntry == null) { try { nextEntry = parser.getNextEntry(); if (nextEntry == null) { @@ -573,8 +543,8 @@ public class MergeLogFiles { /** return true if the entry matches one or more regex patterns */ - private boolean patternMatch(LogFileParser.LogEntry entry) { - if (this.patterns == null || this.patterns.isEmpty()) { + private boolean patternMatch(final LogFileParser.LogEntry entry) { + if (patterns == null || patterns.isEmpty()) { return true; } for (Pattern p : patterns) { @@ -588,10 +558,11 @@ public class MergeLogFiles { /** * Removes the old log entry read from the log file */ + @Override public LogFileParser.LogEntry poll() { LogFileParser.LogEntry returnValue = null; - if (this.nextEntry != null) { - returnValue = this.nextEntry; + if (nextEntry != null) { + returnValue = nextEntry; nextEntry = null; } else { while (returnValue == null) { @@ -618,41 +589,33 @@ public class MergeLogFiles { static class ThreadedReader extends Thread implements Reader { /** The maximum size of the entry queue */ - private static int QUEUE_CAPACITY = 1000; - - //////////////////// Instance Methods //////////////////// + private static final int QUEUE_CAPACITY = 1000; /** The log file */ private BufferedReader logFile; /** The name of the log file */ - private String logFileName; + private final String logFileName; /** The queue containing log entries */ - private BlockingQueue queue; + private final BlockingQueue queue; /** whether to suppress blank lines */ - private boolean suppressBlanks; + private final boolean suppressBlanks; /** whether to align non-timestamped lines with timestamped lines */ - private boolean tabOut; - - private List<Pattern> patterns; + private final boolean tabOut; - //////////////////// Constructors //////////////////// + private final List<Pattern> patterns; /** * Creates a new <code>Reader</code> that reads from the given log file with the given name. * Invoking this constructor will start this reader thread. The InputStream is closed at the * end of processing. - * - * @param patterns TODO - * - * @see #run */ - public ThreadedReader(InputStream logFile, String logFileName, ThreadGroup group, - boolean tabOut, boolean suppressBlanks, List<Pattern> patterns) { - // super(group, "Reader for " + ((logFileName != null) ? logFileName : logFile.toString())); + public ThreadedReader(final InputStream logFile, final String logFileName, + final ThreadGroup group, final boolean tabOut, final boolean suppressBlanks, + final List<Pattern> patterns) { super(group, "Log File Reader"); if (logFileName.endsWith(".gz")) { try { @@ -665,29 +628,30 @@ public class MergeLogFiles { this.logFile = new BufferedReader(new InputStreamReader(logFile)); } this.logFileName = logFileName; - this.queue = new LinkedBlockingQueue(QUEUE_CAPACITY); - // new UnsharedMessageQueue(QUEUE_CAPACITY, - // (75 * QUEUE_CAPACITY) / 100); + queue = new LinkedBlockingQueue(QUEUE_CAPACITY); this.suppressBlanks = suppressBlanks; this.tabOut = tabOut; this.patterns = patterns; - this.start(); + start(); } /** returns the file name being read */ + @Override public String getFileName() { - return this.logFileName; + return logFileName; } /** unique identifier, used for sorting instead of file name */ private int uniqueId; /** set the unique identifier for this reader */ - public void setUniqueId(int id) { + @Override + public void setUniqueId(final int id) { uniqueId = id; } /** retrieve the unique identifier for this reader */ + @Override public int getUniqueId() { return uniqueId; } @@ -700,17 +664,17 @@ public class MergeLogFiles { @Override public void run() { LogFileParser parser = - new LogFileParser(this.logFileName, this.logFile, tabOut, suppressBlanks); + new LogFileParser(logFileName, logFile, tabOut, suppressBlanks); try { while (true) { SystemFailure.checkFailure(); LogFileParser.LogEntry entry = parser.getNextEntry(); if (entry.isLast() || patternMatch(entry)) { - this.queue.put(entry); + queue.put(entry); synchronized (this) { - this.notify(); + notify(); } } if (entry.isLast()) { @@ -733,8 +697,8 @@ public class MergeLogFiles { } /** return true if the entry matches one or more regex patterns */ - private boolean patternMatch(LogFileParser.LogEntry entry) { - if (this.patterns == null || this.patterns.isEmpty()) { + private boolean patternMatch(final LogFileParser.LogEntry entry) { + if (patterns == null || patterns.isEmpty()) { return true; } for (Pattern p : patterns) { @@ -751,17 +715,17 @@ public class MergeLogFiles { * * @return <code>null</code> if interrupted while waiting */ + @Override public LogFileParser.LogEntry peek() { - // out.println(this.getName() + " size " + this.queue.size()); - LogFileParser.LogEntry entry = (LogFileParser.LogEntry) this.queue.peek(); + LogFileParser.LogEntry entry = (LogFileParser.LogEntry) queue.peek(); if (entry == null) { synchronized (this) { - entry = (LogFileParser.LogEntry) this.queue.peek(); + entry = (LogFileParser.LogEntry) queue.peek(); while (entry == null) { boolean interrupted = Thread.interrupted(); try { - this.wait(); - entry = (LogFileParser.LogEntry) this.queue.peek(); + wait(); + entry = (LogFileParser.LogEntry) queue.peek(); } catch (InterruptedException e) { interrupted = true; } finally { @@ -778,8 +742,9 @@ public class MergeLogFiles { /** * Removes the old log entry read from the log file */ + @Override public LogFileParser.LogEntry poll() { - return (LogFileParser.LogEntry) this.queue.poll(); + return (LogFileParser.LogEntry) queue.poll(); } } @@ -787,20 +752,21 @@ public class MergeLogFiles { * A thread group that contains the reader threads and logs uncaught exceptions to standard error. */ static class ReaderGroup extends ThreadGroup { + /** Did an uncaught exception occur? */ private boolean exceptionOccurred; - ReaderGroup(String groupName) { + ReaderGroup(final String groupName) { super(groupName); - this.exceptionOccurred = false; + exceptionOccurred = false; } @Override - public void uncaughtException(Thread t, Throwable e) { + public void uncaughtException(final Thread t, final Throwable e) { if (e instanceof VirtualMachineError) { SystemFailure.setFailure((VirtualMachineError) e); // don't throw } - this.exceptionOccurred = true; + exceptionOccurred = true; System.err.println(String.format("Exception in %s", t)); e.printStackTrace(System.err); } @@ -809,7 +775,7 @@ public class MergeLogFiles { * Returns whether or not an uncaught exception occurred in one of the threads in this group. */ public boolean exceptionOccurred() { - return this.exceptionOccurred; + return exceptionOccurred; } } @@ -827,16 +793,15 @@ public class MergeLogFiles { * @param mergedFile Where the merged logs are printed to * @param tabOut Whether to align non-timestamped lines with others * @param suppressBlanks Whether to suppress output of blank lines - * @param patterns TODO * @return Whether or not problems occurred while merging the log files. * * @throws IllegalArgumentException If the length of <code>logFiles</code> is not the same as * the length of <code>logFileNames</code> */ - public static boolean mergeLogFiles(Map<String, InputStream> logFiles, - PrintWriter mergedFile, boolean tabOut, boolean suppressBlanks, boolean multithreaded, - List<String> patterns) { - List<Pattern> compiledPatterns = new LinkedList<Pattern>(); + public static boolean mergeLogFiles(final Map<String, InputStream> logFiles, + final PrintWriter mergedFile, final boolean tabOut, final boolean suppressBlanks, + final boolean multithreaded, final List<String> patterns) { + List<Pattern> compiledPatterns = new LinkedList<>(); for (String pattern : patterns) { compiledPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE)); } @@ -862,7 +827,7 @@ public class MergeLogFiles { Set sorted = sortReaders(readers); while (!readers.isEmpty()) { - Reader oldest = null; + Reader oldest; Iterator sortedIt = sorted.iterator(); if (!sortedIt.hasNext()) { break; @@ -871,7 +836,7 @@ public class MergeLogFiles { sortedIt.remove(); String nextReaderTimestamp = null; - Reader nextInLine = null; + Reader nextInLine; if (sortedIt.hasNext()) { nextInLine = (Reader) sortedIt.next(); nextReaderTimestamp = nextInLine.peek().getTimestamp(); @@ -884,7 +849,7 @@ public class MergeLogFiles { lastOldest = oldest; } - LogFileParser.LogEntry entry = null; + LogFileParser.LogEntry entry; // write until we hit the next file's time-stamp do { entry = oldest.peek(); @@ -911,7 +876,7 @@ public class MergeLogFiles { return group.exceptionOccurred(); } - private static Set sortReaders(Collection readers) { + private static Set sortReaders(final Collection readers) { Set sorted = new TreeSet(new ReaderComparator()); int uniqueId = 1; for (Iterator iter = readers.iterator(); iter.hasNext();) { @@ -924,12 +889,12 @@ public class MergeLogFiles { } return sorted; } - } protected static class ReaderComparator implements Comparator { - public int compare(Object o1, Object o2) { + @Override + public int compare(final Object o1, final Object o2) { Reader reader1 = (Reader) o1; int id1 = reader1.getUniqueId(); Reader reader2 = (Reader) o2; @@ -963,5 +928,4 @@ public class MergeLogFiles { return compare; } } - } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/SortLogFile.java b/geode-core/src/main/java/org/apache/geode/internal/logging/SortLogFile.java index da7b94e..5274d3c 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/SortLogFile.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/SortLogFile.java @@ -25,50 +25,44 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; -import java.util.Comparator; -import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; +import org.apache.geode.LogWriter; import org.apache.geode.internal.ExitCode; /** - * This program sorts the entries in a GemFire log file (one written using a - * {@link org.apache.geode.LogWriter}) by their timestamps. Note that in order to do so, we - * have to read the entire file into memory. + * This program sorts the entries in a GemFire log file (one written using a {@link LogWriter}) by + * their timestamps. Note that in order to do so, we have to read the entire file into memory. * * @see MergeLogFiles * @see LogFileParser * - * * @since GemFire 3.0 */ public class SortLogFile { - private static PrintStream out = System.out; - private static PrintStream err = System.err; + + private static final PrintStream out = System.out; + private static final PrintStream err = System.err; /** * Parses a log file from a given source and writes the sorted entries to a given destination. */ public static void sortLogFile(InputStream logFile, PrintWriter sortedFile) throws IOException { - SortedSet sorted = new TreeSet(new Comparator() { - public int compare(Object o1, Object o2) { - LogFileParser.LogEntry entry1 = (LogFileParser.LogEntry) o1; - LogFileParser.LogEntry entry2 = (LogFileParser.LogEntry) o2; - String stamp1 = entry1.getTimestamp(); - String stamp2 = entry2.getTimestamp(); - - if (stamp1.equals(stamp2)) { - if (entry1.getContents().equals(entry2.getContents())) { - // Timestamps and contents are both equal - compare hashCode() - return Integer.valueOf(entry1.hashCode()).compareTo(Integer.valueOf(entry2.hashCode())); - } else { - return entry1.getContents().compareTo(entry2.getContents()); - } + SortedSet<LogFileParser.LogEntry> sorted = new TreeSet<>((entry1, entry2) -> { + String stamp1 = entry1.getTimestamp(); + String stamp2 = entry2.getTimestamp(); + + if (stamp1.equals(stamp2)) { + if (entry1.getContents().equals(entry2.getContents())) { + // Timestamps and contents are both equal - compare hashCode() + return Integer.valueOf(entry1.hashCode()).compareTo(entry2.hashCode()); } else { - return stamp1.compareTo(stamp2); + return entry1.getContents().compareTo(entry2.getContents()); } + } else { + return stamp1.compareTo(stamp2); } }); @@ -78,34 +72,28 @@ public class SortLogFile { sorted.add(parser.getNextEntry()); } - for (Iterator iter = sorted.iterator(); iter.hasNext();) { - LogFileParser.LogEntry entry = (LogFileParser.LogEntry) iter.next(); + for (LogFileParser.LogEntry entry : sorted) { entry.writeTo(sortedFile); } } - //////////////////// Main Program //////////////////// - /** * Prints usage information about this program */ private static void usage(String s) { err.println(LINE_SEPARATOR + "** " + s + LINE_SEPARATOR); - err.println( - "Usage: java SortLogFile logFile"); - err.println("-sortedFile file " - + "File in which to put sorted log"); - err.println(""); + err.println("Usage: java SortLogFile logFile"); + err.println("-sortedFile file " + "File in which to put sorted log"); + err.println(); err.println( "Sorts a GemFire log file by timestamp. The merged log file is written to System.out (or a file)."); - err.println(""); + err.println(); ExitCode.FATAL.doSystemExit(); } - public static void main(String[] args) throws IOException { + public static void main(String... args) throws IOException { File logFile = null; File sortedFile = null; - // int dirCount = 0; for (int i = 0; i < args.length; i++) { if (args[i].equals("-sortedFile")) { @@ -148,5 +136,4 @@ public class SortLogFile { ExitCode.NORMAL.doSystemExit(); } - } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/StandardErrorPrinter.java b/geode-core/src/main/java/org/apache/geode/internal/logging/StandardErrorPrinter.java index 943c28e..ace70ea 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/StandardErrorPrinter.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/StandardErrorPrinter.java @@ -20,16 +20,16 @@ package org.apache.geode.internal.logging; class StandardErrorPrinter extends LocalLogWriter { /** - * Creates a writer that logs to <code>System.err</code>. All messages will be logged. + * Creates a writer that logs to {@code System.err}. All messages will be logged. * * @throws IllegalArgumentException if level is not in legal range */ StandardErrorPrinter() { - this(InternalLogWriter.ALL_LEVEL); + this(ALL_LEVEL); } /** - * Creates a writer that logs to <code>System.err</code>. + * Creates a writer that logs to {@code System.err}. * * @param level only messages greater than or equal to this value will be logged. * diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/StandardOutputPrinter.java b/geode-core/src/main/java/org/apache/geode/internal/logging/StandardOutputPrinter.java index f4e771c..7b971d3 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/StandardOutputPrinter.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/StandardOutputPrinter.java @@ -20,16 +20,16 @@ package org.apache.geode.internal.logging; class StandardOutputPrinter extends LocalLogWriter { /** - * Creates a writer that logs to <code>System.err</code>. All messages will be logged. + * Creates a writer that logs to {@code System.err}. All messages will be logged. * * @throws IllegalArgumentException if level is not in legal range */ StandardOutputPrinter() { - this(InternalLogWriter.ALL_LEVEL); + this(ALL_LEVEL); } /** - * Creates a writer that logs to <code>System.err</code>. + * Creates a writer that logs to {@code System.err}. * * @param level only messages greater than or equal to this value will be logged. * diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessage.java b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessage.java index d07cb24..9cf770b 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessage.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessage.java @@ -468,8 +468,8 @@ public class GemFireParameterizedMessage implements Message { } // str.append(Arrays.deepToString((Object[]) o)); } - } else if (o instanceof Map && !(o instanceof Region)) { // GEODE: do NOT use Map handling if - // instanceof Geode Region + } else if (o instanceof Map && !(o instanceof Region)) { + // GEODE: do NOT use Map handling if instanceof Geode Region // special handling of container Map final String id = identityToString(o); if (dejaVu.contains(id)) { @@ -494,10 +494,8 @@ public class GemFireParameterizedMessage implements Message { } str.append('}'); } - } else if (o instanceof Collection && !(o instanceof EntriesSet)) { // GEODE: do NOT use - // Colleciton handling if - // instanceof Geode - // EntriesSet + } else if (o instanceof Collection && !(o instanceof EntriesSet)) { + // GEODE: do NOT use Collection handling if instanceof Geode EntriesSet // special handling of container Collection final String id = identityToString(o); if (dejaVu.contains(id)) { @@ -569,9 +567,8 @@ public class GemFireParameterizedMessage implements Message { @Override public String toString() { + // GEODE: adjust toString to GemFireParameterizedMessage return "GemFireParameterizedMessage[messagePattern=" + messagePattern + ", stringArgs=" - + Arrays.toString(stringArgs) + ", throwable=" + throwable + ']'; // GEODE: adjust toString - // to - // GemFireParameterizedMessage + + Arrays.toString(stringArgs) + ", throwable=" + throwable + ']'; } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessageFactory.java b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessageFactory.java index 8ccb42b..92427c2 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessageFactory.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/message/GemFireParameterizedMessageFactory.java @@ -53,7 +53,7 @@ public class GemFireParameterizedMessageFactory extends AbstractMessageFactory { */ @Override public Message newMessage(final String message, final Object... params) { - return new GemFireParameterizedMessage(message, params); // GEODE: change to construct - // GemFireParameterizedMessage + // GEODE: change to construct GemFireParameterizedMessage + return new GemFireParameterizedMessage(message, params); } } diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java index 04ad2cc..376dcf3 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java @@ -21,6 +21,9 @@ import org.junit.experimental.categories.Category; import org.apache.geode.test.junit.categories.LoggingTest; +/** + * Unit tests for {@link LogWriterImpl}. + */ @Category(LoggingTest.class) public class LogWriterImplTest { diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadFactoryTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadFactoryTest.java index acff02c..4e94ef6 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadFactoryTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadFactoryTest.java @@ -25,10 +25,16 @@ import static org.mockito.Mockito.verify; import java.lang.Thread.UncaughtExceptionHandler; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.apache.geode.internal.logging.LoggingThreadFactory.CommandWrapper; import org.apache.geode.internal.logging.LoggingThreadFactory.ThreadInitializer; +import org.apache.geode.test.junit.categories.LoggingTest; +/** + * Unit tests for {@link LoggingThreadFactory}. + */ +@Category(LoggingTest.class) public class LoggingThreadFactoryTest { @Test diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadTest.java index 97f5dab..9b2b3cd 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingThreadTest.java @@ -21,7 +21,14 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.Thread.UncaughtExceptionHandler; import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.apache.geode.test.junit.categories.LoggingTest; + +/** + * Unit tests for {@link LoggingThread}. + */ +@Category(LoggingTest.class) public class LoggingThreadTest { @Test diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandlerTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandlerTest.java index 85cff4a..bdfb13e 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandlerTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/LoggingUncaughtExceptionHandlerTest.java @@ -27,10 +27,13 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.internal.logging.LoggingUncaughtExceptionHandler.FailureSettor; +import org.apache.geode.internal.logging.LoggingUncaughtExceptionHandler.FailureSetter; import org.apache.geode.internal.logging.LoggingUncaughtExceptionHandler.Implementation; import org.apache.geode.test.junit.categories.LoggingTest; +/** + * Unit tests for {@link LoggingUncaughtExceptionHandler}. + */ @Category(LoggingTest.class) public class LoggingUncaughtExceptionHandlerTest { @@ -106,7 +109,7 @@ public class LoggingUncaughtExceptionHandlerTest { Logger logger = mock(Logger.class); Thread thread = mock(Thread.class); VirtualMachineError error = mock(VirtualMachineError.class); - FailureSettor failureSettor = mock(FailureSettor.class); + FailureSetter failureSettor = mock(FailureSetter.class); Implementation handler = new Implementation(logger, failureSettor); handler.uncaughtException(thread, error); diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java index 329908a..07da2f8 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java @@ -33,7 +33,7 @@ import org.apache.geode.LogWriter; import org.apache.geode.test.junit.categories.LoggingTest; /** - * Tests the functionality of the {@link SortLogFile} program. + * Unit tests for {@link SortLogFile}. * * @since GemFire 3.0 */ diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java index 699e651..9a3ffd0 100755 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java @@ -73,7 +73,7 @@ public class FastLoggerTest { * FastLogger should return isDelegating after setDelegating */ @Test - public void returnIsDelegatingAfterSetDelegating() { + public void isDelegatingIsTrueAfterSetDelegating() { assertThat(fastLogger.isDelegating()).isTrue(); FastLogger.setDelegating(false); diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/HexThreadIdPatternConverterTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/HexThreadIdPatternConverterTest.java index e3d595e..30928a1 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/HexThreadIdPatternConverterTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/HexThreadIdPatternConverterTest.java @@ -20,10 +20,14 @@ import static org.assertj.core.api.Assertions.assertThat; import org.junit.Before; import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.test.junit.categories.LoggingTest; /** * Unit tests for {@link HexThreadIdPatternConverter}. */ +@Category(LoggingTest.class) public class HexThreadIdPatternConverterTest { private HexThreadIdPatternConverter converter; diff --git a/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java b/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java index 59f6ed5..0609cfb 100644 --- a/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java +++ b/geode-junit/src/main/java/org/apache/geode/test/process/ProcessWrapper.java @@ -343,7 +343,7 @@ public class ProcessWrapper { } final String commandString = processCommand.toString(); - logger.debug("Starting " + commandString); + logger.info("Starting " + commandString); final ProcessStreamReader stdOut = new ProcessStreamReader(commandString, this.process.getInputStream(), this.lineBuffer, this.allLines); diff --git a/geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordIntegrationTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/security/LogNoPasswordDistributedTest.java similarity index 98% rename from geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordIntegrationTest.java rename to geode-web/src/distributedTest/java/org/apache/geode/management/internal/security/LogNoPasswordDistributedTest.java index a44a976..6d5e6a5 100644 --- a/geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordIntegrationTest.java +++ b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/security/LogNoPasswordDistributedTest.java @@ -37,7 +37,7 @@ import org.apache.geode.test.junit.categories.SecurityTest; import org.apache.geode.test.junit.rules.GfshCommandRule; @Category({GfshTest.class, SecurityTest.class, LoggingTest.class}) -public class LogNoPasswordIntegrationTest { +public class LogNoPasswordDistributedTest { private static final String PASSWORD = "abcdefghijklmn";