Skip to content

Commit

Permalink
Adapt tests to database/store dir update: use correct directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jul 23, 2018
1 parent 206e367 commit d9ce15a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 44 deletions.
Expand Up @@ -70,12 +70,12 @@ public class ManyPropertyKeysIT
public final RuleChain ruleChain = RuleChain.outerRule( testDirectory )
.around( fileSystemRule ).around( pageCacheRule );

private File storeDir;
private File databaseDir;

@Before
public void setup()
{
storeDir = testDirectory.storeDir();
databaseDir = testDirectory.databaseDir();
}

@Test
Expand Down Expand Up @@ -130,8 +130,7 @@ private GraphDatabaseAPI databaseWithManyPropertyKeys( int propertyKeyCount )
{

PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() );
StoreFactory storeFactory = new StoreFactory(
storeDir, Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ), pageCache,
StoreFactory storeFactory = new StoreFactory( databaseDir, Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ), pageCache,
fileSystemRule.get(),
NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY );
NeoStores neoStores = storeFactory.openAllNeoStores( true );
Expand Down
Expand Up @@ -86,9 +86,8 @@
import org.neo4j.kernel.impl.transaction.state.OnlineIndexUpdates;
import org.neo4j.kernel.impl.transaction.state.PrepareTrackingRecordFormats;
import org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy;

import org.neo4j.storageengine.api.EntityType;
import org.neo4j.kernel.impl.transaction.state.RecordChangeSet;
import org.neo4j.storageengine.api.EntityType;
import org.neo4j.storageengine.api.StorageCommand;
import org.neo4j.storageengine.api.schema.SchemaRule;
import org.neo4j.test.rule.NeoStoresRule;
Expand Down Expand Up @@ -121,6 +120,9 @@

