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")));
}
Aggregations