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