Skip to content

Commit

Permalink
Extracted cleanup method in TestDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Sep 19, 2016
1 parent 65faa24 commit 328f992
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
36 changes: 13 additions & 23 deletions community/io/src/test/java/org/neo4j/test/rule/TestDirectory.java
Expand Up @@ -161,15 +161,14 @@ public File graphDbDir()
return directory( "graph-db" );
}

public File makeGraphDbDir()
public File makeGraphDbDir() throws IOException
{
return cleanDirectory( "graph-db" );
}

public void cleanup() throws IOException
{
fileSystem.deleteRecursively( testClassBaseFolder );
fileSystem.mkdirs( testClassBaseFolder );
clean( fileSystem, testClassBaseFolder );
}

@Override
Expand All @@ -179,14 +178,18 @@ public String toString()
return format( "%s[%s]", getClass().getSimpleName(), testDirectoryName );
}

public File cleanDirectory( String name )
public File cleanDirectory( String name ) throws IOException
{
File dir = new File( ensureBase(), name );
if ( fileSystem.fileExists( dir ) )
return clean( fileSystem, new File( ensureBase(), name ) );
}

private static File clean( FileSystemAbstraction fs, File dir ) throws IOException
{
if ( fs.fileExists( dir ) )
{
deleteSilently( dir );
fs.deleteRecursively( dir );
}
fileSystem.mkdir( dir );
fs.mkdirs( dir );
return dir;
}

Expand All @@ -211,19 +214,7 @@ private void complete( boolean success )
testDirectory = null;
}

private void deleteSilently( File dir )
{
try
{
fileSystem.deleteRecursively( dir );
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}

private File directoryForDescription( Description description )
private File directoryForDescription( Description description ) throws IOException
{
if ( owningTest == null )
{
Expand Down Expand Up @@ -267,8 +258,7 @@ public static File testDataDirectoryOf( FileSystemAbstraction fs, Class<?> ownin
File result = new File( testData, owningTest.getName() ).getAbsoluteFile();
if ( clean )
{
fs.deleteRecursively( result );
fs.mkdirs( result );
clean( fs, result );
}
return result;
}
Expand Down
Expand Up @@ -487,7 +487,6 @@ public void start() throws IOException
dependencies.satisfyDependency( storageEngine.storeReadLayer() );
dependencies.satisfyDependency( logEntryReader );
dependencies.satisfyDependency( storageEngine );
dependencies.satisfyDependency( transactionLogModule.checkPointing() );
satisfyDependencies( kernelModule );
}
catch ( Throwable e )
Expand Down
Expand Up @@ -89,7 +89,7 @@ public void delete() throws IOException
}

@Override
public void create()
public void create() throws IOException
{
dbDir = testDirectory.makeGraphDbDir();
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.test.rule;

import java.io.File;
import java.io.IOException;

import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
Expand Down Expand Up @@ -58,14 +59,14 @@ public NeoStoresRule( Class<?> testClass, StoreType... stores )
this.stores = stores;
}

public NeoStores open( String... config )
public NeoStores open( String... config ) throws IOException
{
Config configuration = new Config( stringMap( config ) );
RecordFormats formats = RecordFormatSelector.selectForConfig( configuration, NullLogProvider.getInstance() );
return open( formats, config );
}

public NeoStores open( RecordFormats format, String... config )
public NeoStores open( RecordFormats format, String... config ) throws IOException
{
efs = new EphemeralFileSystemAbstraction();
Config conf = new Config( stringMap( config ) );
Expand All @@ -74,6 +75,7 @@ public NeoStores open( RecordFormats format, String... config )
}

public NeoStores open( FileSystemAbstraction fs, PageCache pageCache, RecordFormats format, String... config )
throws IOException
{
assert neoStores == null : "Already opened";
TestDirectory testDirectory = TestDirectory.testDirectory( testClass, fs );
Expand Down

0 comments on commit 328f992

Please sign in to comment.