6961408: test/java/util/logging/ParentLoggersTest.java fails in samevm mode
authormchung
Wed, 16 Jun 2010 23:27:41 -0700
changeset 5803 c3ddaebe216b
parent 5802 ea99d72d3c19
child 5804 faf9bd47d6ce
6961408: test/java/util/logging/ParentLoggersTest.java fails in samevm mode Summary: Check against the list of loggers added since the test begins to run Reviewed-by: dcubed
jdk/test/ProblemList.txt
jdk/test/java/util/logging/ParentLoggersTest.java
--- a/jdk/test/ProblemList.txt	Thu Jun 17 13:46:15 2010 +0800
+++ b/jdk/test/ProblemList.txt	Wed Jun 16 23:27:41 2010 -0700
@@ -1206,16 +1206,6 @@
 java/util/Locale/LocaleTest.java				generic-all
 
 # Need to be marked othervm, or changed to be samevm safe
-java/util/logging/GetGlobalTest.java				generic-all
-java/util/logging/LoggerSubclass.java				generic-all
-java/util/logging/LoggingDeadlock.java				generic-all
-java/util/logging/LoggingDeadlock2.java 			generic-all
-java/util/logging/LoggingMXBeanTest.java			generic-all
-java/util/logging/LoggingMXBeanTest2.java			generic-all
-java/util/logging/LoggingNIOChange.java 			generic-all
-java/util/logging/ParentLoggersTest.java			generic-all
-
-# Need to be marked othervm, or changed to be samevm safe
 java/util/WeakHashMap/GCDuringIteration.java			generic-all
 
 # Possible missing input stream close()? Causes samevm issues on windows
--- a/jdk/test/java/util/logging/ParentLoggersTest.java	Thu Jun 17 13:46:15 2010 +0800
+++ b/jdk/test/java/util/logging/ParentLoggersTest.java	Wed Jun 16 23:27:41 2010 -0700
@@ -40,7 +40,19 @@
     static final String LOGGER_NAME_1   = PARENT_NAME_1 + ".myLogger";
     static final String LOGGER_NAME_2   = PARENT_NAME_2 + ".myBar.myLogger";
 
+    static final List<String> initialLoggerNames = new ArrayList<String>();
     public static void main(String args[]) throws Exception {
+        // cache the initial set of loggers before this test begins
+        // to add any loggers
+        Enumeration<String> e = logMgr.getLoggerNames();
+        List<String> defaultLoggers = getDefaultLoggerNames();
+        while (e.hasMoreElements()) {
+            String logger = e.nextElement();
+            if (!defaultLoggers.contains(logger)) {
+                initialLoggerNames.add(logger);
+            }
+        };
+
         String tstSrc = System.getProperty(TST_SRC_PROP);
         File   fname  = new File(tstSrc, LM_PROP_FNAME);
         String prop   = fname.getCanonicalPath();
@@ -56,12 +68,12 @@
         }
     }
 
-    public static Vector getDefaultLoggerNames() {
-        Vector expectedLoggerNames = new Vector(0);
+    public static List<String> getDefaultLoggerNames() {
+        List<String> expectedLoggerNames = new ArrayList<String>();
 
         // LogManager always creates two loggers:
-        expectedLoggerNames.addElement("");       // root   logger: ""
-        expectedLoggerNames.addElement("global"); // global logger: "global"
+        expectedLoggerNames.add("");       // root   logger: ""
+        expectedLoggerNames.add("global"); // global logger: "global"
         return expectedLoggerNames;
     }
 
@@ -71,7 +83,7 @@
      */
     public static boolean checkLoggers() {
         String failMsg = "# checkLoggers: getLoggerNames() returned unexpected loggers";
-        Vector expectedLoggerNames = getDefaultLoggerNames();
+        Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames());
 
         // Create the logger LOGGER_NAME_1
         Logger logger1 = Logger.getLogger(LOGGER_NAME_1);
@@ -83,18 +95,23 @@
         expectedLoggerNames.addElement(PARENT_NAME_2);
         expectedLoggerNames.addElement(LOGGER_NAME_2);
 
-        Enumeration returnedLoggersEnum = logMgr.getLoggerNames();
-        Vector      returnedLoggerNames = new Vector(0);
+        Enumeration<String> returnedLoggersEnum = logMgr.getLoggerNames();
+        Vector<String>      returnedLoggerNames = new Vector<String>(0);
         while (returnedLoggersEnum.hasMoreElements()) {
-            returnedLoggerNames.addElement(returnedLoggersEnum.nextElement());
+           String logger = returnedLoggersEnum.nextElement();
+            if (!initialLoggerNames.contains(logger)) {
+                // filter out the loggers that have been added before this test runs
+                returnedLoggerNames.addElement(logger);
+            }
+
         };
 
         return checkNames(expectedLoggerNames, returnedLoggerNames, failMsg);
     }
 
     // Returns boolean values: PASSED or FAILED
-    private static boolean checkNames(Vector expNames,
-                                      Vector retNames,
+    private static boolean checkNames(Vector<String> expNames,
+                                      Vector<String> retNames,
                                       String failMsg) {
         boolean status = PASSED;
 
@@ -123,8 +140,8 @@
         return status;
     }
 
-    private static void printFailMsg(Vector expNames,
-                                     Vector retNames,
+    private static void printFailMsg(Vector<String> expNames,
+                                     Vector<String> retNames,
                                      String failMsg) {
         out.println();
         out.println(failMsg);