Search in sources :

Example 11 with Timeouts

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());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) ArrayList(java.util.ArrayList) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) HeartbeatListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatListener) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) Test(org.junit.Test)

Aggregations

Timeouts (org.neo4j.cluster.timeout.Timeouts)11 Test (org.junit.Test)10 InstanceId (org.neo4j.cluster.InstanceId)10 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)8 Executor (java.util.concurrent.Executor)7 Config (org.neo4j.kernel.configuration.Config)7 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)6 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)6 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)6 LearnerContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext)5 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)5 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)5 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)4 ArrayList (java.util.ArrayList)3 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)3 ClusterMessage (org.neo4j.cluster.protocol.cluster.ClusterMessage)3 ElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ElectionCredentialsProvider)2 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)2 HashSet (java.util.HashSet)1 StateMachines (org.neo4j.cluster.StateMachines)1