Search in sources :

Example 1 with HandleTrackingFS

use of org.apache.lucene.mockfile.HandleTrackingFS in project lucene-solr by apache.

the class TestHandleTrackingFS method testOnOpenThrowsException.

/** Test that the delegate gets closed on exception in HandleTrackingFS#onOpen */
public void testOnOpenThrowsException() throws IOException {
    // we are using LeakFS under the hood if we don't get closed the test fails
    Path path = wrap(createTempDir());
    FileSystem fs = new HandleTrackingFS("test://", path.getFileSystem()) {

        @Override
        protected void onClose(Path path, Object stream) throws IOException {
        }

        @Override
        protected void onOpen(Path path, Object stream) throws IOException {
            throw new IOException("boom");
        }
    }.getFileSystem(URI.create("file:///"));
    Path dir = new FilterPath(path, fs);
    try {
        OutputStream file = Files.newOutputStream(dir.resolve("somefile"));
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    try {
        SeekableByteChannel channel = Files.newByteChannel(dir.resolve("somefile"));
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    try {
        InputStream stream = Files.newInputStream(dir.resolve("somefile"));
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    fs.close();
    try {
        DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir);
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    fs.close();
}
Also used : Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) InputStream(java.io.InputStream) FileSystem(java.nio.file.FileSystem) OutputStream(java.io.OutputStream) Object(java.lang.Object) IOException(java.io.IOException) HandleTrackingFS(org.apache.lucene.mockfile.HandleTrackingFS) Override(java.lang.Override)

Example 2 with HandleTrackingFS

use of org.apache.lucene.mockfile.HandleTrackingFS in project lucene-solr by apache.

the class TestHandleTrackingFS method testOnCloseThrowsException.

/** Test that the delegate gets closed on exception in HandleTrackingFS#onClose */
public void testOnCloseThrowsException() throws IOException {
    // we are using LeakFS under the hood if we don't get closed the test fails
    Path path = wrap(createTempDir());
    FileSystem fs = new HandleTrackingFS("test://", path.getFileSystem()) {

        @Override
        protected void onClose(Path path, Object stream) throws IOException {
            throw new IOException("boom");
        }

        @Override
        protected void onOpen(Path path, Object stream) throws IOException {
        //
        }
    }.getFileSystem(URI.create("file:///"));
    Path dir = new FilterPath(path, fs);
    OutputStream file = Files.newOutputStream(dir.resolve("somefile"));
    file.write(5);
    try {
        file.close();
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    SeekableByteChannel channel = Files.newByteChannel(dir.resolve("somefile"));
    try {
        channel.close();
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    InputStream stream = Files.newInputStream(dir.resolve("somefile"));
    try {
        stream.close();
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
    fs.close();
    DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir);
    try {
        dirStream.close();
        fail("expected IOException");
    } catch (IOException ex) {
    // expected
    }
}
Also used : Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) InputStream(java.io.InputStream) FileSystem(java.nio.file.FileSystem) OutputStream(java.io.OutputStream) Object(java.lang.Object) IOException(java.io.IOException) HandleTrackingFS(org.apache.lucene.mockfile.HandleTrackingFS) Override(java.lang.Override)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Object (java.lang.Object)2 Override (java.lang.Override)2 SeekableByteChannel (java.nio.channels.SeekableByteChannel)2 FileSystem (java.nio.file.FileSystem)2 Path (java.nio.file.Path)2 HandleTrackingFS (org.apache.lucene.mockfile.HandleTrackingFS)2