use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ClusterContextImplTest method shouldGracefullyHandleEmptyDiscoveryHeader.
@Test
public void shouldGracefullyHandleEmptyDiscoveryHeader() throws Exception {
// Given
InstanceId me = new InstanceId(1);
InstanceId joining = new InstanceId(2);
CommonContextState commonContextState = mock(CommonContextState.class, RETURNS_MOCKS);
Timeouts timeouts = mock(Timeouts.class);
Executor executor = mock(Executor.class);
HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), timeouts, executor, mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), heartbeatContext, mock(Config.class));
ClusterMessage.ConfigurationRequestState request = mock(ClusterMessage.ConfigurationRequestState.class);
when(request.getJoiningId()).thenReturn(joining);
// When
// Instance 2 contacts us with a request but it is empty
context.addContactingInstance(request, "");
// Then
// The discovery header we generate should still contain that instance
assertEquals("2", context.generateDiscoveryHeader());
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ClusterContextImplTest method nonElectorFailingMustNotCauseElectorVersionToBeReset.
/*
* This test ensures that an instance that is marked as failed has its elector version reset. This means that
* the instance, once it comes back, will still be able to do elections even if it lost state
*/
@Test
public void nonElectorFailingMustNotCauseElectorVersionToBeReset() throws Exception {
// Given
InstanceId me = new InstanceId(1);
InstanceId elector = new InstanceId(2);
CommonContextState commonContextState = mock(CommonContextState.class, RETURNS_MOCKS);
Timeouts timeouts = mock(Timeouts.class);
Executor executor = mock(Executor.class);
HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
ArgumentCaptor<HeartbeatListener> listenerCaptor = ArgumentCaptor.forClass(HeartbeatListener.class);
ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), timeouts, executor, mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), heartbeatContext, mock(Config.class));
verify(heartbeatContext).addHeartbeatListener(listenerCaptor.capture());
HeartbeatListener theListener = listenerCaptor.getValue();
// This means instance 2 was the elector at version 8
context.setLastElector(elector);
context.setLastElectorVersion(8);
// When
theListener.failed(new InstanceId(3));
// Then
assertEquals(context.getLastElector(), elector);
assertEquals(context.getLastElectorVersion(), 8);
}
use of org.neo4j.cluster.InstanceId 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());
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ProposerContextImplTest method limitedAcceptors.
private int limitedAcceptors(int maxAcceptors, List<InstanceId> alive) {
CommonContextState commonContextState = new CommonContextState(null, maxAcceptors);
HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
when(heartbeatContext.getAlive()).thenReturn(alive);
// when
ProposerContextImpl proposerContext = new ProposerContextImpl(new InstanceId(1), commonContextState, null, null, null, heartbeatContext);
return proposerContext.getAcceptors().size();
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ProposerContextImplTest method shouldCalculateMajorityOfAcceptors.
@Test
public void shouldCalculateMajorityOfAcceptors() throws Exception {
ProposerContextImpl proposerContext = new ProposerContextImpl(new InstanceId(1), null, null, null, null, null);
assertEquals(1, proposerContext.getMinimumQuorumSize(acceptorUris(1)));
assertEquals(2, proposerContext.getMinimumQuorumSize(acceptorUris(2)));
assertEquals(2, proposerContext.getMinimumQuorumSize(acceptorUris(3)));
assertEquals(3, proposerContext.getMinimumQuorumSize(acceptorUris(4)));
assertEquals(3, proposerContext.getMinimumQuorumSize(acceptorUris(5)));
assertEquals(4, proposerContext.getMinimumQuorumSize(acceptorUris(6)));
assertEquals(4, proposerContext.getMinimumQuorumSize(acceptorUris(7)));
}
Aggregations