use of java.nio.file.AccessDeniedException in project lucene-solr by apache.
the class TestVirusCheckingFS method testDeleteSometimesFails.
/** Test Files.delete fails if a file has an open inputstream against it */
public void testDeleteSometimesFails() throws IOException {
Path dir = wrap(createTempDir());
int counter = 0;
while (true) {
Path path = dir.resolve("file" + counter);
counter++;
OutputStream file = Files.newOutputStream(path);
file.write(5);
file.close();
// File is now closed, we attempt delete:
try {
Files.delete(path);
} catch (AccessDeniedException ade) {
// expected (sometimes)
assertTrue(ade.getMessage().contains("VirusCheckingFS is randomly refusing to delete file "));
break;
}
assertFalse(Files.exists(path));
}
}
Aggregations