Search in sources :

Example 1 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class ObservedClusterMembersTest method joinedMemberShowsInList.

@Test
public void joinedMemberShowsInList() 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));
    // when
    listener.getValue().joinedCluster(clusterId3, 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 2 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class ObservedClusterMembersTest method shouldRegisterItselfOnListeners.

@Test
public void shouldRegisterItselfOnListeners() throws Exception {
    // given
    Cluster cluster = mock(Cluster.class);
    Heartbeat heartbeat = mock(Heartbeat.class);
    ClusterMemberEvents clusterMemberEvents = mock(ClusterMemberEvents.class);
    // when
    new ObservedClusterMembers(logProvider, cluster, heartbeat, clusterMemberEvents, null);
    // then
    verify(cluster).addClusterListener(Mockito.<ClusterListener>any());
    verify(heartbeat).addHeartbeatListener(Mockito.<HeartbeatListener>any());
    verify(clusterMemberEvents).addClusterMemberListener(Mockito.<ClusterMemberListener>any());
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) Test(org.junit.Test)

Example 3 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster 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 4 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class ObservedClusterMembersTest method failedThenAliveMemberShowsAsAlive.

@Test
public void failedThenAliveMemberShowsAsAlive() 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<HeartbeatListener> heartBeatListener = ArgumentCaptor.forClass(HeartbeatListener.class);
    verify(heartbeat).addHeartbeatListener(heartBeatListener.capture());
    // when
    heartBeatListener.getValue().failed(clusterId1);
    heartBeatListener.getValue().alive(clusterId1);
    // then
    assertThat(members.getMembers(), hasItem(sameMemberAs(new ClusterMember(clusterId1))));
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) HeartbeatListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatListener) 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 5 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster 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)

Aggregations

Cluster (org.neo4j.cluster.protocol.cluster.Cluster)22 Test (org.junit.Test)19 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)17 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)15 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)14 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)7 HostnamePort (org.neo4j.helpers.HostnamePort)5 URI (java.net.URI)4 DefaultSlaveFactory (org.neo4j.kernel.ha.com.master.DefaultSlaveFactory)4 SlaveFactory (org.neo4j.kernel.ha.com.master.SlaveFactory)4 Slave (org.neo4j.kernel.ha.com.master.Slave)3 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)3 InstanceId (org.neo4j.cluster.InstanceId)2 AtomicBroadcast (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast)2 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)2 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)2 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)2 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)2 FixedTimeoutStrategy (org.neo4j.cluster.timeout.FixedTimeoutStrategy)2 MessageTimeoutStrategy (org.neo4j.cluster.timeout.MessageTimeoutStrategy)2