Search in sources :

Example 11 with MessageHolder

use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.

the class LearnerStateTest method learnerReceivingLearnFailedShouldLogIt.

@Test
public void learnerReceivingLearnFailedShouldLogIt() throws Throwable {
    // Given
    LearnerState state = LearnerState.learner;
    LearnerContext ctx = mock(LearnerContext.class);
    MessageHolder outgoing = mock(MessageHolder.class);
    InstanceId paxosInstanceIdIAskedFor = new InstanceId(4);
    Message<LearnerMessage> theLearnFailure = Message.to(LearnerMessage.learnFailed, URI.create("c:/1")).setHeader(Message.FROM, "c:/2").setHeader(InstanceId.INSTANCE, "4");
    when(ctx.getPaxosInstance(paxosInstanceIdIAskedFor)).thenReturn(new PaxosInstance(mock(PaxosInstanceStore.class), paxosInstanceIdIAskedFor));
    when(ctx.getMemberURIs()).thenReturn(Collections.singletonList(URI.create("c:/2")));
    // When
    state.handle(ctx, theLearnFailure, outgoing);
    // Then
    // verify that the failure was logged
    verify(ctx, times(1)).notifyLearnMiss(paxosInstanceIdIAskedFor);
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Test(org.junit.Test)

Example 12 with MessageHolder

use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.

the class ProposerStateTest method something.

@Test
public void something() throws Throwable {
    Object acceptorValue = new Object();
    Object bookedValue = new Object();
    org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(42);
    PaxosInstanceStore paxosInstanceStore = new PaxosInstanceStore();
    ProposerContext context = Mockito.mock(ProposerContext.class);
    when(context.getPaxosInstance(instanceId)).thenReturn(paxosInstanceStore.getPaxosInstance(instanceId));
    when(context.getMinimumQuorumSize(Mockito.anyList())).thenReturn(2);
    // The instance is closed
    // the instance
    PaxosInstance paxosInstance = new PaxosInstance(paxosInstanceStore, instanceId);
    paxosInstance.propose(2001, Iterables.asList(Iterables.<URI, URI>iterable(create("http://something1"), create("http://something2"), create("http://something3"))));
    Message message = Message.to(ProposerMessage.promise, create("http://something1"), new ProposerMessage.PromiseState(2001, acceptorValue));
    message.setHeader(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString());
    MessageHolder mockHolder = mock(MessageHolder.class);
    ProposerState.proposer.handle(context, message, mockHolder);
}
Also used : Message(org.neo4j.cluster.com.message.Message) URI(java.net.URI) TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Test(org.junit.Test)

Example 13 with MessageHolder

use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.

the class ElectionStateTest method testElectionRequestIsRejectedIfNoQuorum.

@Test
public void testElectionRequestIsRejectedIfNoQuorum() throws Throwable {
    ElectionContext context = mock(ElectionContext.class);
    ClusterContext clusterContextMock = mock(ClusterContext.class);
    when(context.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
    when(context.electionOk()).thenReturn(false);
    when(clusterContextMock.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
    MessageHolder holder = mock(MessageHolder.class);
    election.handle(context, Message.<ElectionMessage>internal(performRoleElections), holder);
    verifyZeroInteractions(holder);
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) Test(org.junit.Test)

Example 14 with MessageHolder

use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.

the class AtomicBroadcastStateTest method shouldNotBroadcastWhenHavingNoQuorumNoCoordinator.

@Test
public void shouldNotBroadcastWhenHavingNoQuorumNoCoordinator() throws Throwable {
    // GIVEN
    AtomicBroadcastContext context = mock(AtomicBroadcastContext.class);
    when(context.hasQuorum()).thenReturn(false);
    InstanceId coordinator = id(1);
    when(context.getCoordinator()).thenReturn(coordinator);
    when(context.getUriForId(coordinator)).thenReturn(uri(1));
    when(context.getLog(AtomicBroadcastState.class)).thenReturn(NullLog.getInstance());
    final List<Message<?>> messages = new ArrayList<>(1);
    MessageHolder outgoing = new MessageHolder() {

        @Override
        public void offer(Message<? extends MessageType> message) {
            messages.add(message);
        }
    };
    // WHEN
    broadcasting.handle(context, message(1), outgoing);
    // THEN
    assertEquals(0, messages.size());
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) ArrayList(java.util.ArrayList) MessageType(org.neo4j.cluster.com.message.MessageType) Test(org.junit.Test)

Example 15 with MessageHolder

use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.

the class LearnerStateTest method shouldUseLastKnownOnlineClusterMemberAndSetTimeoutForCatchup.

@Test
public void shouldUseLastKnownOnlineClusterMemberAndSetTimeoutForCatchup() throws Throwable {
    // Given
    LearnerState state = LearnerState.learner;
    LearnerContext ctx = mock(LearnerContext.class);
    MessageHolder outgoing = mock(MessageHolder.class);
    org.neo4j.cluster.InstanceId upToDateClusterMember = new org.neo4j.cluster.InstanceId(1);
    // What we know
    when(ctx.getLastLearnedInstanceId()).thenReturn(0L);
    when(ctx.getPaxosInstance(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L))).thenReturn(new PaxosInstance(null, new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L)));
    when(ctx.getLastKnownAliveUpToDateInstance()).thenReturn(upToDateClusterMember);
    when(ctx.getUriForId(upToDateClusterMember)).thenReturn(new URI("c:/1"));
    // What we know the cluster knows
    when(ctx.getLastKnownLearnedInstanceInCluster()).thenReturn(1L);
    // When
    Message<LearnerMessage> message = Message.to(LearnerMessage.catchUp, new URI("c:/2"), 2L).setHeader(Message.FROM, "c:/2").setHeader(Message.INSTANCE_ID, "2");
    State newState = state.handle(ctx, message, outgoing);
    // Then
    assertThat(newState, equalTo((State) LearnerState.learner));
    verify(outgoing).offer(Message.to(LearnerMessage.learnRequest, new URI("c:/1"), new LearnerMessage.LearnRequestState()).setHeader(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, Long.toString(1L)));
    verify(ctx).setTimeout("learn", Message.timeout(LearnerMessage.learnTimedout, message));
}
Also used : URI(java.net.URI) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) State(org.neo4j.cluster.statemachine.State) Test(org.junit.Test)

Aggregations

MessageHolder (org.neo4j.cluster.com.message.MessageHolder)29 Test (org.junit.Test)28 Message (org.neo4j.cluster.com.message.Message)19 InstanceId (org.neo4j.cluster.InstanceId)14 URI (java.net.URI)11 MessageType (org.neo4j.cluster.com.message.MessageType)11 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)10 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)8 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)5 MessageArgumentMatcher (org.neo4j.cluster.protocol.MessageArgumentMatcher)5 AtomicBroadcastMessage (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AtomicBroadcastMessage)5 ClusterMessage (org.neo4j.cluster.protocol.cluster.ClusterMessage)5 TrackingMessageHolder (org.neo4j.cluster.com.message.TrackingMessageHolder)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 HashMap (java.util.HashMap)2 Executor (java.util.concurrent.Executor)2 ConfigurationRequestState (org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState)2