8014045: test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java failing intermittently
This test was failing because it didn't take into account the fact that Loggers could be garbage collected. Reviewed-by: mchung
This commit is contained in:
parent
8de97d93a0
commit
7addcb118b
@ -36,12 +36,14 @@ import javax.management.MBeanServer;
|
|||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class LoggingMXBeanTest
|
public class LoggingMXBeanTest
|
||||||
{
|
{
|
||||||
static String LOGGER_NAME_1 = "com.sun.management.Logger";
|
static final String LOGGER_NAME_1 = "com.sun.management.Logger";
|
||||||
static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
|
static final String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
|
||||||
static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
|
static final String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
|
||||||
|
|
||||||
// These instance variables prevent premature logger garbage collection
|
// These instance variables prevent premature logger garbage collection
|
||||||
// See getLogger() weak reference warnings.
|
// See getLogger() weak reference warnings.
|
||||||
@ -213,23 +215,35 @@ public class LoggingMXBeanTest
|
|||||||
PlatformLoggingMXBean mxbean2) {
|
PlatformLoggingMXBean mxbean2) {
|
||||||
// verify logger names
|
// verify logger names
|
||||||
List<String> loggers1 = mxbean1.getLoggerNames();
|
List<String> loggers1 = mxbean1.getLoggerNames();
|
||||||
|
System.out.println("Loggers: " + loggers1);
|
||||||
|
|
||||||
|
// Retrieve the named loggers to prevent them from being
|
||||||
|
// spontaneously gc'ed.
|
||||||
|
Map<String, Logger> loggersMap = new HashMap<>();
|
||||||
|
for (String n : loggers1) {
|
||||||
|
loggersMap.put(n, Logger.getLogger(n));
|
||||||
|
}
|
||||||
|
|
||||||
List<String> loggers2 = mxbean2.getLoggerNames();
|
List<String> loggers2 = mxbean2.getLoggerNames();
|
||||||
|
|
||||||
|
// loggers1 and loggers2 should be identical - no new logger should
|
||||||
|
// have been created in between (at least no new logger name)
|
||||||
|
//
|
||||||
if (loggers1.size() != loggers2.size())
|
if (loggers1.size() != loggers2.size())
|
||||||
throw new RuntimeException("LoggerNames: unmatched number of entries");
|
throw new RuntimeException("LoggerNames: unmatched number of entries");
|
||||||
List<String> loggers3 = new ArrayList<>(loggers1);
|
if (!loggers2.containsAll(loggersMap.keySet()))
|
||||||
loggers3.removeAll(loggers2);
|
|
||||||
if (loggers3.size() != 0)
|
|
||||||
throw new RuntimeException("LoggerNames: unmatched loggers");
|
throw new RuntimeException("LoggerNames: unmatched loggers");
|
||||||
|
|
||||||
|
|
||||||
// verify logger's level and parent
|
// verify logger's level and parent
|
||||||
for (String logger : loggers1) {
|
for (String logger : loggers1) {
|
||||||
if (!mxbean1.getLoggerLevel(logger)
|
String level1 = mxbean1.getLoggerLevel(logger);
|
||||||
.equals(mxbean2.getLoggerLevel(logger)))
|
String level2 = mxbean2.getLoggerLevel(logger);
|
||||||
|
if (!java.util.Objects.equals(level1, level2)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"LoggerLevel: unmatched level for " + logger
|
"LoggerLevel: unmatched level for " + logger
|
||||||
+ ", " + mxbean1.getLoggerLevel(logger)
|
+ ", " + level1 + ", " + level2);
|
||||||
+ ", " + mxbean2.getLoggerLevel(logger));
|
}
|
||||||
|
|
||||||
if (!mxbean1.getParentLoggerName(logger)
|
if (!mxbean1.getParentLoggerName(logger)
|
||||||
.equals(mxbean2.getParentLoggerName(logger)))
|
.equals(mxbean2.getParentLoggerName(logger)))
|
||||||
|
Loading…
Reference in New Issue
Block a user