Search in sources :

Example 16 with Cluster

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

the class HighAvailabilitySlavesTest method shouldNotReturnUnavailableSlaves.

@Test
public void shouldNotReturnUnavailableSlaves() {
    // given
    Cluster cluster = mock(Cluster.class);
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID)));
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
    slaves.init();
    // when
    Iterable<Slave> memberSlaves = slaves.getSlaves();
    // then
    assertThat(count(memberSlaves), equalTo(0L));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 17 with Cluster

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

the class ObservedClusterMembersTest method iCanGetToMyself.

@Test
public void iCanGetToMyself() 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);
    // when
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    listener.getValue().enteredCluster(clusterConfiguration(clusterUri1, clusterUri2));
    ClusterMember me = members.getCurrentMember();
    assertNotNull(me);
    assertEquals(1, me.getInstanceId().toIntegerIndex());
    assertEquals(clusterId1, me.getInstanceId());
}
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 18 with Cluster

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

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

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

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