Search in sources :

Example 1 with LearnerMessage

use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage in project neo4j by neo4j.

the class HeartbeatStateTest method shouldAddInstanceIdHeaderInCatchUpMessages.

@Test
public void shouldAddInstanceIdHeaderInCatchUpMessages() throws Throwable {
    // Given
    InstanceId instanceId = new InstanceId(1);
    HeartbeatState heartbeat = HeartbeatState.heartbeat;
    ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.getInstance(), "cluster://1", "cluster://2");
    configuration.joined(instanceId, URI.create("cluster://1"));
    InstanceId otherInstance = new InstanceId(2);
    configuration.joined(otherInstance, URI.create("cluster://2"));
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(Executor.class), NullLogProvider.getInstance(), Mockito.mock(ObjectInputStreamFactory.class), Mockito.mock(ObjectOutputStreamFactory.class), Mockito.mock(AcceptorInstanceStore.class), Mockito.mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    int lastDeliveredInstanceId = 100;
    context.getLearnerContext().setLastDeliveredInstanceId(lastDeliveredInstanceId);
    // This gap will trigger the catchUp message that we'll test against
    lastDeliveredInstanceId += 20;
    HeartbeatContext heartbeatContext = context.getHeartbeatContext();
    Message received = Message.internal(HeartbeatMessage.i_am_alive, new HeartbeatMessage.IAmAliveState(otherInstance));
    received.setHeader(Message.FROM, "cluster://2").setHeader(Message.INSTANCE_ID, "2").setHeader("last-learned", Integer.toString(lastDeliveredInstanceId));
    // When
    MessageHolder holder = mock(MessageHolder.class);
    heartbeat.handle(heartbeatContext, received, holder);
    // Then
    verify(holder, times(1)).offer(Matchers.argThat(new MessageArgumentMatcher<LearnerMessage>().onMessageType(LearnerMessage.catchUp).withHeader(Message.INSTANCE_ID, "2")));
}
Also used : LearnerMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Executor(java.util.concurrent.Executor) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) MessageArgumentMatcher(org.neo4j.cluster.protocol.MessageArgumentMatcher) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) Test(org.junit.Test)

Aggregations

Executor (java.util.concurrent.Executor)1 Test (org.junit.Test)1 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)1 InstanceId (org.neo4j.cluster.InstanceId)1 Message (org.neo4j.cluster.com.message.Message)1 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)1 MessageArgumentMatcher (org.neo4j.cluster.protocol.MessageArgumentMatcher)1 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)1 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)1 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)1 LearnerMessage (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage)1 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)1 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)1 ElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ElectionCredentialsProvider)1 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)1 Timeouts (org.neo4j.cluster.timeout.Timeouts)1 Config (org.neo4j.kernel.configuration.Config)1