From 7d661576443f37dec2511ffcd7aa482e868a6dd6 Mon Sep 17 00:00:00 2001 From: mchung Date: Thu, 17 Nov 2011 15:47:34 -0800 Subject: [PATCH] 7067691: java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java failing intermittently Reviewed-by: alanb, mchung Contributed-by: gary.adams@oracle.com --- .../LoggingMXBeanTest.java | 21 ++++++++++++++----- .../PlatformLoggingMXBeanTest.java | 13 ++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/jdk/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java b/jdk/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java index 17569b4cec..26b3b66153 100644 --- a/jdk/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java +++ b/jdk/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 7024172 + * @bug 7024172 7067691 * @summary Test if proxy for PlatformLoggingMXBean is equivalent * to proxy for LoggingMXBean * @@ -43,6 +43,13 @@ public class LoggingMXBeanTest static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2"; 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 { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); LoggingMXBean proxy = @@ -51,7 +58,7 @@ public class LoggingMXBeanTest LoggingMXBean.class); // test LoggingMXBean proxy - LoggingMXBeanTest p = new LoggingMXBeanTest(proxy); + test = new LoggingMXBeanTest(proxy); // check if the attributes implemented by PlatformLoggingMXBean // and LoggingMXBean return the same value @@ -64,9 +71,9 @@ public class LoggingMXBeanTest // same verification as in java/util/logging/LoggingMXBeanTest2 public LoggingMXBeanTest(LoggingMXBean mbean) throws Exception { - Logger logger1 = Logger.getLogger( LOGGER_NAME_1 ); + logger1 = Logger.getLogger( LOGGER_NAME_1 ); logger1.setLevel(Level.FINE); - Logger logger2 = Logger.getLogger( LOGGER_NAME_2 ); + logger2 = Logger.getLogger( LOGGER_NAME_2 ); logger2.setLevel(null); /* @@ -207,6 +214,7 @@ public class LoggingMXBeanTest // verify logger names List loggers1 = mxbean1.getLoggerNames(); List loggers2 = mxbean2.getLoggerNames(); + if (loggers1.size() != loggers2.size()) throw new RuntimeException("LoggerNames: unmatched number of entries"); List loggers3 = new ArrayList<>(loggers1); @@ -219,7 +227,10 @@ public class LoggingMXBeanTest if (!mxbean1.getLoggerLevel(logger) .equals(mxbean2.getLoggerLevel(logger))) throw new RuntimeException( - "LoggerLevel: unmatched level for " + logger); + "LoggerLevel: unmatched level for " + logger + + ", " + mxbean1.getLoggerLevel(logger) + + ", " + mxbean2.getLoggerLevel(logger)); + if (!mxbean1.getParentLoggerName(logger) .equals(mxbean2.getParentLoggerName(logger))) throw new RuntimeException( diff --git a/jdk/test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java b/jdk/test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java index 3694641351..9d13b954c1 100644 --- a/jdk/test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java +++ b/jdk/test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 6876135 7024172 + * @bug 6876135 7024172 7067691 * * @summary Test PlatformLoggingMXBean * This test performs similar testing as @@ -41,11 +41,15 @@ import java.util.List; public class PlatformLoggingMXBeanTest { - ObjectName objectName = null; static String LOGGER_NAME_1 = "com.sun.management.Logger1"; 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 { } @@ -135,8 +139,8 @@ public class PlatformLoggingMXBeanTest System.out.println( "*********** Phase 3 ***********" ); System.out.println( "*******************************" ); System.out.println( " Create and test new Loggers" ); - Logger logger1 = Logger.getLogger( LOGGER_NAME_1 ); - Logger logger2 = Logger.getLogger( LOGGER_NAME_2 ); + logger1 = Logger.getLogger( LOGGER_NAME_1 ); + logger2 = Logger.getLogger( LOGGER_NAME_2 ); // check that Level object are returned properly try { @@ -187,6 +191,7 @@ public class PlatformLoggingMXBeanTest System.out.println( " Set and Check the Logger Level" ); log1 = false; log2 = false; + try { // Set the level of logger1 to ALL params = new Object[2]; -- GitLab