Search in sources :

Example 26 with ClusterMemberEvents

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

the class ObservedClusterMembersTest method missingMasterUnavailabilityEventDoesNotClobberState.

@Test
public void missingMasterUnavailabilityEventDoesNotClobberState() 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 slaves
    memberListener.getValue().memberIsAvailable(SLAVE, clusterId1, haUri1, StoreId.DEFAULT);
    // and then for some reason as master, without an unavailable message in between
    memberListener.getValue().memberIsAvailable(MASTER, clusterId1, haUri1, StoreId.DEFAULT);
    // then
    assertThat(members.getCurrentMember().getHARole(), equalTo(MASTER));
}
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 27 with ClusterMemberEvents

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

the class ObservedClusterMembersTest method availableMasterShowsProperInformation.

@Test
public void availableMasterShowsProperInformation() 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());
    // when
    memberListener.getValue().memberIsAvailable(MASTER, clusterId1, haUri1, StoreId.DEFAULT);
    // then
    assertThat(members.getMembers(), hasItem(sameMemberAs(new ClusterMember(clusterId1).availableAs(MASTER, haUri1, StoreId.DEFAULT))));
}
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)

Aggregations

ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)27 Test (org.junit.Test)26 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)19 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)14 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)14 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)13 InstanceId (org.neo4j.cluster.InstanceId)12 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)7 ObservedClusterMembers (org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers)7 AvailabilityRequirement (org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement)5 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)3 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Election (org.neo4j.cluster.protocol.election.Election)1 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)1