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" );
Files.write( inputFile.toPath(), lines, Charset.defaultCharset() );

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

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

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 ) ) )
.thenReturn( mock( Importer.class ) );

ImportCommand importCommand =
new ImportCommand( homeDir.toPath(), testDir.directory( "conf" ).toPath(), new RealOutsideWorld(),
mockImporterFactory );
try ( RealOutsideWorld outsideWorld = new RealOutsideWorld() )
{
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 )
.getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) );
verify( mockImporterFactory ).getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ),
any( OutsideWorld.class ) );
}
}

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

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

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

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

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

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

@Test
public void failIfDestinationDatabaseAlreadyExists() throws Exception
{
Path homeDir = testDir.directory( "home" ).toPath();
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 )
try ( NullOutsideWorld outsideWorld = new NullOutsideWorld() )
{
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
public TestDirectory testDirectory = TestDirectory.testDirectory( getClass());

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

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

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

@After
public void teardown() throws Exception
public void tearDown() throws Exception
{
pageCache.close();
fs.close();
Expand Down
Expand Up @@ -41,7 +41,6 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
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 )
.around( fileSystemRule ).around( pageCacheRule );

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

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

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

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

import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
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.RateLimitedAuthenticationStrategy;
import org.neo4j.server.security.auth.UserRepository;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;
import org.neo4j.time.Clocks;

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

@Rule
public EphemeralFileSystemRule fsRule = new EphemeralFileSystemRule();

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

0 comments on commit d857f73

Please sign in to comment.