Search in sources :

Example 16 with Cluster

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

the class ClusterDiscoveryIT method shouldNotBeAbleToDiscoverFromReadReplicas.

@Test
public void shouldNotBeAbleToDiscoverFromReadReplicas() throws Exception {
    // given
    Cluster cluster = clusterRule.withSharedCoreParams(config).withNumberOfReadReplicas(2).startCluster();
    try {
        // when
        getMembers(cluster.getReadReplicaById(0).database());
        fail("Should not be able to discover members from read replicas");
    } catch (ProcedureException ex) {
        // then
        assertThat(ex.getMessage(), containsString("There is no procedure with the name"));
    }
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 17 with Cluster

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

the class ClusterLeaderStepDownIT method leaderShouldStepDownWhenFollowersAreGone.

@Test
public void leaderShouldStepDownWhenFollowersAreGone() throws Throwable {
    // when
    Cluster cluster = clusterRule.startCluster();
    //Do some work to make sure the cluster is operating normally.
    CoreClusterMember leader = cluster.coreTx((db, tx) -> {
        Node node = db.createNode(Label.label("bam"));
        node.setProperty("bam", "bam");
        tx.success();
    });
    List<CoreClusterMember> followers = cluster.coreMembers().stream().filter(m -> m.raft().currentRole() != Role.LEADER).collect(toList());
    assertEquals(7, followers.size());
    //when
    //shutdown 4 servers, leaving 4 remaining and therefore not a quorum.
    followers.subList(0, 4).forEach(CoreClusterMember::shutdown);
    //then
    assertEventually("Leader should have stepped down.", () -> leader.raft().isLeader(), Matchers.is(false), 2, TimeUnit.MINUTES);
}
Also used : Role(org.neo4j.causalclustering.core.consensus.roles.Role) Label(org.neo4j.graphdb.Label) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Rule(org.junit.Rule) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.assertEquals(org.junit.Assert.assertEquals) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 18 with Cluster

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

the class ClusterMembershipChangeIT method newMemberNotInInitialMembersConfig.

@Test
@Ignore("Incomplete, HC will hang waiting for others to join.")
public void newMemberNotInInitialMembersConfig() throws Throwable {
    // when
    Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    List<AdvertisedSocketAddress> onlyServerZero = singletonList(Cluster.socketAddressForServer(0));
    // then
    cluster.addCoreMemberWithIdAndInitialMembers(3, onlyServerZero).start();
    cluster.addCoreMemberWithIdAndInitialMembers(4, onlyServerZero).start();
    cluster.addCoreMemberWithIdAndInitialMembers(5, onlyServerZero).start();
    cluster.removeCoreMemberWithMemberId(0);
    cluster.removeCoreMemberWithMemberId(1);
    cluster.removeCoreMemberWithMemberId(2);
    cluster.shutdown();
    cluster.start();
    List<Object[]> currentMembers;
    for (CoreClusterMember member : cluster.coreMembers()) {
        currentMembers = discoverClusterMembers(member.database());
        assertThat(currentMembers, containsInAnyOrder(new Object[] { "127.0.0.1:8003" }, new Object[] { "127.0.0.1:8004" }, new Object[] { "127.0.0.1:8005" }));
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with Cluster

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

the class ClusterOverviewIT method shouldDiscoverCoreMembers.

@Test
public void shouldDiscoverCoreMembers() throws Exception {
    // given
    clusterRule.withNumberOfCoreMembers(3);
    clusterRule.withNumberOfReadReplicas(0);
    // when
    Cluster cluster = clusterRule.startCluster();
    Matcher<List<MemberInfo>> expected = allOf(containsMemberAddresses(cluster.coreMembers()), containsRole(LEADER, 1), containsRole(FOLLOWER, 2), doesNotContainRole(READ_REPLICA));
    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 20 with Cluster

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

the class ClusterOverviewIT method shouldDiscoverCoreMembersAndReadReplicas.

@Test
public void shouldDiscoverCoreMembersAndReadReplicas() throws Exception {
    // given
    clusterRule.withNumberOfCoreMembers(3);
    clusterRule.withNumberOfReadReplicas(3);
    // when
    Cluster cluster = clusterRule.startCluster();
    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)

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