Skip to content

Commit

Permalink
Use the restore command in ITs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Needham committed Jun 27, 2016
1 parent 5e30ead commit 3a19ea8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Expand Up @@ -59,6 +59,7 @@
import static org.junit.Assert.assertNotEquals;
import static org.neo4j.backup.BackupEmbeddedIT.runBackupToolFromOtherJvmToGetExitCode;
import static org.neo4j.coreedge.TestStoreId.assertAllStoresHaveTheSameStoreId;
import static org.neo4j.dbms.DatabaseManagementSystemSettings.database_path;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

Expand Down Expand Up @@ -143,14 +144,14 @@ public void makeSureCoreClusterCanBeRestoredFromABackup() throws Throwable

// when
File initialStoreDir = cluster.coreServerStoreDirectory( 0 );
restoreDatabase( initialStoreDir, backupPath );
restoreDatabase( backupPath, initialStoreDir );
String conversionMetadata = new GenerateClusterSeedCommand().generate( initialStoreDir).getConversionId();

ConvertClassicStoreCommand convertClassicStoreCommand = new ConvertClassicStoreCommand( new ConversionVerifier() );
for ( int i = 0; i < numberOfCoreServers; i++ )
{
File coreStoreDir = cluster.coreServerStoreDirectory( i );
restoreDatabase( coreStoreDir, backupPath );
restoreDatabase( backupPath, coreStoreDir );
convertClassicStoreCommand.convert( coreStoreDir, StandardV3_0.NAME , conversionMetadata );
}

Expand All @@ -169,12 +170,11 @@ public void makeSureCoreClusterCanBeRestoredFromABackup() throws Throwable
assertNotEquals( storeId, afterRestoreStoreId );
}

private void restoreDatabase( File coreStoreDir, File backupPath ) throws IOException
private void restoreDatabase( File backupPath, File coreStoreDir ) throws IOException
{
Config config = Config.empty().with(
stringMap( DatabaseManagementSystemSettings.database_path.name(), coreStoreDir.getAbsolutePath() ) );
new RestoreDatabaseCommand( new DefaultFileSystemAbstraction(),
backupPath, config, "graph.db", true ).execute();
DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
Config config = Config.empty().with( stringMap( database_path.name(), coreStoreDir.getAbsolutePath() ) );
new RestoreDatabaseCommand( fs, backupPath, config, "graph.db", true ).execute();
}

static CoreGraphDatabase createSomeData( Cluster cluster ) throws TimeoutException, InterruptedException
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.junit.runners.Parameterized;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;

Expand All @@ -33,6 +34,7 @@
import org.neo4j.coreedge.convert.GenerateClusterSeedCommand;
import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.server.core.CoreGraphDatabase;
import org.neo4j.dbms.DatabaseManagementSystemSettings;
import org.neo4j.function.ThrowingSupplier;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
Expand All @@ -41,19 +43,23 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileUtils;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.format.highlimit.HighLimit;
import org.neo4j.kernel.impl.store.format.standard.StandardV3_0;
import org.neo4j.restore.RestoreDatabaseCommand;
import org.neo4j.test.coreedge.ClusterRule;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.neo4j.coreedge.discovery.Cluster.coreServerStoreDirectory;
import static org.neo4j.coreedge.server.CoreEdgeClusterSettings.raft_advertised_address;
import static org.neo4j.dbms.DatabaseManagementSystemSettings.database_path;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.Iterables.count;
import static org.neo4j.helpers.collection.MapUtil.stringMap;
import static org.neo4j.test.assertion.Assert.assertEventually;

@RunWith(Parameterized.class)
Expand Down Expand Up @@ -89,7 +95,7 @@ public void shouldReplicateTransactionToCoreServers() throws Throwable
for ( int serverId = 0; serverId < CLUSTER_SIZE; serverId++ )
{
File destination = coreServerStoreDirectory( clusterDirectory, serverId );
FileUtils.copyRecursively( classicNeo4jStore, destination );
restoreDatabase( classicNeo4jStore, destination );
new ConvertClassicStoreCommand( new ConversionVerifier() ).convert( destination, recordFormat, conversionMetadata );
}

Expand Down Expand Up @@ -126,6 +132,13 @@ public void shouldReplicateTransactionToCoreServers() throws Throwable
}
}

private void restoreDatabase( File backupPath, File coreStoreDir ) throws IOException
{
DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
Config config = Config.empty().with( stringMap( database_path.name(), coreStoreDir.getAbsolutePath() ) );
new RestoreDatabaseCommand( fs, backupPath, config, "graph.db", true ).execute();
}

private File createClassicNeo4jStore( File base, int nodesToCreate, String recordFormat )
{
File existingDbDir = new File( base, "existing" );
Expand Down

0 comments on commit 3a19ea8

Please sign in to comment.