Search in sources :

Example 26 with HeartbeatContext

use of org.neo4j.cluster.protocol.heartbeat.HeartbeatContext in project neo4j by neo4j.

the class ClusterContextTest method testElectionVersionIsUpdatedOnElectionFromOtherAndIgnoredIfOld.

@Test
public void testElectionVersionIsUpdatedOnElectionFromOtherAndIgnoredIfOld() throws Exception {
    final String coordinatorRole = "coordinator";
    final InstanceId me = new InstanceId(1);
    final InstanceId winner = new InstanceId(2);
    final InstanceId elector = new InstanceId(2);
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    when(heartbeatContext.getFailed()).thenReturn(Collections.<InstanceId>emptySet());
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.<ElectionRole, ElectionRole>iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), new Executor() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    }, NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    ClusterContext context = multiPaxosContext.getClusterContext();
    ClusterListener listener = mock(ClusterListener.class);
    context.addClusterListener(listener);
    context.elected(coordinatorRole, winner, elector, 2);
    verify(listener, times(1)).elected(coordinatorRole, winner, null);
    context.elected(coordinatorRole, winner, elector, 3);
    verify(listener, times(2)).elected(coordinatorRole, winner, null);
    context.elected(coordinatorRole, winner, elector, 2);
    verifyNoMoreInteractions(listener);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) Executor(java.util.concurrent.Executor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) 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

HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)26 InstanceId (org.neo4j.cluster.InstanceId)22 Test (org.junit.Test)21 Timeouts (org.neo4j.cluster.timeout.Timeouts)16 Config (org.neo4j.kernel.configuration.Config)15 Executor (java.util.concurrent.Executor)13 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)13 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)13 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)11 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)10 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)9 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)8 LinkedList (java.util.LinkedList)5 LearnerContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext)5 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)5 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 ElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ElectionCredentialsProvider)4 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)4 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)3