8160220: (fs) Tests in jdk/test/java/nio/file/WatchService leave directory trees behind

Create temporary files by default in a scratch directory.

Reviewed-by: alanb, chegar
This commit is contained in:
Brian Burkhalter 2016-07-15 17:49:42 -07:00
parent 14d4754bdd
commit eba2a20a2b
2 changed files with 7 additions and 8 deletions

View File

@ -32,6 +32,7 @@ import java.nio.file.FileSystem;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchService; import java.nio.file.WatchService;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -49,7 +50,8 @@ public class DeleteInterference {
* directory. * directory.
*/ */
public static void main(String[] args) throws Exception { 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(); ExecutorService pool = Executors.newCachedThreadPool();
try { try {
Future<?> task1 = pool.submit(() -> openAndCloseWatcher(dir)); Future<?> task1 = pool.submit(() -> openAndCloseWatcher(dir));
@ -58,7 +60,6 @@ public class DeleteInterference {
task2.get(); task2.get();
} finally { } finally {
pool.shutdown(); pool.shutdown();
deleteFileTree(dir);
} }
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * an outstanding I/O operation on directory completes after the
* directory has been closed * directory has been closed
*/ */
import java.nio.file.ClosedWatchServiceException; import java.nio.file.ClosedWatchServiceException;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchKey; import java.nio.file.WatchKey;
import java.nio.file.WatchService; import java.nio.file.WatchService;
import static java.nio.file.StandardWatchEventKinds.*; import static java.nio.file.StandardWatchEventKinds.*;
@ -50,8 +50,8 @@ public class LotsOfCancels {
// one to bash on cancel, the other to poll the events // one to bash on cancel, the other to poll the events
ExecutorService pool = Executors.newCachedThreadPool(); ExecutorService pool = Executors.newCachedThreadPool();
try { try {
Path top = Files.createTempDirectory("LotsOfCancels"); Path testDir = Paths.get(System.getProperty("test.dir", "."));
top.toFile().deleteOnExit(); Path top = Files.createTempDirectory(testDir, "LotsOfCancels");
for (int i=1; i<=16; i++) { for (int i=1; i<=16; i++) {
Path dir = Files.createDirectory(top.resolve("dir-" + i)); Path dir = Files.createDirectory(top.resolve("dir-" + i));
WatchService watcher = FileSystems.getDefault().newWatchService(); WatchService watcher = FileSystems.getDefault().newWatchService();
@ -114,6 +114,4 @@ public class LotsOfCancels {
failed = true; failed = true;
} }
} }
} }