Skip to content

Commit

Permalink
More green tests, adapt custom graph factories, add equality to store…
Browse files Browse the repository at this point in the history
… dir.
  • Loading branch information
MishaDemianenko committed Aug 21, 2018
1 parent 0e0a77c commit 6a29314
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 31 deletions.
Expand Up @@ -59,7 +59,9 @@ protected GraphDatabaseService newEmbeddedDatabase( File dir, Config config, Dep
@Override @Override
protected PlatformModule createPlatform( File storeDir, Config config, Dependencies dependencies ) protected PlatformModule createPlatform( File storeDir, Config config, Dependencies dependencies )
{ {
config.augment( GraphDatabaseSettings.database_path, storeDir.getAbsolutePath() ); File databasesRoot = storeDir.getParentFile();
config.augment( GraphDatabaseSettings.active_database, storeDir.getName() );
config.augment( GraphDatabaseSettings.databases_root_path, databasesRoot.getAbsolutePath() );
return new PlatformModule( storeDir, config, databaseInfo, dependencies ) return new PlatformModule( storeDir, config, databaseInfo, dependencies )
{ {
@Override @Override
Expand All @@ -72,8 +74,7 @@ protected FileSystemAbstraction createFileSystemAbstraction()
protected PageCache createPageCache( FileSystemAbstraction fileSystem, Config config, protected PageCache createPageCache( FileSystemAbstraction fileSystem, Config config,
LogService logging, Tracers tracers, VersionContextSupplier versionContextSupplier ) LogService logging, Tracers tracers, VersionContextSupplier versionContextSupplier )
{ {
PageCache pageCache = super.createPageCache( fileSystem, config, logging, tracers, PageCache pageCache = super.createPageCache( fileSystem, config, logging, tracers, versionContextSupplier );
versionContextSupplier );
return new AdversarialPageCache( pageCache, adversary ); return new AdversarialPageCache( pageCache, adversary );
} }
}; };
Expand Down
Expand Up @@ -257,9 +257,9 @@ public void recoveryShouldFixPartiallyAppliedSchemaIndexUpdates()
Command.RelationshipCommand.class ); Command.RelationshipCommand.class );
adversary.disable(); adversary.disable();


File storeDir = directory.storeDir(); File databaseDir = directory.databaseDir();
GraphDatabaseService db = AdversarialPageCacheGraphDatabaseFactory.create( fileSystemRule.get(), adversary ) GraphDatabaseService db = AdversarialPageCacheGraphDatabaseFactory.create( fileSystemRule.get(), adversary )
.newEmbeddedDatabaseBuilder( storeDir ) .newEmbeddedDatabaseBuilder( databaseDir )
.newGraphDatabase(); .newGraphDatabase();
try try
{ {
Expand Down
Expand Up @@ -37,7 +37,7 @@ public static DatabaseLayout of( StoreLayout storeLayout, String databaseName )


public static DatabaseLayout of( File databaseDirectory ) public static DatabaseLayout of( File databaseDirectory )
{ {
return new DatabaseLayout( StoreLayout.of( databaseDirectory.getParentFile() ), databaseDirectory.getName() ); return of( databaseDirectory.getParentFile(), databaseDirectory.getName() );
} }


public static DatabaseLayout of( File rootDirectory, String databaseName ) public static DatabaseLayout of( File rootDirectory, String databaseName )
Expand Down
22 changes: 22 additions & 0 deletions community/io/src/main/java/org/neo4j/io/layout/StoreLayout.java
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.io.layout; package org.neo4j.io.layout;


import java.io.File; import java.io.File;
import java.util.Objects;


public class StoreLayout public class StoreLayout
{ {
Expand Down Expand Up @@ -56,6 +57,27 @@ public File storeLockFile()
return new File( storeDirectory, STORE_LOCK_FILENAME ); return new File( storeDirectory, STORE_LOCK_FILENAME );
} }


@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
StoreLayout that = (StoreLayout) o;
return Objects.equals( storeDirectory, that.storeDirectory );
}

@Override
public int hashCode()
{
return Objects.hash( storeDirectory );
}

@Override @Override
public String toString() public String toString()
{ {
Expand Down
Expand Up @@ -179,7 +179,7 @@ public DatabaseLayout databaseLayout()
public DatabaseLayout databaseLayout( File storeDir ) public DatabaseLayout databaseLayout( File storeDir )
{ {
DatabaseLayout databaseLayout = StoreLayout.of( storeDir ).databaseLayout( DEFAULT_DATABASE_DIRECTORY ); DatabaseLayout databaseLayout = StoreLayout.of( storeDir ).databaseLayout( DEFAULT_DATABASE_DIRECTORY );
createDirectory( defaultDatabaseLayout.databaseDirectory() ); createDirectory( databaseLayout.databaseDirectory() );
return databaseLayout; return databaseLayout;
} }


Expand Down
Expand Up @@ -192,7 +192,7 @@ private File getLogsDirectory()
File neo4jHome = config.get( GraphDatabaseSettings.neo4j_home ); File neo4jHome = config.get( GraphDatabaseSettings.neo4j_home );
File databasePath = config.get( database_path ); File databasePath = config.get( database_path );
File logicalLogsLocation = config.get( GraphDatabaseSettings.logical_logs_location ); File logicalLogsLocation = config.get( GraphDatabaseSettings.logical_logs_location );
if ( databaseLayout.getStoreLayout().equals( neo4jHome ) && databasePath.equals( logicalLogsLocation ) ) if ( databaseLayout.getStoreLayout().storeDirectory().equals( neo4jHome ) && databasePath.equals( logicalLogsLocation ) )
{ {
return databaseLayout.databaseDirectory(); return databaseLayout.databaseDirectory();
} }
Expand Down
Expand Up @@ -294,7 +294,7 @@ public void makeSureStoreIdIsEnforced()
// Data should be OK, but store id check should prevent that. // Data should be OK, but store id check should prevent that.
try try
{ {
backup.incremental( serverStorePath.getPath() ); backup.incremental( backupDatabasePath.getPath() );
fail( "Shouldn't work" ); fail( "Shouldn't work" );
} }
catch ( RuntimeException e ) catch ( RuntimeException e )
Expand All @@ -306,7 +306,7 @@ public void makeSureStoreIdIsEnforced()
// server A, even after a failed attempt from server B // server A, even after a failed attempt from server B
DbRepresentation furtherRepresentation = addMoreData( serverStorePath ); DbRepresentation furtherRepresentation = addMoreData( serverStorePath );
server = startServer( serverStorePath, backupPort ); server = startServer( serverStorePath, backupPort );
backup.incremental( serverStorePath.getPath() ); backup.incremental( backupDatabasePath.getPath() );
assertTrue( "Should be consistent", backup.isConsistent() ); assertTrue( "Should be consistent", backup.isConsistent() );
assertEquals( furtherRepresentation, getDbRepresentation() ); assertEquals( furtherRepresentation, getDbRepresentation() );
shutdownServer( server ); shutdownServer( server );
Expand Down
Expand Up @@ -243,6 +243,6 @@ private static void shutdownServer( ServerInterface server ) throws Exception


private DbRepresentation getBackupDbRepresentation() private DbRepresentation getBackupDbRepresentation()
{ {
return DbRepresentation.of( backupStore, Config.defaults( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ) ); return DbRepresentation.of( backupDatabase, Config.defaults( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ) );
} }
} }
Expand Up @@ -27,7 +27,6 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
Expand All @@ -40,6 +39,7 @@
import org.neo4j.helpers.progress.ProgressMonitorFactory; import org.neo4j.helpers.progress.ProgressMonitorFactory;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.logging.LogProvider; import org.neo4j.logging.LogProvider;
import org.neo4j.test.rule.TestDirectory;


import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
Expand All @@ -55,6 +55,8 @@ public class BackupStrategyCoordinatorTest
{ {
@Rule @Rule
public final ExpectedException expectedException = ExpectedException.none(); public final ExpectedException expectedException = ExpectedException.none();
@Rule
public final TestDirectory testDirectory = TestDirectory.testDirectory();


// dependencies // dependencies
private final ConsistencyCheckService consistencyCheckService = mock( ConsistencyCheckService.class ); private final ConsistencyCheckService consistencyCheckService = mock( ConsistencyCheckService.class );
Expand All @@ -78,7 +80,7 @@ public class BackupStrategyCoordinatorTest
@Before @Before
public void setup() public void setup()
{ {
when( reportDir.toFile() ).thenReturn( mock( File.class ) ); when( reportDir.toFile() ).thenReturn( testDirectory.databaseLayout().databaseDirectory() );
when( outsideWorld.fileSystem() ).thenReturn( fileSystem ); when( outsideWorld.fileSystem() ).thenReturn( fileSystem );
when( onlineBackupContext.getRequiredArguments() ).thenReturn( requiredArguments ); when( onlineBackupContext.getRequiredArguments() ).thenReturn( requiredArguments );
when( onlineBackupContext.getResolvedLocationFromName() ).thenReturn( reportDir ); when( onlineBackupContext.getResolvedLocationFromName() ).thenReturn( reportDir );
Expand Down
Expand Up @@ -48,7 +48,6 @@
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout; import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.layout.StoreLayout;
import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule; import org.neo4j.test.rule.fs.EphemeralFileSystemRule;


Expand Down Expand Up @@ -187,11 +186,10 @@ public void shouldPrintUsage() throws Throwable
} }
} }


private Path createUnlockedFakeDbDir( Path homeDir ) throws IOException private void createUnlockedFakeDbDir( Path homeDir ) throws IOException
{ {
Path fakeDbDir = createFakeDbDir( homeDir ); Path fakeDbDir = createFakeDbDir( homeDir );
Files.createFile( DatabaseLayout.of( fakeDbDir.toFile() ).getStoreLayout().storeLockFile().toPath() ); Files.createFile( DatabaseLayout.of( fakeDbDir.toFile() ).getStoreLayout().storeLockFile().toPath() );
return fakeDbDir;
} }


private FileLock createLockedFakeDbDir( Path homeDir ) throws IOException private FileLock createLockedFakeDbDir( Path homeDir ) throws IOException
Expand All @@ -207,14 +205,14 @@ private Path createFakeDbDir( Path homeDir ) throws IOException
return graphDb; return graphDb;
} }


