Skip to content

Commit

Permalink
Rename methods that expose database directory and not a store dir
Browse files Browse the repository at this point in the history
to represent that. Clean some related tests.
  • Loading branch information
MishaDemianenko committed Jul 23, 2018
1 parent 3e2bee0 commit 4c19eb7
Show file tree
Hide file tree
Showing 47 changed files with 134 additions and 692 deletions.
Expand Up @@ -102,10 +102,10 @@ public void reportNotCleanNativeIndex() throws IOException, ConsistencyCheckInco
@Test
public void reportNotCleanNativeIndexWithCorrectData() throws IOException, ConsistencyCheckIncompleteException
{
File storeDir = db.getStoreDir();
File databaseDir = db.databaseDirectory();
someData();
resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) );
File indexesCopy = new File( storeDir, "indexesCopy" );
File indexesCopy = new File( databaseDir, "indexesCopy" );
File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory();
copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER );

Expand Down
Expand Up @@ -115,7 +115,7 @@ public void test() throws Exception
try
{
// WHEN
importTool( "--into", dbRule.getStoreDirAbsolutePath(), "--quote", "'", "--nodes", data.getAbsolutePath() );
importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--quote", "'", "--nodes", data.getAbsolutePath() );
// THEN
fail( "Expected import to fail" );
}
Expand All @@ -132,6 +132,6 @@ private String fileName( String name )

private File file( String localname )
{
return new File( dbRule.getStoreDir(), localname );
return new File( dbRule.databaseDirectory(), localname );
}
}
Expand Up @@ -1927,11 +1927,11 @@ public void shouldKeepStoreFilesAfterFailedImport() throws Exception

