8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
authordfuchs
Mon, 11 Jul 2016 11:32:40 +0100
changeset 39566 fb9192e776ba
parent 39565 5ed04f754c31
child 39567 43cbd4fc502b
8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory. Summary: added some instrumentation to the test to help a better diagnosis Reviewed-by: mchung
jdk/test/java/util/logging/CheckLockLocationTest.java
--- a/jdk/test/java/util/logging/CheckLockLocationTest.java	Mon Jul 11 00:24:46 2016 +0300
+++ b/jdk/test/java/util/logging/CheckLockLocationTest.java	Mon Jul 11 11:32:40 2016 +0100
@@ -30,13 +30,16 @@
  * @run  main/othervm CheckLockLocationTest
  */
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 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.UUID;
 import java.util.logging.FileHandler;
 public class CheckLockLocationTest {
 
@@ -78,7 +81,11 @@
         } catch (IOException ex) {
             throw new RuntimeException("Test failed: should have been able"
                     + " to create FileHandler for " + "%t/" + WRITABLE_DIR
-                    + "/log.log in writable directory.", ex);
+                    + "/log.log in writable directory"
+                    + (!writableDir.canRead() // concurrent tests running or user conf issue?
+                        ? ": directory not readable.\n\tPlease check your "
+                         + "environment and machine configuration."
+                        : "."), ex);
         } finally {
             // the above test leaves files in the directory.  Get rid of the
             // files created and the directory
@@ -149,8 +156,41 @@
                     + " writable working directory "
                     + writableDir.getAbsolutePath() );
         }
+
+        if (!writableDir.canRead()) {
+            throw new RuntimeException("Test setup failed: can't read "
+                    + " writable working directory "
+                    + writableDir.getAbsolutePath() );
+        }
+
         // writableDirectory and its contents will be deleted after the test
-        // that uses it
+        // that uses it.
+
+        // check that we can write in the new writable dir.
+        File dummyFile = new File(writableDir, UUID.randomUUID().toString() + ".txt" );
+        try {
+            if (!dummyFile.createNewFile()) {
+                throw new RuntimeException("Test setup failed: can't create "
+                        + " dummy file in writable working directory "
+                        + dummyFile.getAbsolutePath() );
+            }
+            try (OutputStream os = new FileOutputStream(dummyFile)) {
+                os.write('A');
+            } finally {
+                dummyFile.delete();
+            }
+            if (dummyFile.canRead()) {
+                throw new RuntimeException("Test setup failed: can't delete "
+                        + " dummy file in writable working directory "
+                        + dummyFile.getAbsolutePath() );
+            }
+            System.out.println("Successfully created and deleted dummy file: " +
+                dummyFile.getAbsolutePath());
+        } catch(IOException x) {
+            throw new RuntimeException("Test setup failed: can't write "
+                        + " or delete dummy file in writable working directory "
+                        + dummyFile.getAbsolutePath(), x);
+        }
 
         // Create a plain file which we will attempt to use as a directory
         // (%t/not-a-dir)