Skip to content

Commit

Permalink
Update FileSystemAbstraction to extend Closeable and throw IOExceptio…
Browse files Browse the repository at this point in the history
…n on close.
  • Loading branch information
MishaDemianenko committed Nov 21, 2016
1 parent 316c20c commit 17867b4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
Expand Up @@ -217,7 +217,7 @@ protected StoreFileChannel getStoreFileChannel( FileChannel channel )
}

@Override
public void close() throws Exception
public void close() throws IOException
{
IOUtils.closeAll( thirdPartyFileSystems.values() );
}
Expand Down
Expand Up @@ -54,6 +54,7 @@
public class DelegateFileSystemAbstraction implements FileSystemAbstraction
{
private final FileSystem fs;
private final Map<Class<?>, ThirdPartyFileSystem> thirdPartyFs = new HashMap<>();

public DelegateFileSystemAbstraction( FileSystem fs )
{
Expand Down Expand Up @@ -253,8 +254,6 @@ private void copyRecursively( Path source, Path target ) throws IOException
}
}

private final Map<Class<?>, ThirdPartyFileSystem> thirdPartyFs = new HashMap<>();

@Override
public synchronized <K extends ThirdPartyFileSystem> K getOrCreateThirdPartyFileSystem(
Class<K> clazz, Function<Class<K>,K> creator )
Expand Down Expand Up @@ -291,10 +290,11 @@ public void deleteFileOrThrow( File file ) throws IOException
}

@Override
public void close() throws Exception
public void close() throws IOException
{
ArrayList<Closeable> fsToClose = new ArrayList<>( thirdPartyFs.values() );
ArrayList<Closeable> fsToClose = new ArrayList<>( thirdPartyFs.size() + 1 );
fsToClose.add( fs );
fsToClose.addAll( thirdPartyFs.values() );
IOUtils.closeAll( fsToClose );
}
}
Expand Up @@ -32,7 +32,7 @@
import java.util.function.Function;
import java.util.zip.ZipOutputStream;

public interface FileSystemAbstraction extends AutoCloseable
public interface FileSystemAbstraction extends Closeable
{
StoreChannel open( File fileName, String mode ) throws IOException;

Expand Down
Expand Up @@ -239,7 +239,7 @@ public Object invoke( Object proxy, Method method, Object[] args ) throws Throwa
}

@Override
public void close() throws Exception
public void close() throws IOException
{
adversary.injectFailure( IOException.class, SecurityException.class );
delegate.close();
Expand Down
Expand Up @@ -182,7 +182,7 @@ public void copyRecursively( File fromDirectory, File toDirectory ) throws IOExc
}

@Override
public void close() throws Exception
public void close() throws IOException
{
delegate.close();
}
Expand Down
Expand Up @@ -137,16 +137,25 @@ public void crash()
}

@Override
public synchronized void close() throws Exception
public synchronized void close() throws IOException
{
closeFiles();
closeFileSystems();
}

private void closeFileSystems() throws IOException
{
IOUtils.closeAll( thirdPartyFileSystems.values() );
thirdPartyFileSystems.clear();
}

private void closeFiles()
{
for ( EphemeralFileData file : files.values() )
{
file.free();
}
files.clear();

IOUtils.closeAll( thirdPartyFileSystems.values() );
thirdPartyFileSystems.clear();
}

public void assertNoOpenFiles() throws Exception
Expand Down
Expand Up @@ -199,7 +199,7 @@ private FileSystemAbstraction chooseFileSystem( File file )
}

@Override
public void close() throws Exception
public void close() throws IOException
{
IOUtils.closeAll( specialFileSystem, defaultFileSystem );
}
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.graphdb.mockfs;

import java.io.IOException;

import org.neo4j.io.fs.FileSystemAbstraction;

/**
Expand All @@ -33,7 +35,7 @@ public UncloseableDelegatingFileSystemAbstraction( FileSystemAbstraction delegat
}

@Override
public void close() throws Exception
public void close() throws IOException
{
// do nothing
}
Expand Down
Expand Up @@ -276,7 +276,7 @@ public void deleteFileOrThrow( File file ) throws IOException
}

@Override
public void close() throws Exception
public void close() throws IOException
{
fs.close();
}
Expand Down

0 comments on commit 17867b4

Please sign in to comment.