use of org.neo4j.cluster.member.ClusterMemberEvents in project neo4j by neo4j.
the class HighAvailabilityMemberStateMachineTest method shouldSwitchToToSlaveOnMasterAvailableForSomeoneElse.
@Test
public void shouldSwitchToToSlaveOnMasterAvailableForSomeoneElse() throws Throwable {
// Given
InstanceId me = new InstanceId(1);
HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
ClusterMemberEvents events = mock(ClusterMemberEvents.class);
ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events);
stateMachine.init();
ClusterMemberListener memberListener = memberListenerContainer.get();
HAStateChangeListener probe = new HAStateChangeListener();
stateMachine.addHighAvailabilityMemberListener(probe);
// When
memberListener.memberIsAvailable(MASTER, new InstanceId(2), URI.create("ha://whatever"), StoreId.DEFAULT);
// Then
assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.TO_SLAVE));
assertThat(probe.masterIsAvailable, is(true));
}
use of org.neo4j.cluster.member.ClusterMemberEvents 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());
}
use of org.neo4j.cluster.member.ClusterMemberEvents 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)))));
}
use of org.neo4j.cluster.member.ClusterMemberEvents 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))));
}
use of org.neo4j.cluster.member.ClusterMemberEvents 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))));
}
Aggregations