use of org.neo4j.cluster.timeout.Timeouts in project neo4j by neo4j.
the class HeartbeatContextImplTest method shouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor.
@Test
public void shouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor() throws Throwable {
// Given
InstanceId me = new InstanceId(1);
InstanceId failedMachine = new InstanceId(2);
InstanceId goodMachine = new InstanceId(3);
Timeouts timeouts = mock(Timeouts.class);
CommonContextState commonState = mock(CommonContextState.class);
ClusterConfiguration configuration = mock(ClusterConfiguration.class);
when(commonState.configuration()).thenReturn(configuration);
when(configuration.getMembers()).thenReturn(members(3));
when(configuration.getMemberIds()).thenReturn(ids(3));
final List<Runnable> runnables = new ArrayList<>();
HeartbeatContext context = new HeartbeatContextImpl(me, commonState, NullLogProvider.getInstance(), timeouts, new DelayedDirectExecutor(NullLogProvider.getInstance()) {
@Override
public synchronized void execute(Runnable command) {
runnables.add(command);
}
});
context.addHeartbeatListener(mock(HeartbeatListener.class));
context.suspicions(goodMachine, new HashSet<>(singletonList(failedMachine)));
// fail
context.suspect(failedMachine);
// alive
context.alive(failedMachine);
// Then
// fail + alive
assertEquals(2, runnables.size());
}
Aggregations