Skip to content

Commit

Permalink
Additional cleanup and closing FS's
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Nov 21, 2016
1 parent 595b2b2 commit d857f73
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 61 deletions.
Expand Up @@ -52,12 +52,14 @@ public void writesReportToSpecifiedReportFile() throws Exception
List<String> lines = Arrays.asList( "foo,bar,baz" ); List<String> lines = Arrays.asList( "foo,bar,baz" );
Files.write( inputFile.toPath(), lines, Charset.defaultCharset() ); Files.write( inputFile.toPath(), lines, Charset.defaultCharset() );


CsvImporter csvImporter = new CsvImporter( try ( RealOutsideWorld outsideWorld = new RealOutsideWorld() )
Args.parse( String.format( "--report-file=%s", reportLocation.getAbsolutePath() ), {
String.format( "--nodes=%s", inputFile.getAbsolutePath() ) ), Config.defaults(), CsvImporter csvImporter = new CsvImporter(
new RealOutsideWorld() ); Args.parse( String.format( "--report-file=%s", reportLocation.getAbsolutePath() ),

String.format( "--nodes=%s", inputFile.getAbsolutePath() ) ), Config.defaults(),
csvImporter.doImport(); outsideWorld );
csvImporter.doImport();
}


assertTrue( reportLocation.exists() ); assertTrue( reportLocation.exists() );
} }
Expand Down
Expand Up @@ -65,73 +65,84 @@ public void defaultsToCsvWhenModeNotSpecified() throws Exception
.getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) ) ) .getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) ) )
.thenReturn( mock( Importer.class ) ); .thenReturn( mock( Importer.class ) );


ImportCommand importCommand = try ( RealOutsideWorld outsideWorld = new RealOutsideWorld() )
new ImportCommand( homeDir.toPath(), testDir.directory( "conf" ).toPath(), new RealOutsideWorld(), {
mockImporterFactory ); ImportCommand importCommand =
new ImportCommand( homeDir.toPath(), testDir.directory( "conf" ).toPath(), outsideWorld,
mockImporterFactory );


String[] arguments = {"--database=foo", "--from=bar"}; String[] arguments = {"--database=foo", "--from=bar"};


importCommand.execute( arguments ); importCommand.execute( arguments );


verify( mockImporterFactory ) verify( mockImporterFactory ).getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ),
.getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) ); any( OutsideWorld.class ) );
}
} }


@Test @Test
public void requiresDatabaseArgument() throws Exception public void requiresDatabaseArgument() throws Exception
{ {
ImportCommand importCommand = try ( NullOutsideWorld outsideWorld = new NullOutsideWorld() )
new ImportCommand( testDir.directory( "home" ).toPath(), testDir.directory( "conf" ).toPath(),
new NullOutsideWorld() );

String[] arguments = {"--mode=database", "--from=bar"};
try
{ {
importCommand.execute( arguments ); ImportCommand importCommand =
fail( "Should have thrown an exception." ); new ImportCommand( testDir.directory( "home" ).toPath(), testDir.directory( "conf" ).toPath(),
} outsideWorld );
catch ( IncorrectUsage e )
{ String[] arguments = {"--mode=database", "--from=bar"};
assertThat( e.getMessage(), containsString( "database" ) ); try
{
importCommand.execute( arguments );
fail( "Should have thrown an exception." );
}
catch ( IncorrectUsage e )
{
assertThat( e.getMessage(), containsString( "database" ) );
}
} }
} }


@Test @Test
public void failIfInvalidModeSpecified() throws Exception public void failIfInvalidModeSpecified() throws Exception
{ {
ImportCommand importCommand = try ( NullOutsideWorld outsideWorld = new NullOutsideWorld() )
new ImportCommand( testDir.directory( "home" ).toPath(), testDir.directory( "conf" ).toPath(),
new NullOutsideWorld() );

String[] arguments = {"--mode=foo", "--database=bar", "--from=baz"};
try
{ {
importCommand.execute( arguments ); ImportCommand importCommand =
fail( "Should have thrown an exception." ); new ImportCommand( testDir.directory( "home" ).toPath(), testDir.directory( "conf" ).toPath(),
} outsideWorld );
catch ( IncorrectUsage e )
{ String[] arguments = {"--mode=foo", "--database=bar", "--from=baz"};
assertThat( e.getMessage(), containsString( "foo" ) ); try
{
importCommand.execute( arguments );
fail( "Should have thrown an exception." );
}
catch ( IncorrectUsage e )
{
assertThat( e.getMessage(), containsString( "foo" ) );
}
} }
} }


