changeset 6508:118f39596581

7067691: java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java failing intermittently Reviewed-by: alanb, mchung Contributed-by: gary.adams@oracle.com
author mchung
date Thu, 17 Nov 2011 15:47:34 -0800
parents b86ef75b0b34
children 5519825327a7
files test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java
diffstat 2 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java	Fri Jul 26 13:17:15 2013 +0100
+++ b/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java	Thu Nov 17 15:47:34 2011 -0800
@@ -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 @@
     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 @@
                 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 @@
     // 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 @@
         // verify logger names
         List<String> loggers1 = mxbean1.getLoggerNames();
         List<String> loggers2 = mxbean2.getLoggerNames();
+
         if (loggers1.size() != loggers2.size())
             throw new RuntimeException("LoggerNames: unmatched number of entries");
         List<String> loggers3 = new ArrayList<>(loggers1);
@@ -219,7 +227,10 @@
             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(
--- a/test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java	Fri Jul 26 13:17:15 2013 +0100
+++ b/test/java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java	Thu Nov 17 15:47:34 2011 -0800
@@ -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 @@
 
 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 @@
         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 @@
         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];