Search in sources :

Example 21 with Cluster

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

the class ClusterOverviewIT method shouldDiscoverNewCoreMembers.

@Test
public void shouldDiscoverNewCoreMembers() throws Exception {
    // given
    clusterRule.withNumberOfCoreMembers(3);
    clusterRule.withNumberOfReadReplicas(0);
    Cluster cluster = clusterRule.startCluster();
    // when
    cluster.addCoreMemberWithId(3).start();
    cluster.addCoreMemberWithId(4).start();
    Matcher<List<MemberInfo>> expected = allOf(containsMemberAddresses(cluster.coreMembers()), containsRole(LEADER, 1), containsRole(FOLLOWER, 4));
    for (int coreServerId = 0; coreServerId < 5; coreServerId++) {
        // then
        assertEventualOverview(cluster, expected, coreServerId);
    }
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.Test)

Example 22 with Cluster

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

the class ClusterOverviewIT method shouldDiscoverReadReplicasAfterRestartingCores.

@Test
public void shouldDiscoverReadReplicasAfterRestartingCores() throws Exception {
    // given
    clusterRule.withNumberOfCoreMembers(3);
    clusterRule.withNumberOfReadReplicas(3);
    // when
    Cluster cluster = clusterRule.startCluster();
    cluster.shutdownCoreMembers();
    cluster.startCoreMembers();
    Matcher<List<MemberInfo>> expected = allOf(containsAllMemberAddresses(cluster.coreMembers(), cluster.readReplicas()), containsRole(LEADER, 1), containsRole(FOLLOWER, 2), containsRole(READ_REPLICA, 3));
    for (int coreServerId = 0; coreServerId < 3; coreServerId++) {
        // then
        assertEventualOverview(cluster, expected, coreServerId);
    }
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.Test)

Example 23 with Cluster

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

the class CausalClusteringRolesIT method readReplicasShouldRefuseWrites.

@Test
public void readReplicasShouldRefuseWrites() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    GraphDatabaseService db = cluster.findAnyReadReplica().database();
    Transaction tx = db.beginTx();
    // then
    exceptionMatcher.expect(WriteOperationsNotAllowedException.class);
    // when
    db.createNode();
    tx.success();
    tx.close();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 24 with Cluster

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

the class ClusterShutdownIT method shouldShutdownEvenThoughWaitingForLock.

@Test
public void shouldShutdownEvenThoughWaitingForLock() throws Exception {
    Cluster cluster = clusterRule.startCluster();
    try {
        for (int victimId = 0; victimId < cluster.numberOfCoreMembersReportedByTopology(); victimId++) {
            assertTrue(cluster.getCoreMemberById(victimId).database().isAvailable(1000));
            shouldShutdownEvenThoughWaitingForLock0(cluster, victimId, shutdownOrder);
            cluster.start();
        }
    } catch (WriteOperationsNotAllowedException e) {
    // expected
    }
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 25 with Cluster

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

Aggregations

Cluster (org.neo4j.causalclustering.discovery.Cluster)52 Test (org.junit.Test)51 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)21 File (java.io.File)14 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)13 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)13 Node (org.neo4j.graphdb.Node)12 Rule (org.junit.Rule)11 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)11 IOException (java.io.IOException)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Transaction (org.neo4j.graphdb.Transaction)10 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)10 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)10 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)9 Map (java.util.Map)8 TimeUnit (java.util.concurrent.TimeUnit)8 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 UnsatisfiedDependencyException (org.neo4j.kernel.impl.util.UnsatisfiedDependencyException)8