private FileLock createLockedStoreLockFileIn( Path storeDir ) throws IOException private FileLock createLockedStoreLockFileIn( Path databaseDir ) throws IOException
{ {
Path storeLockFile = StoreLayout.of( storeDir.toFile() ).storeLockFile().toPath(); Path storeLockFile = Files.createFile( DatabaseLayout.of( databaseDir.toFile() ).getStoreLayout().storeLockFile().toPath() );
channel = FileChannel.open( storeLockFile, READ, WRITE ); channel = FileChannel.open( storeLockFile, READ, WRITE );
return channel.lock( 0, Long.MAX_VALUE, true ); return channel.lock( 0, Long.MAX_VALUE, true );
} }


private String[] databaseNameParameter( String databaseName ) private static String[] databaseNameParameter( String databaseName )
{ {
return new String[]{"--database=" + databaseName}; return new String[]{"--database=" + databaseName};
} }
Expand Down
4 changes: 4 additions & 0 deletions enterprise/cypher/acceptance-spec-suite/pom.xml
Expand Up @@ -232,6 +232,10 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>


<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<!-- other --> <!-- other -->


<dependency> <dependency>
Expand Down
Expand Up @@ -28,15 +28,15 @@ import java.time.ZoneOffset
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.graphdb.config.Setting import org.neo4j.graphdb.config.Setting
import org.neo4j.io.fs.FileUtils import org.neo4j.io.fs.FileUtils
import org.neo4j.kernel.configuration.Settings
import org.neo4j.kernel.impl.index.schema.config.SpatialIndexSettings import org.neo4j.kernel.impl.index.schema.config.SpatialIndexSettings
import org.neo4j.test.rule.TestDirectory
import org.neo4j.values.storable._ import org.neo4j.values.storable._


