changeset 6223:7004848974a2

8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win] Reviewed-by: alanb
author jgish
date Tue, 04 Dec 2012 20:21:19 +0000
parents 2e8863c4f7d0
children 44ae777564eb
files test/ProblemList.txt test/java/util/logging/CheckLockLocationTest.java
diffstat 2 files changed, 33 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/test/ProblemList.txt	Tue Dec 04 15:10:03 2012 +0000
+++ b/test/ProblemList.txt	Tue Dec 04 20:21:19 2012 +0000
@@ -363,9 +363,6 @@
 # Filed 6772009
 java/util/concurrent/locks/ReentrantLock/CancelledLockLoops.java generic-all
 
-# 8003596
-java/util/logging/CheckLockLocationTest.java			windows-all
-
 # 7041639, Solaris DSA keypair generation bug
 java/util/TimeZone/TimeZoneDatePermissionCheck.sh               solaris-all
 
--- a/test/java/util/logging/CheckLockLocationTest.java	Tue Dec 04 15:10:03 2012 +0000
+++ b/test/java/util/logging/CheckLockLocationTest.java	Tue Dec 04 20:21:19 2012 +0000
@@ -42,17 +42,22 @@
     private static final String NOT_A_DIR = "not-a-dir";
     private static final String WRITABLE_DIR = "writable-dir";
     private static final String NON_EXISTENT_DIR = "non-existent-dir";
+    private static boolean runNonWritableDirTest;
 
     public static void main(String... args) throws IOException {
         // we'll base all file creation attempts on the system temp directory,
         // %t and also try specifying non-existent directories and plain files
         // that should be directories, and non-writable directories,
         // to exercise all code paths of checking the lock location
+        // Note that on platforms like Windows that don't support
+        // setWritable() on a directory, we'll skip the non-writable
+        // directory test if setWritable(false) returns false.
+        //
         File writableDir = setup();
         // we now have three files/directories to work with:
         //    writableDir
         //    notAdir
-        //    nonWritableDir
+        //    nonWritableDir (may not be possible on some platforms)
         //    nonExistentDir (which doesn't exist)
         runTests(writableDir);
     }
@@ -79,15 +84,19 @@
         }
 
         // Test 2: creating FileHandler in non-writable directory should fail
-        try {
-            new FileHandler("%t/" + NON_WRITABLE_DIR + "/log.log");
-            throw new RuntimeException("Test failed: should not have been able"
-                    + " to create FileHandler for " + "%t/" + NON_WRITABLE_DIR
-                    + "/log.log in non-writable directory.");
-        } catch (IOException ex) {
-            // check for the right exception
-            if (!(ex instanceof AccessDeniedException)) {
-                throw new RuntimeException("Test failed: Expected exception was not an AccessDeniedException", ex);
+        if (runNonWritableDirTest) {
+            try {
+                new FileHandler("%t/" + NON_WRITABLE_DIR + "/log.log");
+                throw new RuntimeException("Test failed: should not have been able"
+                        + " to create FileHandler for " + "%t/" + NON_WRITABLE_DIR
+                        + "/log.log in non-writable directory.");
+            } catch (IOException ex) {
+                // check for the right exception
+                if (!(ex instanceof AccessDeniedException)) {
+                    throw new RuntimeException(
+                        "Test failed: Expected exception was not an "
+                                + "AccessDeniedException", ex);
+                }
             }
         }
 
@@ -99,8 +108,11 @@
                     + "/log.log in non-directory.");
         } catch (IOException ex) {
             // check for the right exception
-            if (!(ex instanceof FileSystemException && ex.getMessage().contains("Not a directory"))) {
-                throw new RuntimeException("Test failed: Expected exception was not a FileSystemException", ex);
+            if (!(ex instanceof FileSystemException
+                    && ex.getMessage().contains("Not a directory"))) {
+                throw new RuntimeException(
+                        "Test failed: Expected exception was not a "
+                        + "FileSystemException", ex);
             }
         }
 
@@ -113,7 +125,8 @@
         } catch (IOException ex) {
             // check for the right exception
             if (!(ex instanceof NoSuchFileException)) {
-                throw new RuntimeException("Test failed: Expected exception was not a NoSuchFileException", ex);
+                throw new RuntimeException("Test failed: Expected exception "
+                        + "was not a NoSuchFileException", ex);
             }
         }
     }
@@ -162,10 +175,14 @@
         nonWritableDir.deleteOnExit();
 
         // make it non-writable
-        if (!nonWritableDir.setWritable(false)) {
-            throw new RuntimeException("Test setup failed: unable to make"
+        if (nonWritableDir.setWritable(false)) {
+            runNonWritableDirTest = true;
+        } else {
+            runNonWritableDirTest = false;
+            System.out.println( "Test Setup WARNING: unable to make"
                     + " working directory " + nonWritableDir.getAbsolutePath()
-                    + " non-writable.");
+                    + " non-writable on platform " + System.getProperty("os.name"));
+
         }
 
         // make sure non-existent directory really doesn't exist