提交 7d661576 编写于 作者: M mchung

7067691: java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java failing intermittently

Reviewed-by: alanb, mchung
Contributed-by: gary.adams@oracle.com
上级 3de78351
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 7024172 * @bug 7024172 7067691
* @summary Test if proxy for PlatformLoggingMXBean is equivalent * @summary Test if proxy for PlatformLoggingMXBean is equivalent
* to proxy for LoggingMXBean * to proxy for LoggingMXBean
* *
...@@ -43,6 +43,13 @@ public class LoggingMXBeanTest ...@@ -43,6 +43,13 @@ public class LoggingMXBeanTest
static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2"; static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown"; static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
// These instance variables prevent premature logger garbage collection
// See getLogger() weak reference warnings.
Logger logger1;
Logger logger2;
static LoggingMXBeanTest test;
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
LoggingMXBean proxy = LoggingMXBean proxy =
...@@ -51,7 +58,7 @@ public class LoggingMXBeanTest ...@@ -51,7 +58,7 @@ public class LoggingMXBeanTest
LoggingMXBean.class); LoggingMXBean.class);
// test LoggingMXBean proxy // test LoggingMXBean proxy
LoggingMXBeanTest p = new LoggingMXBeanTest(proxy); test = new LoggingMXBeanTest(proxy);
// check if the attributes implemented by PlatformLoggingMXBean // check if the attributes implemented by PlatformLoggingMXBean
// and LoggingMXBean return the same value // and LoggingMXBean return the same value
...@@ -64,9 +71,9 @@ public class LoggingMXBeanTest ...@@ -64,9 +71,9 @@ public class LoggingMXBeanTest
// same verification as in java/util/logging/LoggingMXBeanTest2 // same verification as in java/util/logging/LoggingMXBeanTest2
public LoggingMXBeanTest(LoggingMXBean mbean) throws Exception { public LoggingMXBeanTest(LoggingMXBean mbean) throws Exception {
Logger logger1 = Logger.getLogger( LOGGER_NAME_1 ); logger1 = Logger.getLogger( LOGGER_NAME_1 );
logger1.setLevel(Level.FINE); logger1.setLevel(Level.FINE);
Logger logger2 = Logger.getLogger( LOGGER_NAME_2 ); logger2 = Logger.getLogger( LOGGER_NAME_2 );
logger2.setLevel(null); logger2.setLevel(null);
/* /*
...@@ -207,6 +214,7 @@ public class LoggingMXBeanTest ...@@ -207,6 +214,7 @@ public class LoggingMXBeanTest
// verify logger names // verify logger names
List<String> loggers1 = mxbean1.getLoggerNames(); List<String> loggers1 = mxbean1.getLoggerNames();
List<String> loggers2 = mxbean2.getLoggerNames(); List<String> loggers2 = mxbean2.getLoggerNames();
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); List<String> loggers3 = new ArrayList<>(loggers1);
...@@ -219,7 +227,10 @@ public class LoggingMXBeanTest ...@@ -219,7 +227,10 @@ public class LoggingMXBeanTest
if (!mxbean1.getLoggerLevel(logger) if (!mxbean1.getLoggerLevel(logger)
.equals(mxbean2.getLoggerLevel(logger))) .equals(mxbean2.getLoggerLevel(logger)))
throw new RuntimeException( throw new RuntimeException(
"LoggerLevel: unmatched level for " + logger); "LoggerLevel: unmatched level for " + logger
+ ", " + mxbean1.getLoggerLevel(logger)
+ ", " + mxbean2.getLoggerLevel(logger));
if (!mxbean1.getParentLoggerName(logger) if (!mxbean1.getParentLoggerName(logger)
.equals(mxbean2.getParentLoggerName(logger))) .equals(mxbean2.getParentLoggerName(logger)))
throw new RuntimeException( throw new RuntimeException(
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6876135 7024172 * @bug 6876135 7024172 7067691
* *
* @summary Test PlatformLoggingMXBean * @summary Test PlatformLoggingMXBean
* This test performs similar testing as * This test performs similar testing as
...@@ -41,11 +41,15 @@ import java.util.List; ...@@ -41,11 +41,15 @@ import java.util.List;
public class PlatformLoggingMXBeanTest public class PlatformLoggingMXBeanTest
{ {
ObjectName objectName = null; ObjectName objectName = null;
static String LOGGER_NAME_1 = "com.sun.management.Logger1"; static String LOGGER_NAME_1 = "com.sun.management.Logger1";
static String LOGGER_NAME_2 = "com.sun.management.Logger2"; static String LOGGER_NAME_2 = "com.sun.management.Logger2";
// Use Logger instance variables to prevent premature garbage collection
// of weak references.
Logger logger1;
Logger logger2;
public PlatformLoggingMXBeanTest() throws Exception { public PlatformLoggingMXBeanTest() throws Exception {
} }
...@@ -135,8 +139,8 @@ public class PlatformLoggingMXBeanTest ...@@ -135,8 +139,8 @@ public class PlatformLoggingMXBeanTest
System.out.println( "*********** Phase 3 ***********" ); System.out.println( "*********** Phase 3 ***********" );
System.out.println( "*******************************" ); System.out.println( "*******************************" );
System.out.println( " Create and test new Loggers" ); System.out.println( " Create and test new Loggers" );
Logger logger1 = Logger.getLogger( LOGGER_NAME_1 ); logger1 = Logger.getLogger( LOGGER_NAME_1 );
Logger logger2 = Logger.getLogger( LOGGER_NAME_2 ); logger2 = Logger.getLogger( LOGGER_NAME_2 );
// check that Level object are returned properly // check that Level object are returned properly
try { try {
...@@ -187,6 +191,7 @@ public class PlatformLoggingMXBeanTest ...@@ -187,6 +191,7 @@ public class PlatformLoggingMXBeanTest
System.out.println( " Set and Check the Logger Level" ); System.out.println( " Set and Check the Logger Level" );
log1 = false; log1 = false;
log2 = false; log2 = false;
try { try {
// Set the level of logger1 to ALL // Set the level of logger1 to ALL
params = new Object[2]; params = new Object[2];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册