Search in sources :

Example 21 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class ClusterBindingIT method aNewServerShouldJoinTheClusterByDownloadingASnapshot.

@Test
public void aNewServerShouldJoinTheClusterByDownloadingASnapshot() throws Exception {
    // GIVEN
    cluster.coreTx((db, tx) -> {
        Node node = db.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    SampleData.createSomeData(100, cluster);
    for (CoreClusterMember db : cluster.coreMembers()) {
        db.coreState().prune();
    }
    // WHEN
    cluster.addCoreMemberWithId(4).start();
    cluster.awaitLeader();
    // THEN
    assertEquals(4, cluster.healthyCoreMembers().size());
    List<File> coreStoreDirs = storeDirs(cluster.coreMembers());
    cluster.shutdown();
    assertAllStoresHaveTheSameStoreId(coreStoreDirs, fs);
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Example 22 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class CorePruningIT method actuallyDeletesTheFiles.

@Test
public void actuallyDeletesTheFiles() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    CoreClusterMember coreGraphDatabase = null;
    int txs = 10;
    for (int i = 0; i < txs; i++) {
        coreGraphDatabase = cluster.coreTx((db, tx) -> {
            createData(db, 1);
            tx.success();
        });
    }
    // when pruning kicks in then some files are actually deleted
    File raftLogDir = coreGraphDatabase.raftLogDirectory();
    int expectedNumberOfLogFilesAfterPruning = 2;
    assertEventually("raft logs eventually pruned", () -> numberOfFiles(raftLogDir), equalTo(expectedNumberOfLogFilesAfterPruning), 5, TimeUnit.SECONDS);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) CausalClusteringSettings.raft_log_pruning_strategy(org.neo4j.causalclustering.core.CausalClusteringSettings.raft_log_pruning_strategy) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Test(org.junit.Test) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) File(java.io.File) Test(org.junit.Test)

Example 23 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class CorePruningIT method shouldNotPruneUncommittedEntries.

@Test
public void shouldNotPruneUncommittedEntries() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    CoreClusterMember coreGraphDatabase = null;
    int txs = 1000;
    for (int i = 0; i < txs; i++) {
        coreGraphDatabase = cluster.coreTx((db, tx) -> createData(db, 1));
    }
    // when pruning kicks in then some files are actually deleted
    int expectedNumberOfLogFilesAfterPruning = 2;
    File raftLogDir = coreGraphDatabase.raftLogDirectory();
    assertEventually("raft logs eventually pruned", () -> numberOfFiles(raftLogDir), equalTo(expectedNumberOfLogFilesAfterPruning), 5, TimeUnit.SECONDS);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) CausalClusteringSettings.raft_log_pruning_strategy(org.neo4j.causalclustering.core.CausalClusteringSettings.raft_log_pruning_strategy) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Test(org.junit.Test) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) File(java.io.File) Test(org.junit.Test)

Example 24 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class ClusterSeedingIT method shouldSeedNewMemberFromEmptyIdleCluster.

@Test
public void shouldSeedNewMemberFromEmptyIdleCluster() throws Throwable {
    // given
    cluster = new Cluster(testDir.directory("cluster-b"), 3, 0, new SharedDiscoveryService(), emptyMap(), backupParams(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
    cluster.start();
    // when: creating a backup
    File backupDir = createBackup(cluster.getCoreMemberById(0).database(), "the-backup");
    // and: seeding new member with said backup
    CoreClusterMember newMember = cluster.addCoreMemberWithId(3);
    fsa.copyRecursively(backupDir, newMember.storeDir());
    newMember.start();
    // then
    dataMatchesEventually(DbRepresentation.of(newMember.database()), cluster.coreMembers());
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) SharedDiscoveryService(org.neo4j.causalclustering.discovery.SharedDiscoveryService) File(java.io.File) Test(org.junit.Test)

Example 25 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember 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)

Aggregations

Test (org.junit.Test)45 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)45 Cluster (org.neo4j.causalclustering.discovery.Cluster)20 Node (org.neo4j.graphdb.Node)16 File (java.io.File)12 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)11 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)10 Driver (org.neo4j.driver.v1.Driver)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (org.neo4j.driver.v1.Session)9 Rule (org.junit.Rule)8 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)8 TimeUnit (java.util.concurrent.TimeUnit)7 Transaction (org.neo4j.graphdb.Transaction)7 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Role (org.neo4j.causalclustering.core.consensus.roles.Role)5