import scala.collection.{Map, immutable} import scala.collection.Map


class IndexPersistenceAcceptanceTest extends IndexingTestSupport { class IndexPersistenceAcceptanceTest extends IndexingTestSupport {


private var dbDir = new File("test") private var dbDir = TestDirectory.testDirectory(getClass).prepareDirectoryForTest("test")


override val cypherComparisonSupport = false override val cypherComparisonSupport = false


Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.neo4j.cluster.member.ClusterMemberListener; import org.neo4j.cluster.member.ClusterMemberListener;
import org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider; import org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider;
import org.neo4j.consistency.store.StoreAssertions; import org.neo4j.consistency.store.StoreAssertions;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.TransactionFailureException; import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.graphdb.config.Setting; import org.neo4j.graphdb.config.Setting;
Expand All @@ -66,6 +67,7 @@
import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.Iterables;
import org.neo4j.helpers.collection.MapUtil; import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.io.layout.DatabaseLayout; import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.layout.StoreLayout;
import org.neo4j.io.pagecache.IOLimiter; import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
Expand Down Expand Up @@ -1157,14 +1159,15 @@ private HighlyAvailableGraphDatabase startMemberNow( InstanceId serverId )
URI clusterUri = clusterUri( member ); URI clusterUri = clusterUri( member );
int clusterPort = clusterUri.getPort(); int clusterPort = clusterUri.getPort();
int haPort = PortAuthority.allocatePort(); int haPort = PortAuthority.allocatePort();
File storeDir = new File( parent, "server" + serverId ); StoreLayout storeLayout = StoreLayout.of( new File( parent, "server" + serverId ) );
DatabaseLayout databaseLayout = storeLayout.databaseLayout( DatabaseManager.DEFAULT_DATABASE_NAME );
if ( storeDirInitializer != null ) if ( storeDirInitializer != null )
{ {
storeDirInitializer.initializeStoreDir( serverId.toIntegerIndex(), storeDir ); storeDirInitializer.initializeStoreDir( serverId.toIntegerIndex(), databaseLayout.databaseDirectory() );
} }


Monitors monitors = getDatabaseMonitors(); Monitors monitors = getDatabaseMonitors();
GraphDatabaseBuilder builder = dbFactory.setMonitors( monitors ).newEmbeddedDatabaseBuilder( storeDir.getAbsoluteFile() ); GraphDatabaseBuilder builder = dbFactory.setMonitors( monitors ).newEmbeddedDatabaseBuilder( databaseLayout.databaseDirectory() );
builder.setConfig( ClusterSettings.cluster_name, name ); builder.setConfig( ClusterSettings.cluster_name, name );
builder.setConfig( ClusterSettings.initial_hosts, initialHosts ); builder.setConfig( ClusterSettings.initial_hosts, initialHosts );
builder.setConfig( ClusterSettings.server_id, serverId + "" ); builder.setConfig( ClusterSettings.server_id, serverId + "" );
Expand Down
Expand Up @@ -38,7 +38,6 @@
import org.neo4j.kernel.impl.factory.Edition; import org.neo4j.kernel.impl.factory.Edition;
import org.neo4j.kernel.impl.logging.LogService; import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.logging.SimpleLogService; import org.neo4j.kernel.impl.logging.SimpleLogService;
import org.neo4j.logging.AssertableLogProvider;
import org.neo4j.logging.LogProvider; import org.neo4j.logging.LogProvider;


/** /**
Expand All @@ -65,7 +64,10 @@ protected GraphDatabaseBuilder.DatabaseCreator createDatabaseCreator( File store
@Override @Override
public GraphDatabaseService newDatabase( Config config ) public GraphDatabaseService newDatabase( Config config )
{ {
File databasesRoot = storeDir.getParentFile();
config.augment( GraphDatabaseSettings.ephemeral, Settings.FALSE ); config.augment( GraphDatabaseSettings.ephemeral, Settings.FALSE );
config.augment( GraphDatabaseSettings.active_database, storeDir.getName() );
config.augment( GraphDatabaseSettings.databases_root_path, databasesRoot.getAbsolutePath() );
return new GraphDatabaseFacadeFactory( DatabaseInfo.ENTERPRISE, EnterpriseEditionModule::new ) return new GraphDatabaseFacadeFactory( DatabaseInfo.ENTERPRISE, EnterpriseEditionModule::new )
{ {
@Override @Override
Expand All @@ -88,7 +90,7 @@ protected LogService createLogService( LogProvider userLogProvider )
} }
}; };
} }
}.newFacade( storeDir, config, GraphDatabaseDependencies.newDependencies( state.databaseDependencies() ) ); }.newFacade( databasesRoot, config, GraphDatabaseDependencies.newDependencies( state.databaseDependencies() ) );
} }
}; };
} }
Expand Down
Expand Up @@ -86,7 +86,7 @@ public void compositeNodeKeyConstraintUpdate() throws Exception
} }
database.shutdown(); database.shutdown();


ConsistencyCheckService.Result consistencyCheckResult = checkDbConsistency( testDirectory.databaseDir() ); ConsistencyCheckService.Result consistencyCheckResult = checkDbConsistency( testDirectory.storeDir() );
assertTrue( "Database is consistent", consistencyCheckResult.isSuccessful() ); assertTrue( "Database is consistent", consistencyCheckResult.isSuccessful() );
} }


Expand Down
Expand Up @@ -56,11 +56,11 @@ public class HalfCreatedConstraintIT
@Test @Test
public void uniqueIndexWithoutOwningConstraintIsIgnoredDuringCheck() throws ConsistencyCheckTool.ToolFailureException, IOException public void uniqueIndexWithoutOwningConstraintIsIgnoredDuringCheck() throws ConsistencyCheckTool.ToolFailureException, IOException
{ {
File storeDir = testDirectory.storeDir(); File databaseDir = testDirectory.databaseDir();
Label marker = Label.label( "MARKER" ); Label marker = Label.label( "MARKER" );
String property = "property"; String property = "property";


GraphDatabaseService database = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); GraphDatabaseService database = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( databaseDir );
try try
{ {
createNodes( marker, property, database ); createNodes( marker, property, database );
Expand All @@ -72,7 +72,7 @@ public void uniqueIndexWithoutOwningConstraintIsIgnoredDuringCheck() throws Cons
database.shutdown(); database.shutdown();
} }


ConsistencyCheckService.Result checkResult = ConsistencyCheckTool.runConsistencyCheckTool( new String[]{testDirectory.databaseDir().getAbsolutePath()}, ConsistencyCheckService.Result checkResult = ConsistencyCheckTool.runConsistencyCheckTool( new String[]{databaseDir.getAbsolutePath()},
emptyPrintStream(), emptyPrintStream() ); emptyPrintStream(), emptyPrintStream() );
assertTrue( String.join( System.lineSeparator(), Files.readAllLines( checkResult.reportFile().toPath() ) ), checkResult.isSuccessful() ); assertTrue( String.join( System.lineSeparator(), Files.readAllLines( checkResult.reportFile().toPath() ) ), checkResult.isSuccessful() );
} }
Expand Down

0 comments on commit 6a29314

Please sign in to comment.