changeset 8865:059530c5ae9a

8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10 Summary: this test has been seen failing on Solaris 10, presumably because it was run as root. The fix will skip the non-writable case if it can't make a non-writable dir. Reviewed-by: mchung
author dfuchs
date Tue, 19 Nov 2013 22:28:12 +0100
parents f496565c4eec
children 19d2e9649138 93826827e8b4
files test/java/util/logging/CheckLockLocationTest.java
diffstat 1 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/util/logging/CheckLockLocationTest.java	Tue Nov 19 13:22:50 2013 -0800
+++ b/test/java/util/logging/CheckLockLocationTest.java	Tue Nov 19 22:28:12 2013 +0100
@@ -33,7 +33,10 @@
 import java.io.IOException;
 import java.nio.file.AccessDeniedException;
 import java.nio.file.FileSystemException;
+import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.attribute.UserPrincipal;
 import java.util.logging.FileHandler;
 public class CheckLockLocationTest {
 
@@ -169,14 +172,19 @@
         nonWritableDir.deleteOnExit();
 
         // make it non-writable
-        if (nonWritableDir.setWritable(false)) {
+        Path path = nonWritableDir.toPath();
+        final boolean nonWritable = nonWritableDir.setWritable(false);
+        final boolean isWritable = Files.isWritable(path);
+        if (nonWritable && !isWritable) {
             runNonWritableDirTest = true;
+            System.out.println("Created non writable dir for "
+                    + getOwner(path) + " at: " + path.toString());
         } else {
             runNonWritableDirTest = false;
             System.out.println( "Test Setup WARNING: unable to make"
                     + " working directory " + nonWritableDir.getAbsolutePath()
-                    + " non-writable on platform " + System.getProperty("os.name"));
-
+                    + "\n\t non-writable for " + getOwner(path)
+                    +  " on platform " + System.getProperty("os.name"));
         }
 
         // make sure non-existent directory really doesn't exist
@@ -184,9 +192,21 @@
         if (nonExistentDir.exists()) {
             nonExistentDir.delete();
         }
+        System.out.println("Setup completed - writableDir is: " + writableDir.getPath());
         return writableDir;
     }
 
+    private static String getOwner(Path path) {
+        UserPrincipal user = null;
+        try {
+            user = Files.getOwner(path);
+        } catch (Exception x) {
+            System.err.println("Failed to get owner of: " + path);
+            System.err.println("\terror is: " + x);
+        }
+        return user == null ? "???" : user.getName();
+    }
+
     /**
      * @param newFile
      * @return true if file already exists or creation succeeded