Search in sources :

Example 1 with ClusterMemberListener

use of org.neo4j.cluster.member.ClusterMemberListener in project neo4j by neo4j.

the class ObservedClusterMembersTest method missingMasterUnavailabilityEventForOtherInstanceStillRemovesBackupRole.

@Test
public void missingMasterUnavailabilityEventForOtherInstanceStillRemovesBackupRole() throws Exception {
    // given
    Cluster cluster = mock(Cluster.class);
    Heartbeat heartbeat = mock(Heartbeat.class);
    ClusterMemberEvents memberEvents = mock(ClusterMemberEvents.class);
    ObservedClusterMembers members = new ObservedClusterMembers(logProvider, cluster, heartbeat, memberEvents, clusterId1);
    // initialized with the members of the cluster
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    listener.getValue().enteredCluster(clusterConfiguration(clusterUri1, clusterUri2, clusterUri3));
    ArgumentCaptor<ClusterMemberListener> memberListener = ArgumentCaptor.forClass(ClusterMemberListener.class);
    verify(memberEvents).addClusterMemberListener(memberListener.capture());
    // instance 2 is available as MASTER and BACKUP
    memberListener.getValue().memberIsAvailable(OnlineBackupKernelExtension.BACKUP, clusterId2, clusterUri2, StoreId.DEFAULT);
    memberListener.getValue().memberIsAvailable(MASTER, clusterId2, clusterUri2, StoreId.DEFAULT);
    // when - instance 2 becomes available as SLAVE
    memberListener.getValue().memberIsAvailable(SLAVE, clusterId2, clusterUri2, StoreId.DEFAULT);
    // then - instance 2 should be available ONLY as SLAVE
    for (ClusterMember clusterMember : members.getMembers()) {
        if (clusterMember.getInstanceId().equals(clusterId2)) {
            assertThat(count(clusterMember.getRoles()), equalTo(1L));
            assertThat(Iterables.single(clusterMember.getRoles()), equalTo(SLAVE));
            // that's the only member we care about
            break;
        }
    }
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Example 2 with ClusterMemberListener

use of org.neo4j.cluster.member.ClusterMemberListener in project neo4j by neo4j.

the class ObservedClusterMembersTest method receivingInstanceFailureEventRemovesAllRolesForIt.

@Test
public void receivingInstanceFailureEventRemovesAllRolesForIt() throws Exception {
    // given
    Cluster cluster = mock(Cluster.class);
    Heartbeat heartbeat = mock(Heartbeat.class);
    ClusterMemberEvents memberEvents = mock(ClusterMemberEvents.class);
    ObservedClusterMembers members = new ObservedClusterMembers(logProvider, cluster, heartbeat, memberEvents, clusterId1);
    // initialized with the members of the cluster
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    listener.getValue().enteredCluster(clusterConfiguration(clusterUri1, clusterUri2, clusterUri3));
    ArgumentCaptor<ClusterMemberListener> memberListener = ArgumentCaptor.forClass(ClusterMemberListener.class);
    verify(memberEvents).addClusterMemberListener(memberListener.capture());
    // instance 2 is available as MASTER and BACKUP
    memberListener.getValue().memberIsAvailable(OnlineBackupKernelExtension.BACKUP, clusterId2, clusterUri2, StoreId.DEFAULT);
    memberListener.getValue().memberIsAvailable(MASTER, clusterId2, clusterUri2, StoreId.DEFAULT);
    // when - instance 2 becomes failed
    memberListener.getValue().memberIsFailed(clusterId2);
    // then - instance 2 should not be available as any roles
    for (ClusterMember clusterMember : members.getMembers()) {
        if (clusterMember.getInstanceId().equals(clusterId2)) {
            assertThat(count(clusterMember.getRoles()), equalTo(0L));
            // that's the only member we care about
            break;
        }
    }
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Example 3 with ClusterMemberListener

use of org.neo4j.cluster.member.ClusterMemberListener in project neo4j by neo4j.

the class ObservedClusterMembersTest method membersShowsAsUnavailableWhenNewMasterElectedBeforeTheyBecomeAvailable.

@Test
public void membersShowsAsUnavailableWhenNewMasterElectedBeforeTheyBecomeAvailable() throws Exception {
    // given
    Cluster cluster = mock(Cluster.class);
    Heartbeat heartbeat = mock(Heartbeat.class);
    ClusterMemberEvents memberEvents = mock(ClusterMemberEvents.class);
    ObservedClusterMembers members = new ObservedClusterMembers(logProvider, cluster, heartbeat, memberEvents, null);
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    listener.getValue().enteredCluster(clusterConfiguration(clusterUri1, clusterUri2, clusterUri3));
    ArgumentCaptor<ClusterMemberListener> memberListener = ArgumentCaptor.forClass(ClusterMemberListener.class);
    verify(memberEvents).addClusterMemberListener(memberListener.capture());
    memberListener.getValue().memberIsAvailable(SLAVE, clusterId1, haUri1, StoreId.DEFAULT);
    // when
    memberListener.getValue().coordinatorIsElected(clusterId2);
    // then
    assertThat(members.getMembers(), hasItem(sameMemberAs(new ClusterMember(clusterId1))));
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Example 4 with ClusterMemberListener

use of org.neo4j.cluster.member.ClusterMemberListener in project neo4j by neo4j.

the class ObservedClusterMembersTest method missingSlaveUnavailabilityEventDoesNotClobberState.

@Test
public void missingSlaveUnavailabilityEventDoesNotClobberState() throws Exception {
    // given
    Cluster cluster = mock(Cluster.class);
    Heartbeat heartbeat = mock(Heartbeat.class);
    ClusterMemberEvents memberEvents = mock(ClusterMemberEvents.class);
    ObservedClusterMembers members = new ObservedClusterMembers(logProvider, cluster, heartbeat, memberEvents, clusterId1);
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    listener.getValue().enteredCluster(clusterConfiguration(clusterUri1, clusterUri2, clusterUri3));
    ArgumentCaptor<ClusterMemberListener> memberListener = ArgumentCaptor.forClass(ClusterMemberListener.class);
    verify(memberEvents).addClusterMemberListener(memberListener.capture());
    // when
    // first we are available as master
    memberListener.getValue().memberIsAvailable(MASTER, clusterId1, haUri1, StoreId.DEFAULT);
    // and then for some reason as slave, without an unavailable message in between
    memberListener.getValue().memberIsAvailable(SLAVE, clusterId1, haUri1, StoreId.DEFAULT);
    // then
    assertThat(members.getCurrentMember().getHARole(), equalTo(SLAVE));
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Example 5 with ClusterMemberListener

use of org.neo4j.cluster.member.ClusterMemberListener in project neo4j by neo4j.

the class HighAvailabilityMemberStateMachineTest method whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending.

@Test
public void whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other1 = new InstanceId(2);
    InstanceId other2 = new InstanceId(3);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    List<InstanceId> otherInstances = new LinkedList();
    otherInstances.add(other1);
    otherInstances.add(other2);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), otherInstances);
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(me);
    memberListener.memberIsAvailable(MASTER, me, URI.create("ha://whatever"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
    // When
    memberListener.memberIsFailed(new InstanceId(2));
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) LinkedList(java.util.LinkedList) ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)18 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)18 InstanceId (org.neo4j.cluster.InstanceId)11 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)7 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)7 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)7 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)7 ObservedClusterMembers (org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers)7 AvailabilityRequirement (org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement)5 LinkedList (java.util.LinkedList)1