8160220: (fs) Tests in jdk/test/java/nio/file/WatchService leave directory trees behind
authorbpb
Fri, 15 Jul 2016 17:49:42 -0700
changeset 39726 0dbf4284a3f6
parent 39725 9548f8d846e9
child 39727 4c68ece98c47
8160220: (fs) Tests in jdk/test/java/nio/file/WatchService leave directory trees behind Summary: Create temporary files by default in a scratch directory. Reviewed-by: alanb, chegar
jdk/test/java/nio/file/WatchService/DeleteInterference.java
jdk/test/java/nio/file/WatchService/LotsOfCancels.java
--- a/jdk/test/java/nio/file/WatchService/DeleteInterference.java	Fri Jul 15 14:04:09 2016 -0700
+++ b/jdk/test/java/nio/file/WatchService/DeleteInterference.java	Fri Jul 15 17:49:42 2016 -0700
@@ -32,6 +32,7 @@
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.nio.file.WatchService;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -49,7 +50,8 @@
      * directory.
      */
     public static void main(String[] args) throws Exception {
-        Path dir = Files.createTempDirectory("DeleteInterference");
+        Path testDir = Paths.get(System.getProperty("test.dir", "."));
+        Path dir = Files.createTempDirectory(testDir, "DeleteInterference");
         ExecutorService pool = Executors.newCachedThreadPool();
         try {
             Future<?> task1 = pool.submit(() -> openAndCloseWatcher(dir));
@@ -58,7 +60,6 @@
             task2.get();
         } finally {
             pool.shutdown();
-            deleteFileTree(dir);
         }
     }
 
--- a/jdk/test/java/nio/file/WatchService/LotsOfCancels.java	Fri Jul 15 14:04:09 2016 -0700
+++ b/jdk/test/java/nio/file/WatchService/LotsOfCancels.java	Fri Jul 15 17:49:42 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,11 +27,11 @@
  *    an outstanding I/O operation on directory completes after the
  *    directory has been closed
  */
-
 import java.nio.file.ClosedWatchServiceException;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.nio.file.WatchKey;
 import java.nio.file.WatchService;
 import static java.nio.file.StandardWatchEventKinds.*;
@@ -50,8 +50,8 @@
         // one to bash on cancel, the other to poll the events
         ExecutorService pool = Executors.newCachedThreadPool();
         try {
-            Path top = Files.createTempDirectory("LotsOfCancels");
-            top.toFile().deleteOnExit();
+            Path testDir = Paths.get(System.getProperty("test.dir", "."));
+            Path top = Files.createTempDirectory(testDir, "LotsOfCancels");
             for (int i=1; i<=16; i++) {
                 Path dir = Files.createDirectory(top.resolve("dir-" + i));
                 WatchService watcher = FileSystems.getDefault().newWatchService();
@@ -114,6 +114,4 @@
             failed = true;
         }
     }
-
 }
-