Search in sources :

Example 11 with Heartbeat

use of org.neo4j.cluster.protocol.heartbeat.Heartbeat in project neo4j by neo4j.

the class ObservedClusterMembersTest method leftMemberDisappearsFromList.

@Test
public void leftMemberDisappearsFromList() 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));
    // when
    listener.getValue().leftCluster(clusterId3, clusterUri3);
    // then
    assertThat(members.getMembers(), not(hasItems(sameMemberAs(new ClusterMember(clusterId3)))));
}
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) Test(org.junit.Test)

Example 12 with Heartbeat

use of org.neo4j.cluster.protocol.heartbeat.Heartbeat in project neo4j by neo4j.

the class ObservedClusterMembersTest method shouldContainMemberListAfterEnteringCluster.

@Test
public void shouldContainMemberListAfterEnteringCluster() 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);
    // when
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    listener.getValue().enteredCluster(clusterConfiguration(clusterUri1, clusterUri2, clusterUri3));
    // then
    assertThat(members.getMembers(), hasItems(sameMemberAs(new ClusterMember(clusterId1)), sameMemberAs(new ClusterMember(clusterId2)), sameMemberAs(new ClusterMember(clusterId3))));
}
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) Test(org.junit.Test)

Example 13 with Heartbeat

use of org.neo4j.cluster.protocol.heartbeat.Heartbeat in project neo4j by neo4j.

the class ObservedClusterMembersTest method availableSlaveShowsProperInformation.

@Test
public void availableSlaveShowsProperInformation() 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(SLAVE, clusterId1, haUri1, StoreId.DEFAULT);
    // then
    assertThat(members.getMembers(), hasItem(sameMemberAs(new ClusterMember(clusterId1).availableAs(SLAVE, 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)

Example 14 with Heartbeat

use of org.neo4j.cluster.protocol.heartbeat.Heartbeat 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 15 with Heartbeat

use of org.neo4j.cluster.protocol.heartbeat.Heartbeat 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

Cluster (org.neo4j.cluster.protocol.cluster.Cluster)15 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)15 Test (org.junit.Test)14 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)14 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)14 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)7 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)3 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 BindingListener (org.neo4j.cluster.BindingListener)1 InstanceId (org.neo4j.cluster.InstanceId)1 MultiPaxosServerFactory (org.neo4j.cluster.MultiPaxosServerFactory)1 NetworkedServerFactory (org.neo4j.cluster.NetworkedServerFactory)1 StateMachines (org.neo4j.cluster.StateMachines)1 AtomicBroadcast (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast)1 AtomicBroadcastListener (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastListener)1