Search in sources :

Example 16 with AccessDeniedException

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));
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) OutputStream(java.io.OutputStream)

Aggregations

AccessDeniedException (java.nio.file.AccessDeniedException)16 Test (org.junit.Test)6 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)5 IOException (java.io.IOException)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 Path (java.nio.file.Path)4 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)3 FileSystemException (java.nio.file.FileSystemException)3 FileSystemLoopException (java.nio.file.FileSystemLoopException)3 NotDirectoryException (java.nio.file.NotDirectoryException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Closeable (java.io.Closeable)2 Configuration (org.apache.hadoop.conf.Configuration)2 Path (org.apache.hadoop.fs.Path)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2