Search in sources :

Example 6 with ClusterMemberListener

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

the class HighAvailabilityMemberStateMachineTest method whenInToMasterStateLosingQuorumShouldPutInPending.

@Test
public void whenInToMasterStateLosingQuorumShouldPutInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other = new InstanceId(2);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), singletonList(other));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(me);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.TO_MASTER));
    // When
    memberListener.memberIsFailed(new InstanceId(2));
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) Test(org.junit.Test)

Example 7 with ClusterMemberListener

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

the class HighAvailabilityMemberStateMachineTest method whenInSlaveStateLosingOtherSlaveShouldNotPutInPending.

@Test
public void whenInSlaveStateLosingOtherSlaveShouldNotPutInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId master = new InstanceId(2);
    InstanceId otherSlave = new InstanceId(3);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, singletonList(master), singletonList(otherSlave));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.memberIsAvailable(MASTER, master, URI.create("ha://whatever"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, me, URI.create("ha://whatever3"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, otherSlave, URI.create("ha://whatever2"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.SLAVE));
    // When
    memberListener.memberIsFailed(otherSlave);
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.SLAVE));
    assertThat(probe.instanceStops, is(false));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Example 8 with ClusterMemberListener

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

the class HighAvailabilityMemberStateMachineTest method whenInMasterStateLosingQuorumFromTwoInstancesShouldRemainMaster.

@Test
public void whenInMasterStateLosingQuorumFromTwoInstancesShouldRemainMaster() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other = new InstanceId(2);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), singletonList(other));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(me);
    memberListener.memberIsAvailable(MASTER, me, URI.create("ha://whatever"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
    // When
    memberListener.memberIsFailed(new InstanceId(2));
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(false));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Example 9 with ClusterMemberListener

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

the class HighAvailabilityMemberStateMachineTest method whenInSlaveStateWith2MemberClusterLosingMasterShouldPutInPending.

@Test
public void whenInSlaveStateWith2MemberClusterLosingMasterShouldPutInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId master = new InstanceId(2);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), singletonList(master));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(master);
    memberListener.memberIsAvailable(MASTER, master, URI.create("ha://whatever"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, me, URI.create("ha://whatever3"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.SLAVE));
    // When
    memberListener.memberIsFailed(master);
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) Test(org.junit.Test)

Example 10 with ClusterMemberListener

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

the class HighAvailabilityMemberStateMachineTest method whenSlaveOnlyIsElectedStayInPending.

@Test
public void whenSlaveOnlyIsElectedStayInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, true);
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    // When
    memberListener.coordinatorIsElected(me);
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)18 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)18 InstanceId (org.neo4j.cluster.InstanceId)11 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)7 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)7 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)7 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)7 ObservedClusterMembers (org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers)7 AvailabilityRequirement (org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement)5 LinkedList (java.util.LinkedList)1