test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java

Print this page

        

@@ -55,13 +55,35 @@
 
     private static int numPass = 0;
     private static int numFail = 0;
     private static List<String> msgs = new ArrayList<>();
 
+    // This test has been falling in timeout - so we're adding some
+    // time stamp here and there to help diagnose whether it's a 
+    // simple system slowness or whether there's a deeper issue,
+    // like a deadlock. The timeout issue should be fixed now,
+    // but we leave the time stamps in case it reappears.
+    //
+    static final long stamp = System.currentTimeMillis();
+    private static String newDate(long time) {
+        long delta = time - stamp;
+        long min = delta/60000;
+        long sec = (delta - min * 60000) / 10000;
+        long msec = delta - min * 60000 - sec * 1000;
+        return (min == 0 ? "" : (min + " min. ")) + 
+               (sec == 0 ? "" : (sec + " sec. ")) +
+               (msec == 0 ? "" : (msec + "ms.")); 
+    }
+
     public static void main(String[] args) throws Throwable {
+        System.out.println("ResourceBundleSearchTest starting: "+newDate(System.currentTimeMillis()));
         ResourceBundleSearchTest test = new ResourceBundleSearchTest();
+        try {
         test.runTests();
+        } finally {
+            System.out.println("ResourceBundleSearchTest terminated: "+newDate(System.currentTimeMillis()));
+        }
     }
 
     private void runTests() throws Throwable {
         // ensure we are using en as the default Locale so we can find the resource
         Locale.setDefault(Locale.ENGLISH);

@@ -75,19 +97,23 @@
         URL[] urls = new URL[1];
 
         urls[0] = Paths.get(testDir, "resources").toUri().toURL();
         URLClassLoader rbClassLoader = new URLClassLoader(urls);
 
+        int testnb = 1;
+        System.out.println("ResourceBundleSearchTest starting test #"+(testnb++)+": "+newDate(System.currentTimeMillis()));
         // Test 1 - can we find a Logger bundle from doing a stack search?
         // We shouldn't be able to
         assertFalse(testGetBundleFromStackSearch(), "1-testGetBundleFromStackSearch");
 
+        System.out.println("ResourceBundleSearchTest starting test #"+(testnb++)+": "+newDate(System.currentTimeMillis()));
         // Test 2 - can we find a Logger bundle off of the Thread context class
         // loader? We should be able to.
         assertTrue(testGetBundleFromTCCL(TCCL_TEST_BUNDLE, rbClassLoader),
                    "2-testGetBundleFromTCCL");
 
+        System.out.println("ResourceBundleSearchTest starting test #"+(testnb++)+": "+newDate(System.currentTimeMillis()));
         // Test 3 - Can we find a Logger bundle from the classpath?  We should be
         // able to.  We'll first check to make sure the setup is correct and
         // it actually is on the classpath before checking whether logging
         // can see it there.
         if (isOnClassPath(PROP_RB_NAME, myClassLoader)) {

@@ -97,25 +123,29 @@
         } else {
             throw new Exception("TEST SETUP FAILURE: Cannot see " + PROP_RB_NAME
                                  + " on the classpath");
         }
 
+        System.out.println("ResourceBundleSearchTest starting test #"+(testnb++)+": "+newDate(System.currentTimeMillis()));
         // Test 4 - we should be able to find a bundle from the caller's
         // classloader, but only one level up.
         assertTrue(testGetBundleFromCallersClassLoader(),
                    "4-testGetBundleFromCallersClassLoader");
 
+        System.out.println("ResourceBundleSearchTest starting test #"+(testnb++)+": "+newDate(System.currentTimeMillis()));
         // Test 5 - this ensures that getAnonymousLogger(String rbName)
         // can find the bundle from the caller's classloader
         assertTrue(testGetAnonymousLogger(), "5-testGetAnonymousLogger");
 
+        System.out.println("ResourceBundleSearchTest starting test #"+(testnb++)+": "+newDate(System.currentTimeMillis()));
         // Test 6 - first call getLogger("myLogger").
         // Then call getLogger("myLogger","bundleName") from a different ClassLoader
         // Make sure we find the bundle
         assertTrue(testGetBundleFromSecondCallersClassLoader(),
                    "6-testGetBundleFromSecondCallersClassLoader");
 
+        System.out.println("ResourceBundleSearchTest generating report");
         report();
     }
 
     private void report() throws Exception {
         System.out.println("Num passed = " + numPass + " Num failed = " + numFail);

@@ -130,20 +160,22 @@
     }
 
     public void assertTrue(boolean testResult, String testName) {
         if (testResult) {
             numPass++;
+            System.out.println("PASSED: " + testName);
         } else {
             numFail++;
             System.out.println("FAILED: " + testName
                                + " was supposed to return true but did NOT!");
         }
     }
 
     public void assertFalse(boolean testResult, String testName) {
         if (!testResult) {
             numPass++;
+            System.out.println("PASSED: " + testName);
         } else {
             numFail++;
             System.out.println("FAILED: " + testName
                                + " was supposed to return false but did NOT!");
         }

@@ -168,17 +200,15 @@
         // This should succeed.  We should be able to get the bundle from the
         // thread context class loader
         debug("Looking for " + bundleName + " using TCCL");
         LoggingThread lr = new LoggingThread(bundleName, setOnTCCL);
         lr.start();
-        synchronized (lr) {
             try {
-                lr.wait();
+            lr.join();
             } catch (InterruptedException ex) {
                 throw ex;
             }
-        }
         msgs.add(lr.msg);
         return lr.foundBundle;
     }
 
     /*