public class TransactionRecordStateTest
{
@Rule
public final NeoStoresRule neoStoresRule = new NeoStoresRule( getClass() );

private static final String LONG_STRING = "string value long enough not to be stored as a short string";
private static final int propertyId1 = 1;
private static final int propertyId2 = 2;
Expand All @@ -130,6 +132,8 @@ public class TransactionRecordStateTest
private final long[] oneLabelId = new long[]{3};
private final long[] secondLabelId = new long[]{4};
private final long[] bothLabelIds = new long[]{3, 4};
private final IntegrityValidator integrityValidator = mock( IntegrityValidator.class );
private RecordChangeSet recordChangeSet;

private static void assertRelationshipGroupDoesNotExist( RecordChangeSet recordChangeSet, NodeRecord node, int type )
{
Expand Down Expand Up @@ -197,11 +201,6 @@ private static int manuallyCountRelationships( RecordChangeSet recordChangeSet,
return count;
}

@Rule
public final NeoStoresRule neoStoresRule = new NeoStoresRule( getClass() );
private final IntegrityValidator integrityValidator = mock( IntegrityValidator.class );
private RecordChangeSet recordChangeSet;

@Test
public void shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities() throws Exception
{
Expand Down
Expand Up @@ -71,11 +71,11 @@ public Builder builder()
}

private NeoStores open( FileSystemAbstraction fs, PageCache pageCache, RecordFormats format,
Function<FileSystemAbstraction,IdGeneratorFactory> idGeneratorFactory, String... config )
throws IOException
Function<FileSystemAbstraction,IdGeneratorFactory> idGeneratorFactory, String... config ) throws IOException
{
assert neoStores == null : "Already opened";
TestDirectory testDirectory = TestDirectory.testDirectory( testClass, fs );
TestDirectory testDirectory = TestDirectory.testDirectory( fs );
testDirectory.prepareDirectory( testClass, null );
File databaseDir = testDirectory.databaseDir();
Config configuration = configOf( config );
StoreFactory storeFactory = new StoreFactory( databaseDir, configuration, idGeneratorFactory.apply( fs ),
Expand Down
Expand Up @@ -129,6 +129,7 @@ public void shouldNotCopyOverAndExistingDatabase() throws Exception
@Test
public void shouldThrowExceptionIfBackupDirectoryDoesNotExist() throws Exception
{
assertTrue( fromDatabase.delete() );
createDbAt( toStore, toLogicalLogsPath, 0, toConfig );

expectedException.expect( IllegalArgumentException.class );
Expand All @@ -141,8 +142,6 @@ public void shouldThrowExceptionIfBackupDirectoryDoesNotExist() throws Exception
@Test
public void shouldThrowExceptionIfBackupDirectoryDoesNotHaveStoreFiles() throws Exception
{
assertTrue( fromDatabase.mkdirs() );

expectedException.expect( IllegalArgumentException.class );
expectedException.expectMessage( "Source directory is not a database backup" );

Expand Down
Expand Up @@ -27,8 +27,6 @@
import org.junit.Rule;
import org.junit.Test;

import java.io.File;

import org.neo4j.causalclustering.discovery.Cluster;
import org.neo4j.causalclustering.discovery.IpFamily;
import org.neo4j.causalclustering.discovery.SharedDiscoveryServiceFactory;
Expand Down Expand Up @@ -80,20 +78,19 @@ public void after()
public void shouldRestoreBySeedingAllMembers() throws Throwable
{
// given
File storeDir = testDir.storeDir();
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir )
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDir.storeDir() )
.setConfig( GraphDatabaseSettings.allow_upgrade, Settings.TRUE )
.setConfig( GraphDatabaseSettings.record_format, HighLimit.NAME )
.setConfig( OnlineBackupSettings.online_backup_enabled, Boolean.FALSE.toString() )
.newGraphDatabase();
database.shutdown();
Config config = Config.defaults( OnlineBackupSettings.online_backup_enabled, Settings.FALSE );
DbRepresentation before = DbRepresentation.of( storeDir, config );
DbRepresentation before = DbRepresentation.of( testDir.storeDir(), config );

// when
fsa.copyRecursively( storeDir, cluster.getCoreMemberById( 0 ).databaseDirectory() );
fsa.copyRecursively( storeDir, cluster.getCoreMemberById( 1 ).databaseDirectory() );
fsa.copyRecursively( storeDir, cluster.getCoreMemberById( 2 ).databaseDirectory() );
fsa.copyRecursively( testDir.databaseDir(), cluster.getCoreMemberById( 0 ).databaseDirectory() );
fsa.copyRecursively( testDir.databaseDir(), cluster.getCoreMemberById( 1 ).databaseDirectory() );
fsa.copyRecursively( testDir.databaseDir(), cluster.getCoreMemberById( 2 ).databaseDirectory() );
cluster.start();

// then
Expand Down
Expand Up @@ -360,7 +360,7 @@ public void newSlaveJoiningClusterShouldNotAcceptOperationsUntilConstraintIsOnli
HighlyAvailableGraphDatabase master = cluster.getMaster();

HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
File slaveStoreDirectory = cluster.getStoreDir( slave );
File slaveStoreDirectory = cluster.getDatabaseDir( slave );

// Crash the slave
ClusterManager.RepairKit shutdownSlave = cluster.shutdown( slave );
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void shouldHandleSlaveWritingFirstAfterStoryCopy() throws Throwable
cluster.sync();

// ... crash the slave
File slaveStoreDirectory = cluster.getStoreDir( slave );
File slaveStoreDirectory = cluster.getDatabaseDir( slave );
ClusterManager.RepairKit shutdownSlave = cluster.shutdown( slave );
deleteRecursively( slaveStoreDirectory );

Expand Down
Expand Up @@ -1353,7 +1353,7 @@ public InstanceId getServerId( HighlyAvailableGraphDatabase member )
return member.getDependencyResolver().resolveDependency( Config.class ).get( ClusterSettings.server_id );
}

public File getStoreDir( HighlyAvailableGraphDatabase member )
public File getDatabaseDir( HighlyAvailableGraphDatabase member )
{
assertMember( member );
return member.databaseDirectory();
Expand Down
Expand Up @@ -60,11 +60,11 @@
public class PageCacheWarmupEnterpriseEditionIT extends PageCacheWarmupTestSupport
{
@Rule
public SuppressOutput suppressOutput = SuppressOutput.suppressAll();
public final SuppressOutput suppressOutput = SuppressOutput.suppressAll();
@Rule
public TestDirectory testDirectory = TestDirectory.testDirectory();
public final TestDirectory testDirectory = TestDirectory.testDirectory();
@Rule
public EnterpriseDatabaseRule db = new EnterpriseDatabaseRule( testDirectory ).startLazily();
public final EnterpriseDatabaseRule db = new EnterpriseDatabaseRule( testDirectory ).startLazily();

private static void verifyEventuallyWarmsUp( long pagesInMemory, File metricsDirectory ) throws Exception
{
Expand Down Expand Up @@ -179,7 +179,6 @@ public void exit( int status )
File data = testDirectory.cleanDirectory( "data" );
File databases = new File( data, "databases" );
File graphdb = testDirectory.databaseDir( databases );
assertTrue( graphdb.mkdirs() );
FileUtils.copyRecursively( databaseDir, graphdb );
FileUtils.deleteRecursively( databaseDir );
Path homePath = data.toPath().getParent();
Expand Down
Expand Up @@ -31,7 +31,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -55,7 +54,6 @@
import org.neo4j.internal.kernel.api.IndexReference;
import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.io.fs.FileUtils;
import org.neo4j.kernel.api.InwardKernel;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.Statement;
Expand Down Expand Up @@ -217,9 +215,10 @@ public void serverDatabaseShouldStartOnOlderStoreWhenUpgradeIsEnabled() throws T
public void migratingOlderDataAndThanStartAClusterUsingTheNewerDataShouldWork() throws Throwable
{
// migrate the store using a single instance
File databaseDirectory = store.prepareDirectory( testDir.databaseDir() );
File storeDir = testDir.storeDir( "initialData" );
File databaseDirectory = store.prepareDirectory( testDir.databaseDir( storeDir ) );
GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder( testDir.storeDir() );
GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder( storeDir );
builder.setConfig( GraphDatabaseSettings.allow_upgrade, "true" );
builder.setConfig( GraphDatabaseSettings.pagecache_memory, "8m" );
builder.setConfig( GraphDatabaseSettings.logs_directory, testDir.directory( "logs" ).getAbsolutePath() );
Expand All @@ -237,10 +236,9 @@ public void migratingOlderDataAndThanStartAClusterUsingTheNewerDataShouldWork()
assertConsistentStore( databaseDirectory );

// start the cluster with the db migrated from the old instance
File haDir = Files.createTempDirectory("ha-stuff" ).toFile();
FileUtils.deleteRecursively( haDir );
File haDir = testDir.storeDir( "ha-stuff" );
ClusterManager clusterManager = new ClusterManager.Builder( haDir )
.withSeedDir( databaseDirectory ).withCluster( clusterOfSize( 2 ) ).build();
.withSeedDir( storeDir ).withCluster( clusterOfSize( 2 ) ).build();

clusterManager.start();

Expand Down Expand Up @@ -389,15 +387,15 @@ private Store( String resourceName, long expectedNodeCount, long lastTxId,
this.formatFamily = formatFamily;
}

File prepareDirectory( File targetDir ) throws IOException
File prepareDirectory( File databaseDirectory ) throws IOException
{
if ( !targetDir.exists() && !targetDir.mkdirs() )
if ( !databaseDirectory.exists() && !databaseDirectory.mkdirs() )
{
throw new IOException( "Could not create directory " + targetDir );
throw new IOException( "Could not create directory " + databaseDirectory );
}
Unzip.unzip( getClass(), resourceName, targetDir );
new File( targetDir, "debug.log" ).delete(); // clear the log
return targetDir;
Unzip.unzip( getClass(), resourceName, databaseDirectory );
new File( databaseDirectory, "debug.log" ).delete(); // clear the log
return databaseDirectory;
}

@Override
Expand Down

0 comments on commit d9ce15a

Please sign in to comment.