Search in sources :

Example 11 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class BackupCoreIT method makeSureBackupCanBePerformedFromAnyInstance.

@Test
public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable {
    for (CoreClusterMember db : cluster.coreMembers()) {
        // Run backup
        DbRepresentation beforeChange = DbRepresentation.of(createSomeData(cluster));
        String[] args = backupArguments(backupAddress(db.database()), backupsDir, "" + db.serverId());
        assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(clusterRule.clusterDirectory(), args));
        // Add some new data
        DbRepresentation afterChange = DbRepresentation.of(createSomeData(cluster));
        // Verify that old data is back
        DbRepresentation backupRepresentation = DbRepresentation.of(new File(backupsDir, "" + db.serverId()), getConfig());
        assertEquals(beforeChange, backupRepresentation);
        assertNotEquals(backupRepresentation, afterChange);
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 12 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class ClusterSeedingIT method shouldRestoreBySeedingSingleMember.

@Test
@Ignore("need to seed all members for now")
public void shouldRestoreBySeedingSingleMember() throws Throwable {
    // given
    File backupDir = createBackupUsingAnotherCluster();
    DbRepresentation before = DbRepresentation.of(backupDir);
    // when
    fsa.copyRecursively(backupDir, cluster.getCoreMemberById(0).storeDir());
    cluster.getCoreMemberById(0).start();
    Thread.sleep(2_000);
    cluster.getCoreMemberById(1).start();
    cluster.getCoreMemberById(2).start();
    // then
    dataMatchesEventually(before, cluster.coreMembers());
}
Also used : File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class ClusterSeedingIT method shouldRestoreBySeedingAllMembers.

@Test
public void shouldRestoreBySeedingAllMembers() throws Throwable {
    // given
    File backupDir = createBackupUsingAnotherCluster();
    DbRepresentation before = DbRepresentation.of(backupDir);
    // when
    fsa.copyRecursively(backupDir, cluster.getCoreMemberById(0).storeDir());
    fsa.copyRecursively(backupDir, cluster.getCoreMemberById(1).storeDir());
    fsa.copyRecursively(backupDir, cluster.getCoreMemberById(2).storeDir());
    cluster.start();
    // then
    dataMatchesEventually(before, cluster.coreMembers());
}
Also used : File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 14 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project graphdb by neo4j-attic.

the class TestBackup method makeSureStoreIdIsEnforced.

@Test
public void makeSureStoreIdIsEnforced() throws Exception {
    // Create data set X on server A
    DbRepresentation initialDataSetRepresentation = createInitialDataSet(serverPath);
    ServerInterface server = startServer(serverPath);
    // Grab initial backup from server A
    OnlineBackup backup = OnlineBackup.from("localhost");
    backup.full(backupPath);
    assertEquals(initialDataSetRepresentation, DbRepresentation.of(backupPath));
    shutdownServer(server);
    // Create data set X+Y on server B 
    createInitialDataSet(otherServerPath);
    addMoreData(otherServerPath);
    server = startServer(otherServerPath);
    // Data should be OK, but store id check should prevent that.
    try {
        backup.incremental(backupPath);
        fail("Shouldn't work");
    } catch (ComException e) {
    // Good
    }
    shutdownServer(server);
    // Just make sure incremental backup can be received properly from
    // server A, even after a failed attempt from server B
    DbRepresentation furtherRepresentation = addMoreData(serverPath);
    server = startServer(serverPath);
    backup.incremental(backupPath);
    assertEquals(furtherRepresentation, DbRepresentation.of(backupPath));
    shutdownServer(server);
}
Also used : ComException(org.neo4j.com.ComException) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 15 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project graphdb by neo4j-attic.

the class TestBackup method createInitialDataSet.

private DbRepresentation createInitialDataSet(String path) {
    GraphDatabaseService db = startGraphDatabase(path);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    node.setProperty("myKey", "myValue");
    db.getReferenceNode().createRelationshipTo(node, DynamicRelationshipType.withName("KNOWS"));
    tx.success();
    tx.finish();
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DbRepresentation(org.neo4j.test.DbRepresentation)

Aggregations

DbRepresentation (org.neo4j.test.DbRepresentation)27 Test (org.junit.Test)18 Transaction (org.neo4j.graphdb.Transaction)11 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)10 Node (org.neo4j.graphdb.Node)9 File (java.io.File)7 Relationship (org.neo4j.graphdb.Relationship)4 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)2 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)2 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)2 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)2 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Clock (java.time.Clock)1 Duration.ofSeconds (java.time.Duration.ofSeconds)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1