Search in sources :

Example 6 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldNotBroadcastIfMasterAndReceivesSlaveIsAvailable.

@Test
public void shouldNotBroadcastIfMasterAndReceivesSlaveIsAvailable() throws Exception {
    // Given
    ClusterMemberAvailability availability = mock(ClusterMemberAvailability.class);
    HighAvailabilityModeSwitcher toTest = createModeSwitcher(availability);
    // When
    toTest.slaveIsAvailable(new HighAvailabilityMemberChangeEvent(HighAvailabilityMemberState.MASTER, HighAvailabilityMemberState.MASTER, new InstanceId(2), URI.create("ha://someone")));
    // Then
    /*
           * The second argument to memberIsAvailable below is null because it has not been set yet. This would require
           * a switch to master which we don't do here.
           */
    verifyZeroInteractions(availability);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) Test(org.junit.Test)

Example 7 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class HAStateMachineIllegalTransitionsTest method shouldProperlyHandleConflictingMasterAvailableMessage.

@Test
public void shouldProperlyHandleConflictingMasterAvailableMessage() throws Throwable {
    /*
         * If the instance is currently in TO_MASTER and a masterIsAvailable comes for another instance, then
         * this instance should transition to PENDING and ask for an election.
         */
    // Given
    InstanceId rogue = new InstanceId(2);
    // sanity check of starting state
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    // when
    // It receives available master without having gone through TO_MASTER
    memberListener.coordinatorIsElected(me);
    // then
    // sanity check it transitioned to TO_MASTER
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.TO_MASTER));
    // when
    // it receives a masterIsAvailable for another instance
    memberListener.memberIsAvailable(MASTER, rogue, URI.create("ha://someUri"), StoreId.DEFAULT);
    // then
    assertPendingStateAndElectionsAsked();
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Test(org.junit.Test)

Example 8 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class HighAvailabilityMemberStateMachineTest method whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending.

@Test
public void whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId other1 = new InstanceId(2);
    InstanceId other2 = new InstanceId(3);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    List<InstanceId> otherInstances = new LinkedList();
    otherInstances.add(other1);
    otherInstances.add(other2);
    ObservedClusterMembers members = mockClusterMembers(me, emptyList(), otherInstances);
    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.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) LinkedList(java.util.LinkedList) ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) Test(org.junit.Test)

Example 9 with InstanceId

use of org.neo4j.cluster.InstanceId 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 10 with InstanceId

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

Aggregations

InstanceId (org.neo4j.cluster.InstanceId)154 Test (org.junit.Test)129 URI (java.net.URI)47 Config (org.neo4j.kernel.configuration.Config)37 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)36 Timeouts (org.neo4j.cluster.timeout.Timeouts)32 Executor (java.util.concurrent.Executor)28 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)28 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)27 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)27 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)27 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)24 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)18 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)16 Message (org.neo4j.cluster.com.message.Message)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)13 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)12 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)12