// WHEN data file contains more columns than header file
int extraColumns = 3;
String storeDir = dbRule.getStoreDirAbsolutePath();
String databaseDir = dbRule.getDatabaseDirAbsolutePath();
try
{
importTool(
"--into", storeDir,
"--into", databaseDir,
"--nodes", nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER +
nodeData( false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns ).getAbsolutePath() );
fail( "Should have thrown exception" );
Expand All @@ -1943,7 +1943,7 @@ public void shouldKeepStoreFilesAfterFailedImport() throws Exception
{
if ( storeType.isRecordStore() )
{
assertTrue( new File( storeDir, MetaDataStore.DEFAULT_NAME + storeType.getStoreName() ).exists() );
assertTrue( new File( databaseDir, MetaDataStore.DEFAULT_NAME + storeType.getStoreName() ).exists() );
}
}

Expand Down Expand Up @@ -1984,15 +1984,15 @@ public void shouldFailIfSupplyingBothFileArgumentAndAnyOtherArgument() throws Ex
String arguments = format(
"--into %s%n" +
"--nodes %s --relationships %s",
dbRule.getStoreDirAbsolutePath(),
dbRule.getDatabaseDirAbsolutePath(),
nodeData( true, config, nodeIds, TRUE ).getAbsolutePath(),
relationshipData( true, config, nodeIds, TRUE, true ).getAbsolutePath() );
writeToFile( argumentFile, arguments, false );

try
{
// when
importTool( "-f", argumentFile.getAbsolutePath(), "--into", dbRule.getStoreDirAbsolutePath() );
importTool( "-f", argumentFile.getAbsolutePath(), "--into", dbRule.getDatabaseDirAbsolutePath() );
fail( "Should have failed" );
}
catch ( IllegalArgumentException e )
Expand Down
Expand Up @@ -144,7 +144,7 @@ private File archiveFile() throws IOException
{
try ( FileSystemAbstraction fs = new DefaultFileSystemAbstraction() )
{
File indexDir = indexRootDirectory( db.getStoreDir() );
File indexDir = indexRootDirectory( db.databaseDirectory() );
File[] files = indexDir.listFiles( pathname -> pathname.isFile() && pathname.getName().startsWith( "archive-" ) );
if ( files == null || files.length == 0 )
{
Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.impl.store.id.IdGeneratorImpl;
import org.neo4j.kernel.impl.store.id.validation.ReservedIdException;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.test.rule.EmbeddedDatabaseRule;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;
import org.neo4j.unsafe.batchinsert.BatchInserter;
Expand All @@ -53,7 +52,7 @@ public class BatchInsertionIT
public void shouldIndexNodesWithMultipleLabels() throws Exception
{
// Given
File path = new File( dbRule.getStoreDirAbsolutePath(), DataSourceManager.DEFAULT_DATABASE_NAME );
File path = dbRule.databaseDirectory();
BatchInserter inserter = BatchInserters.inserter( path, fileSystemRule.get() );

inserter.createNode( map( "name", "Bob" ), label( "User" ), label( "Admin" ) );
Expand All @@ -75,14 +74,13 @@ public void shouldIndexNodesWithMultipleLabels() throws Exception
{
db.shutdown();
}

}

@Test
public void shouldNotIndexNodesWithWrongLabel() throws Exception
{
// Given
File file = new File( dbRule.getStoreDirAbsolutePath() );
File file = new File( dbRule.getDatabaseDirAbsolutePath() );
BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() );

inserter.createNode( map("name", "Bob"), label( "User" ), label("Admin"));
Expand All @@ -108,7 +106,7 @@ public void shouldNotIndexNodesWithWrongLabel() throws Exception
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception
{
File file = dbRule.getStoreDirFile();
File file = dbRule.databaseDirectory();
BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() );
long nodeId = inserter.createNode( Collections.emptyMap() );

Expand All @@ -134,7 +132,7 @@ public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception
{
File file = new File( dbRule.getStoreDirAbsolutePath(), DataSourceManager.DEFAULT_DATABASE_NAME );
File file = dbRule.databaseDirectory();
BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() );
long nodeId = inserter.createNode( Collections.emptyMap() );

Expand Down Expand Up @@ -164,7 +162,7 @@ public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultipleProperti
public void makeSureCantCreateNodeWithMagicNumber() throws IOException
{
// given
File path = new File( dbRule.getStoreDirAbsolutePath() );
File path = dbRule.databaseDirectory();
BatchInserter inserter = BatchInserters.inserter( path, fileSystemRule.get() );

try
Expand Down
Expand Up @@ -146,7 +146,7 @@ public void testIndexDeleteIssue() throws Exception
public void recoveryForRelationshipCommandsOnly() throws Throwable
{
// shutdown db here
File storeDir = db.getStoreDirFile();
File databaseDir = db.databaseDirectory();
shutdownDB();

try ( Transaction tx = db.beginTx() )
Expand All @@ -163,8 +163,8 @@ public void recoveryForRelationshipCommandsOnly() throws Throwable
db.shutdown();

Config config = Config.defaults();
IndexConfigStore indexStore = new IndexConfigStore( storeDir, fileSystemRule.get() );
LuceneDataSource ds = new LuceneDataSource( storeDir, config, indexStore, fileSystemRule.get(), OperationalMode.single );
IndexConfigStore indexStore = new IndexConfigStore( databaseDir, fileSystemRule.get() );
LuceneDataSource ds = new LuceneDataSource( databaseDir, config, indexStore, fileSystemRule.get(), OperationalMode.single );
ds.start();
ds.stop();
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public class FusionIndexIT
@Before
public void setup()
{
databaseDirectory = db.getStoreDir();
databaseDirectory = db.databaseDirectory();
fs = db.getDependencyResolver().resolveDependency( FileSystemAbstraction.class );
}

Expand Down
Expand Up @@ -157,7 +157,7 @@ protected PlatformModule createPlatform( File storeDir, Config config, Dependenc
}.initFacade( storeDir, params, dependencies, this );
}

private void trackUnclosedUse( File storeDir )
private static void trackUnclosedUse( File storeDir )
{
if ( TRACK_UNCLOSED_DATABASE_INSTANCES )
{
Expand All @@ -175,7 +175,7 @@ public void shutdown()
{
if ( TRACK_UNCLOSED_DATABASE_INSTANCES )
{
startedButNotYetClosed.remove( getStoreDir() );
startedButNotYetClosed.remove( databaseDirectory() );
}

super.shutdown();
Expand Down
Expand Up @@ -67,7 +67,7 @@ public abstract class DatabaseRule extends ExternalResource implements GraphData
{
private GraphDatabaseBuilder databaseBuilder;
private GraphDatabaseAPI database;
private File storeDir;
private File databaseDir;
private Supplier<Statement> statementSupplier;
private boolean startEagerly = true;
private Map<Setting<?>, String> config;
Expand Down Expand Up @@ -342,7 +342,7 @@ public synchronized void ensureStarted( String... additionalConfig )
{
applyConfigChanges( additionalConfig );
database = (GraphDatabaseAPI) databaseBuilder.newGraphDatabase();
storeDir = database.getStoreDir();
databaseDir = database.databaseDirectory();
statementSupplier = resolveDependency( ThreadToStatementContextBridge.class );
}
}
Expand Down Expand Up @@ -386,7 +386,7 @@ public GraphDatabaseAPI restartDatabase( RestartAction action, String... configC
{
FileSystemAbstraction fs = resolveDependency( FileSystemAbstraction.class );
database.shutdown();
action.run( fs, storeDir );
action.run( fs, databaseDir );
database = null;
applyConfigChanges( configChanges );
return getGraphDatabaseAPI();
Expand Down Expand Up @@ -459,19 +459,14 @@ public StoreId storeId()
}

@Override
public File getStoreDir()
public File databaseDirectory()
{
return database.getStoreDir();
return database.databaseDirectory();
}

public String getStoreDirAbsolutePath()
public String getDatabaseDirAbsolutePath()
{
return getStoreDir().getAbsolutePath();
}

public File getStoreDirFile()
{
return getStoreDir();
return databaseDirectory().getAbsolutePath();
}

@Override
Expand Down
Expand Up @@ -51,15 +51,15 @@ public EmbeddedDatabaseRule startLazily()
}

@Override
public File getStoreDir()
public File databaseDirectory()
{
return testDirectory.graphDbDir();
}

@Override
public String getStoreDirAbsolutePath()
public String getDatabaseDirAbsolutePath()
{
return testDirectory.directory().getAbsolutePath();
return databaseDirectory().getAbsolutePath();
}

@Override
Expand Down
Expand Up @@ -63,7 +63,7 @@ public void scanStoreStartWithoutExistentIndex() throws Throwable
labelScanStore.shutdown();
workCollector.shutdown();

deleteLabelScanStoreFiles( dbRule.getStoreDir() );
deleteLabelScanStoreFiles( dbRule.databaseDirectory() );

workCollector.init();
labelScanStore.init();
Expand All @@ -86,7 +86,7 @@ public void scanStoreRecreateCorruptedIndexOnStartup() throws Throwable
labelScanStore.shutdown();
workCollector.shutdown();

corruptLabelScanStoreFiles( dbRule.getStoreDir() );
corruptLabelScanStoreFiles( dbRule.databaseDirectory() );

workCollector.init();
labelScanStore.init();
Expand Down
Expand Up @@ -92,7 +92,7 @@ public void canRemoveFilesAndReinvokeShutdown() throws IOException
GraphDatabaseAPI databaseAPI = (GraphDatabaseAPI) this.graphDb;
FileSystemAbstraction fileSystemAbstraction = getDatabaseFileSystem( databaseAPI );
graphDb.shutdown();
fileSystemAbstraction.deleteRecursively( databaseAPI.getStoreDir() );
fileSystemAbstraction.deleteRecursively( databaseAPI.databaseDirectory() );
graphDb.shutdown();
}

Expand Down Expand Up @@ -128,7 +128,7 @@ public ExecutionOrder orderComparedTo( KernelEventHandler other )
graphDb.shutdown();
}

private FileSystemAbstraction getDatabaseFileSystem( GraphDatabaseAPI databaseAPI )
private static FileSystemAbstraction getDatabaseFileSystem( GraphDatabaseAPI databaseAPI )
{
return databaseAPI.getDependencyResolver().resolveDependency( FileSystemAbstraction.class );
}
Expand Down
Expand Up @@ -55,7 +55,7 @@ public void pruningStrategyShouldBeDynamic() throws IOException
Config config = getInstanceFromDb( Config.class );
FileSystemAbstraction fs = getInstanceFromDb( FileSystemAbstraction.class );

LogFiles logFiles = LogFilesBuilder.builder( db.getStoreDir(), fs )
LogFiles logFiles = LogFilesBuilder.builder( db.databaseDirectory(), fs )
.withLogVersionRepository( new SimpleLogVersionRepository() )
.withLastCommittedTransactionIdSupplier( () -> 1 )
.withTransactionIdStore( new SimpleTransactionIdStore() ).build();
Expand Down
Expand Up @@ -238,15 +238,15 @@ private void verifyLogFilesWithCustomPathListing( String path ) throws IOExcepti
graphDatabase.shutdown();
}

private void filesInStoreDirAre( File storeDir, String[] filenames, String[] dirs )
private static void filesInStoreDirAre( File storeDir, String[] filenames, String[] dirs )
{
ArrayList<File> files = new ArrayList<>();
mockFiles( filenames, files, false );
mockFiles( dirs, files, true );
when( storeDir.listFiles() ).thenReturn( files.toArray( new File[files.size()] ) );
}

private ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore, String[] fileNames )
private static ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore, String[] fileNames )
{
ArrayList<File> files = new ArrayList<>();
mockFiles( fileNames, files, false );
Expand All @@ -255,7 +255,7 @@ private ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore,
return snapshot;
}

private ResourceIterator<File> indexFilesAre( IndexingService indexingService, String[] fileNames )
private static ResourceIterator<File> indexFilesAre( IndexingService indexingService, String[] fileNames )
throws IOException
{
ArrayList<File> files = new ArrayList<>();
Expand All @@ -267,15 +267,15 @@ private ResourceIterator<File> indexFilesAre( IndexingService indexingService, S

private void createIndexDbFile() throws IOException
{
File storeDir = db.getStoreDir();
final File indexFile = new File( storeDir, "index.db" );
File databaseDir = db.databaseDirectory();
final File indexFile = new File( databaseDir, "index.db" );
if ( !indexFile.exists() )
{
assertTrue( indexFile.createNewFile() );
}
}

private void mockFiles( String[] filenames, ArrayList<File> files, boolean isDirectories )
private static void mockFiles( String[] filenames, ArrayList<File> files, boolean isDirectories )
{
for ( String filename : filenames )
{
Expand All @@ -295,7 +295,7 @@ private void mockFiles( String[] filenames, ArrayList<File> files, boolean isDir
private static class MarkerFileProvider implements NeoStoreFileListing.StoreFileProvider
{
@Override
public Resource addFilesTo( Collection<StoreFileMetadata> fileMetadataCollection ) throws IOException
public Resource addFilesTo( Collection<StoreFileMetadata> fileMetadataCollection )
{
fileMetadataCollection.add( new StoreFileMetadata( new File( "marker" ), 0 ) );
return Resource.EMPTY;
Expand Down
Expand Up @@ -157,7 +157,7 @@ public interface SPI

StoreId storeId();

File storeDir();
File databaseDirectory();

/** Eg. Neo4j Enterprise HA, Neo4j Community Standalone.. */
String name();
Expand Down Expand Up @@ -916,15 +916,15 @@ public URL validateURLAccess( URL url ) throws URLAccessValidationError
}

@Override
public File getStoreDir()
public File databaseDirectory()
{
return spi.storeDir();
return spi.databaseDirectory();
}

@Override
public String toString()
{
return spi.name() + " [" + getStoreDir() + "]";
return spi.name() + " [" + databaseDirectory() + "]";
}

@Override
Expand Down
Expand Up @@ -53,7 +53,10 @@ public interface GraphDatabaseAPI extends GraphDatabaseService
*/
URL validateURLAccess( URL url ) throws URLAccessValidationError;

File getStoreDir();
/**
* @return underlying database directory
*/
File databaseDirectory();

/**
* Begin internal transaction with specified type and access mode
Expand Down

0 comments on commit 4c19eb7

Please sign in to comment.