use of org.neo4j.cluster.timeout.TimeoutStrategy in project neo4j by neo4j.
the class HeartbeatStateTest method shouldLogFirstHeartbeatAfterTimeout.
@Test
public void shouldLogFirstHeartbeatAfterTimeout() throws Throwable {
// given
InstanceId instanceId = new InstanceId(1), otherInstance = new InstanceId(2);
ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.getInstance(), "cluster://1", "cluster://2");
configuration.getMembers().put(otherInstance, URI.create("cluster://2"));
AssertableLogProvider internalLog = new AssertableLogProvider(true);
TimeoutStrategy timeoutStrategy = mock(TimeoutStrategy.class);
Timeouts timeouts = new Timeouts(timeoutStrategy);
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, mock(Executor.class), internalLog, mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), timeouts, mock(ElectionCredentialsProvider.class), config);
StateMachines stateMachines = new StateMachines(internalLog, mock(StateMachines.Monitor.class), mock(MessageSource.class), mock(MessageSender.class), timeouts, mock(DelayedDirectExecutor.class), command -> command.run(), instanceId);
stateMachines.addStateMachine(new StateMachine(context.getHeartbeatContext(), HeartbeatMessage.class, HeartbeatState.start, internalLog));
timeouts.tick(0);
when(timeoutStrategy.timeoutFor(any(Message.class))).thenReturn(5L);
// when
stateMachines.process(Message.internal(HeartbeatMessage.join));
stateMachines.process(Message.internal(HeartbeatMessage.i_am_alive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.CREATED_BY, otherInstance.toString()));
for (int i = 1; i <= 15; i++) {
timeouts.tick(i);
}
// then
verify(timeoutStrategy, times(3)).timeoutTriggered(argThat(new MessageArgumentMatcher<>().onMessageType(HeartbeatMessage.timed_out)));
internalLog.assertExactly(inLog(HeartbeatState.class).debug("Received timed out for server 2"), inLog(HeartbeatContext.class).info("1(me) is now suspecting 2"), inLog(HeartbeatState.class).debug("Received timed out for server 2"), inLog(HeartbeatState.class).debug("Received timed out for server 2"));
internalLog.clear();
// when
stateMachines.process(Message.internal(HeartbeatMessage.i_am_alive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.CREATED_BY, otherInstance.toString()));
// then
internalLog.assertExactly(inLog(HeartbeatState.class).debug("Received i_am_alive[2] after missing 3 (15ms)"));
}
Aggregations