Skip to content

Commit

Permalink
Expose database directory in one more rule
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jul 23, 2018
1 parent 015bf7f commit 1782f6d
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 69 deletions.
Expand Up @@ -37,7 +37,6 @@
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.index.IndexDirectoryStructure;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule;
import org.neo4j.values.storable.CoordinateReferenceSystem;
Expand Down Expand Up @@ -145,7 +144,7 @@ private File archiveFile() throws IOException
{
try ( FileSystemAbstraction fs = new DefaultFileSystemAbstraction() )
{
File indexDir = indexRootDirectory( new File( db.getStoreDir(), DataSourceManager.DEFAULT_DATABASE_NAME ) );
File indexDir = indexRootDirectory( db.getStoreDir() );
File[] files = indexDir.listFiles( pathname -> pathname.isFile() && pathname.getName().startsWith( "archive-" ) );
if ( files == null || files.length == 0 )
{
Expand Down
Expand Up @@ -108,7 +108,7 @@ public void shouldNotIndexNodesWithWrongLabel() throws Exception
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception
{
File file = new File( dbRule.getStoreDirFile(), DataSourceManager.DEFAULT_DATABASE_NAME );
File file = dbRule.getStoreDirFile();
BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() );
long nodeId = inserter.createNode( Collections.emptyMap() );

Expand Down
Expand Up @@ -34,7 +34,6 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.impl.index.schema.NumberIndexProvider;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule;
Expand All @@ -53,7 +52,7 @@ public class FusionIndexIT
public DatabaseRule db = new EmbeddedDatabaseRule()
.withSetting( GraphDatabaseSettings.default_schema_provider, GraphDatabaseSettings.SchemaIndex.NATIVE20.providerName() );

private File storeDir;
private File databaseDirectory;
private final Label label = Label.label( "label" );
private final String propKey = "propKey";
private FileSystemAbstraction fs;
Expand All @@ -65,7 +64,7 @@ public class FusionIndexIT
@Before
public void setup()
{
storeDir = db.getStoreDir();
databaseDirectory = db.getStoreDir();
fs = db.getDependencyResolver().resolveDependency( FileSystemAbstraction.class );
}

Expand Down Expand Up @@ -132,7 +131,7 @@ private void verifyContent()

private void deleteIndexFilesFor( IndexProvider.Descriptor descriptor )
{
File databaseDirectory = new File( this.storeDir, DataSourceManager.DEFAULT_DATABASE_NAME );
File databaseDirectory = this.databaseDirectory;
File rootDirectory = subProviderDirectoryStructure( databaseDirectory ).forProvider( descriptor ).rootDirectory();
File[] files = fs.listFiles( rootDirectory );
for ( File indexFile : files )
Expand Down
Expand Up @@ -53,7 +53,7 @@ public EmbeddedDatabaseRule startLazily()
@Override
public File getStoreDir()
{
return testDirectory.directory();
return testDirectory.graphDbDir();
}

@Override
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.neo4j.kernel.api.labelscan.NodeLabelUpdate;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.index.labelscan.NativeLabelScanStore;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.storageengine.api.schema.LabelScanReader;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void scanStoreStartWithoutExistentIndex() throws Throwable
labelScanStore.shutdown();
workCollector.shutdown();

deleteLabelScanStoreFiles( new File( dbRule.getStoreDirFile(), DataSourceManager.DEFAULT_DATABASE_NAME ) );
deleteLabelScanStoreFiles( dbRule.getStoreDir() );

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

corruptLabelScanStoreFiles( new File( dbRule.getStoreDirFile(), DataSourceManager.DEFAULT_DATABASE_NAME ) );
corruptLabelScanStoreFiles( dbRule.getStoreDir() );

workCollector.init();
labelScanStore.init();
Expand Down Expand Up @@ -151,12 +150,12 @@ private void corruptLabelScanStoreFiles( File storeDirectory ) throws IOExceptio
scrambleFile( storeFile( storeDirectory ) );
}

private void deleteLabelScanStoreFiles( File storeDirectory )
private static void deleteLabelScanStoreFiles( File storeDirectory )
{
assertTrue( storeFile( storeDirectory ).delete() );
}

private void checkLabelScanStoreAccessible( LabelScanStore labelScanStore ) throws IOException
private static void checkLabelScanStoreAccessible( LabelScanStore labelScanStore ) throws IOException
{
int labelId = 1;
try ( LabelScanWriter labelScanWriter = labelScanStore.newWriter() )
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.Rule;
import org.junit.Test;

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

import org.neo4j.graphdb.Transaction;
Expand All @@ -35,7 +34,6 @@
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
import org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder;
import org.neo4j.kernel.impl.transaction.log.rotation.LogRotation;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule;

Expand All @@ -57,7 +55,7 @@ public void pruningStrategyShouldBeDynamic() throws IOException
Config config = getInstanceFromDb( Config.class );
FileSystemAbstraction fs = getInstanceFromDb( FileSystemAbstraction.class );

LogFiles logFiles = LogFilesBuilder.builder( new File( db.getStoreDir(), DataSourceManager.DEFAULT_DATABASE_NAME ), fs )
LogFiles logFiles = LogFilesBuilder.builder( db.getStoreDir(), fs )
.withLogVersionRepository( new SimpleLogVersionRepository() )
.withLastCommittedTransactionIdSupplier( () -> 1 )
.withTransactionIdStore( new SimpleTransactionIdStore() ).build();
Expand Down
Expand Up @@ -19,16 +19,13 @@
*/
package org.neo4j.harness;

import org.apache.commons.io.FileUtils;
import org.codehaus.jackson.JsonNode;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
Expand Down Expand Up @@ -189,63 +186,56 @@ public void shouldRunBuilderOnExistingStoreDir() throws Exception
{
// When
// create graph db with one node upfront
Path dir = Files.createTempDirectory( getClass().getSimpleName() + "_shouldRunBuilderOnExistingStorageDir" );
File storeDir = Config.defaults( GraphDatabaseSettings.data_directory, dir.toString() )
.get( GraphDatabaseSettings.database_path );
File existingStoreDir = testDir.directory( "existingStore" );
File storeDir = Config.defaults( GraphDatabaseSettings.data_directory, existingStoreDir.toPath().toString() )
.get( GraphDatabaseSettings.database_path ).getParentFile();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
try
{
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
try
{
db.execute( "create ()" );
}
finally
{
db.shutdown();
}
db.execute( "create ()" );
}
finally
{
db.shutdown();
}

try ( ServerControls server = getTestServerBuilder( testDir.directory() ).copyFrom( dir.toFile() )
.newServer() )
try ( ServerControls server = getTestServerBuilder( testDir.directory() ).copyFrom( existingStoreDir )
.newServer() )
{
// Then
try ( Transaction tx = server.graph().beginTx() )
{
// Then
try ( Transaction tx = server.graph().beginTx() )
{
ResourceIterable<Node> allNodes = Iterables.asResourceIterable( server.graph().getAllNodes() );
ResourceIterable<Node> allNodes = Iterables.asResourceIterable( server.graph().getAllNodes() );

assertTrue( Iterables.count( allNodes ) > 0 );
assertTrue( Iterables.count( allNodes ) > 0 );

// When: create another node
server.graph().createNode();
tx.success();
}
// When: create another node
server.graph().createNode();
tx.success();
}
}

// Then: we still only have one node since the server is supposed to work on a copy
db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
try
{
try ( Transaction tx = db.beginTx() )
{
assertEquals( 1, Iterables.count( db.getAllNodes() ) );
tx.success();
}
}
finally
// Then: we still only have one node since the server is supposed to work on a copy
db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
try
{
try ( Transaction tx = db.beginTx() )
{
db.shutdown();
assertEquals( 1, Iterables.count( db.getAllNodes() ) );
tx.success();
}
}
finally
{
FileUtils.forceDelete( dir.toFile() );
db.shutdown();
}
}

@Test
public void shouldOpenBoltPort() throws Throwable
{
// given
try ( ServerControls controls = getTestServerBuilder( testDir.graphDbDir() ).newServer() )
try ( ServerControls controls = getTestServerBuilder( testDir.directory() ).newServer() )
{
URI uri = controls.boltURI();

Expand All @@ -263,7 +253,7 @@ public void shouldFailWhenProvidingANonDirectoryAsSource() throws IOException
File notADirectory = File.createTempFile( "prefix", "suffix" );
assertFalse( notADirectory.isDirectory() );

try ( ServerControls ignored = getTestServerBuilder( testDir.graphDbDir() )
try ( ServerControls ignored = getTestServerBuilder( testDir.directory() )
.copyFrom( notADirectory ).newServer() )
{
fail( "server should not start" );
Expand Down
Expand Up @@ -58,7 +58,8 @@ public class CommunityNeoServer extends AbstractNeoServer
{
protected static final GraphFactory COMMUNITY_FACTORY = ( config, dependencies ) ->
{
File storeDir = config.get( GraphDatabaseSettings.database_path );
//TODO:
File storeDir = config.get( GraphDatabaseSettings.database_path ).getParentFile();
return new GraphDatabaseFacadeFactory( DatabaseInfo.COMMUNITY, CommunityEditionModule::new )
.newFacade( storeDir, config, dependencies );
};
Expand Down
Expand Up @@ -81,7 +81,7 @@ public static List<String> recordFormats()
public void shouldInsertDifferentTypesOfThings() throws Exception
{
// GIVEN
BatchInserter inserter = BatchInserters.inserter( directory.directory(), fileSystemRule.get(),
BatchInserter inserter = BatchInserters.inserter( directory.graphDbDir(), fileSystemRule.get(),
stringMap( GraphDatabaseSettings.log_queries.name(), "true",
GraphDatabaseSettings.record_format.name(), recordFormat,
GraphDatabaseSettings.log_queries_filename.name(),
Expand Down Expand Up @@ -142,7 +142,7 @@ public void insertIntoExistingDatabase() throws IOException
db.shutdown();
}

BatchInserter inserter = BatchInserters.inserter( storeDir, fileSystemRule.get() );
BatchInserter inserter = BatchInserters.inserter( directory.graphDbDir(), fileSystemRule.get() );
try
{
long start = inserter.createNode( someProperties( 5 ), Labels.One );
Expand Down
Expand Up @@ -92,7 +92,7 @@ logService, new TestAdditionalInitialIds(), Config.defaults() ) )
batchingNeoStores.createNew();
}

GraphDatabaseService database = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
GraphDatabaseService database = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.directory() );
try
{
TransactionIdStore transactionIdStore = getTransactionIdStore( (GraphDatabaseAPI) database );
Expand Down
Expand Up @@ -71,27 +71,27 @@ public class RecordFormatsMigrationIT
@Test
public void migrateLatestStandardToLatestHighLimit()
{
executeAndStopDb( startStandardFormatDb(), this::createNode );
executeAndStopDb( startStandardFormatDb(), RecordFormatsMigrationIT::createNode );
assertLatestStandardStore();

executeAndStopDb( startHighLimitFormatDb(), this::assertNodeExists );
executeAndStopDb( startHighLimitFormatDb(), RecordFormatsMigrationIT::assertNodeExists );
assertLatestHighLimitStore();
}

@Test
public void migrateHighLimitV3_0ToLatestHighLimit()
{
executeAndStopDb( startDb( HighLimitV3_0_0.NAME ), this::createNode );
executeAndStopDb( startDb( HighLimitV3_0_0.NAME ), RecordFormatsMigrationIT::createNode );
assertStoreFormat( HighLimitV3_0_0.RECORD_FORMATS );

executeAndStopDb( startHighLimitFormatDb(), this::assertNodeExists );
executeAndStopDb( startHighLimitFormatDb(), RecordFormatsMigrationIT::assertNodeExists );
assertLatestHighLimitStore();
}

@Test
public void migrateHighLimitToStandard()
{
executeAndStopDb( startHighLimitFormatDb(), this::createNode );
executeAndStopDb( startHighLimitFormatDb(), RecordFormatsMigrationIT::createNode );
assertLatestHighLimitStore();

try
Expand All @@ -106,7 +106,7 @@ public void migrateHighLimitToStandard()
assertLatestHighLimitStore();
}

private void createNode( GraphDatabaseService db )
private static void createNode( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
Expand All @@ -116,7 +116,7 @@ private void createNode( GraphDatabaseService db )
}
}

private void assertNodeExists( GraphDatabaseService db )
private static void assertNodeExists( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
Expand All @@ -137,7 +137,7 @@ private GraphDatabaseService startHighLimitFormatDb()

private GraphDatabaseService startDb( String recordFormatName )
{
return new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDirectory.graphDbDir() )
return new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDirectory.directory() )
.setConfig( GraphDatabaseSettings.allow_upgrade, Settings.TRUE )
.setConfig( GraphDatabaseSettings.record_format, recordFormatName )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
Expand Down

0 comments on commit 1782f6d

Please sign in to comment.