@Test @Test
public void failIfDestinationDatabaseAlreadyExists() throws Exception public void failIfDestinationDatabaseAlreadyExists() throws Exception
{ {
Path homeDir = testDir.directory( "home" ).toPath(); try ( NullOutsideWorld outsideWorld = new NullOutsideWorld() )
ImportCommand importCommand =
new ImportCommand( homeDir, testDir.directory( "conf" ).toPath(), new NullOutsideWorld() );

putStoreInDirectory( homeDir.resolve( "data" ).resolve( "databases" ).resolve( "existing.db" ) );
String[] arguments = {"--mode=csv", "--database=existing.db"};
try
{
importCommand.execute( arguments );
fail( "Should have thrown an exception." );
}
catch ( Exception e )
{ {
assertThat( e.getMessage(), containsString( "already contains a database" ) ); Path homeDir = testDir.directory( "home" ).toPath();
ImportCommand importCommand = new ImportCommand( homeDir, testDir.directory( "conf" ).toPath(), outsideWorld );

putStoreInDirectory( homeDir.resolve( "data" ).resolve( "databases" ).resolve( "existing.db" ) );
String[] arguments = {"--mode=csv", "--database=existing.db"};
try
{
importCommand.execute( arguments );
fail( "Should have thrown an exception." );
}
catch ( Exception e )
{
assertThat( e.getMessage(), containsString( "already contains a database" ) );
}
} }
} }


Expand Down
Expand Up @@ -46,10 +46,8 @@ public class BackupToolIT
{ {
@Rule @Rule
public TestDirectory testDirectory = TestDirectory.testDirectory( getClass()); public TestDirectory testDirectory = TestDirectory.testDirectory( getClass());

@Rule @Rule
public ExpectedException expected = ExpectedException.none(); public ExpectedException expected = ExpectedException.none();

@Rule @Rule
public EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ).startLazily(); public EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ).startLazily();


Expand All @@ -68,7 +66,7 @@ public void setUp() throws Exception
} }


@After @After
public void teardown() throws Exception public void tearDown() throws Exception
{ {
pageCache.close(); pageCache.close();
fs.close(); fs.close();
Expand Down
Expand Up @@ -41,7 +41,6 @@
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory; import org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory; import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory;
Expand Down Expand Up @@ -94,8 +93,8 @@ public class StoreMigratorFrom20IT
public RuleChain ruleChain = RuleChain.outerRule( storeDir ) public RuleChain ruleChain = RuleChain.outerRule( storeDir )
.around( fileSystemRule ).around( pageCacheRule ); .around( fileSystemRule ).around( pageCacheRule );


private final FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
private final ListAccumulatorMigrationProgressMonitor monitor = new ListAccumulatorMigrationProgressMonitor(); private final ListAccumulatorMigrationProgressMonitor monitor = new ListAccumulatorMigrationProgressMonitor();
private FileSystemAbstraction fs;
private PageCache pageCache; private PageCache pageCache;
private final LifeSupport life = new LifeSupport(); private final LifeSupport life = new LifeSupport();
private UpgradableDatabase upgradableDatabase; private UpgradableDatabase upgradableDatabase;
Expand All @@ -118,6 +117,7 @@ public static List<Object[]> recordFormats()
@Before @Before
public void setUp() public void setUp()
{ {
fs = fileSystemRule.get();
pageCache = pageCacheRule.getPageCache( fs ); pageCache = pageCacheRule.getPageCache( fs );


schemaIndexProvider = new LuceneSchemaIndexProvider( fs, DirectoryFactory.PERSISTENT, storeDir.directory(), schemaIndexProvider = new LuceneSchemaIndexProvider( fs, DirectoryFactory.PERSISTENT, storeDir.directory(),
Expand Down
Expand Up @@ -21,7 +21,6 @@


import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import java.io.CharArrayReader; import java.io.CharArrayReader;
Expand All @@ -34,6 +33,7 @@
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;


import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction; import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.util.Neo4jJobScheduler; import org.neo4j.kernel.impl.util.Neo4jJobScheduler;
Expand All @@ -46,7 +46,6 @@
import org.neo4j.server.security.auth.PasswordPolicy; import org.neo4j.server.security.auth.PasswordPolicy;
import org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy; import org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy;
import org.neo4j.server.security.auth.UserRepository; import org.neo4j.server.security.auth.UserRepository;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;
import org.neo4j.time.Clocks; import org.neo4j.time.Clocks;


import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -59,9 +58,6 @@ public class InternalFlatFileRealmIT
File userStoreFile; File userStoreFile;
File roleStoreFile; File roleStoreFile;


@Rule
public EphemeralFileSystemRule fsRule = new EphemeralFileSystemRule();

TestJobScheduler jobScheduler = new TestJobScheduler(); TestJobScheduler jobScheduler = new TestJobScheduler();
LogProvider logProvider = NullLogProvider.getInstance(); LogProvider logProvider = NullLogProvider.getInstance();
InternalFlatFileRealm realm; InternalFlatFileRealm realm;
Expand All @@ -72,7 +68,7 @@ public class InternalFlatFileRealmIT
@Before @Before
public void setup() throws Throwable public void setup() throws Throwable
{ {
fs = new EvilFileSystem( fsRule.get() ); fs = new EvilFileSystem( new EphemeralFileSystemAbstraction() );
userStoreFile = new File( "dbms", "auth" ); userStoreFile = new File( "dbms", "auth" );
roleStoreFile = new File( "dbms", "roles" ); roleStoreFile = new File( "dbms", "roles" );
final UserRepository userRepository = new FileUserRepository( fs, userStoreFile, logProvider ); final UserRepository userRepository = new FileUserRepository( fs, userStoreFile, logProvider );
Expand Down

0 comments on commit d857f73

Please sign in to comment.