Search in sources :

Example 16 with ClusterMemberEvents

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

the class HighAvailabilityMemberStateMachineTest method whenInToSlaveStateLosingQuorumShouldPutInPending.

@Test
public void whenInToSlaveStateLosingQuorumShouldPutInPending() 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.memberIsAvailable(MASTER, other, URI.create("ha://whatever"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.TO_SLAVE));
    // 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 17 with ClusterMemberEvents

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

the class HAStateMachineIllegalTransitionsTest method setup.

@Before
public void setup() throws Throwable {
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    HighAvailabilityMemberStateMachineTest.ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    election = mock(Election.class);
    stateMachine = buildMockedStateMachine(context, events, election);
    stateMachine.init();
    memberListener = memberListenerContainer.get();
    HighAvailabilityMemberStateMachineTest.HAStateChangeListener probe = new HighAvailabilityMemberStateMachineTest.HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) Election(org.neo4j.cluster.protocol.election.Election) Before(org.junit.Before)

Example 18 with ClusterMemberEvents

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

the class HighAvailabilityMemberStateMachineTest method shouldRemainToPendingOnMasterElectedForSomeoneElse.

@Test
public void shouldRemainToPendingOnMasterElectedForSomeoneElse() 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();
    // When
    memberListener.coordinatorIsElected(new InstanceId(2));
    // 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)

Example 19 with ClusterMemberEvents

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

the class HighAvailabilityMemberStateMachineTest method whenInSlaveStateWith3MemberClusterLosingMasterShouldPutInPending.

@Test
public void whenInSlaveStateWith3MemberClusterLosingMasterShouldPutInPending() 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(otherSlave), 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);
    memberListener.memberIsAvailable(SLAVE, otherSlave, URI.create("ha://whatever2"), 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 20 with ClusterMemberEvents

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

the class HighAvailabilityMemberStateMachineTest method shouldMoveToToMasterFromPendingOnMasterElectedForItself.

@Test
public void shouldMoveToToMasterFromPendingOnMasterElectedForItself() 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();
    // When
    memberListener.coordinatorIsElected(me);
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.TO_MASTER));
}
Also used : ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Aggregations

ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)27 Test (org.junit.Test)26 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)19 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)14 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)14 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)13 InstanceId (org.neo4j.cluster.InstanceId)12 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)7 ObservedClusterMembers (org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers)7 AvailabilityRequirement (org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement)5 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)3 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Election (org.neo4j.cluster.protocol.election.Election)1 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)1