use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.
the class ElectionContextTest method testElectionNotOkQuorumFailedFourInstances.
@Test
public void testElectionNotOkQuorumFailedFourInstances() {
Set<InstanceId> failed = new HashSet<InstanceId>();
failed.add(new InstanceId(2));
failed.add(new InstanceId(3));
Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
members.put(new InstanceId(1), URI.create("server1"));
members.put(new InstanceId(2), URI.create("server2"));
members.put(new InstanceId(3), URI.create("server3"));
members.put(new InstanceId(4), URI.create("server4"));
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
when(clusterConfiguration.getMembers()).thenReturn(members);
ClusterContext clusterContext = mock(ClusterContext.class);
when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
context.getHeartbeatContext().getFailed().addAll(failed);
ElectionContext toTest = context.getElectionContext();
assertFalse(toTest.electionOk());
}
use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.
the class ElectionContextTest method testElectionNotOkQuorumFailedFiveInstances.
@Test
public void testElectionNotOkQuorumFailedFiveInstances() {
Set<InstanceId> failed = new HashSet<InstanceId>();
failed.add(new InstanceId(2));
failed.add(new InstanceId(3));
failed.add(new InstanceId(4));
Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
members.put(new InstanceId(1), URI.create("server1"));
members.put(new InstanceId(2), URI.create("server2"));
members.put(new InstanceId(3), URI.create("server3"));
members.put(new InstanceId(4), URI.create("server4"));
members.put(new InstanceId(5), URI.create("server5"));
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
when(clusterConfiguration.getMembers()).thenReturn(members);
ClusterContext clusterContext = mock(ClusterContext.class);
when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
context.getHeartbeatContext().getFailed().addAll(failed);
ElectionContext toTest = context.getElectionContext();
assertFalse(toTest.electionOk());
}
use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.
the class ElectionStateTest method testElectionRequestIsRejectedIfNoQuorum.
@Test
public void testElectionRequestIsRejectedIfNoQuorum() throws Throwable {
ElectionContext context = mock(ElectionContext.class);
ClusterContext clusterContextMock = mock(ClusterContext.class);
when(context.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
when(context.electionOk()).thenReturn(false);
when(clusterContextMock.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
MessageHolder holder = mock(MessageHolder.class);
election.handle(context, Message.<ElectionMessage>internal(performRoleElections), holder);
verifyZeroInteractions(holder);
}
use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.
the class DefaultWinnerStrategyTest method shouldNotPickAWinnerIfAllVotesAreForIneligibleCandidates.
@Test
public void shouldNotPickAWinnerIfAllVotesAreForIneligibleCandidates() {
// given
InstanceId instanceOne = new InstanceId(1);
InstanceId instanceTwo = new InstanceId(2);
ClusterContext clusterContext = mock(ClusterContext.class);
final Log log = mock(Log.class);
LogProvider logProvider = new LogProvider() {
@Override
public Log getLog(Class loggingClass) {
return log;
}
@Override
public Log getLog(String name) {
return log;
}
};
when(clusterContext.getLog(DefaultWinnerStrategy.class)).thenReturn(logProvider.getLog(DefaultWinnerStrategy.class));
// when
Collection<Vote> votes = Arrays.asList(new Vote(instanceOne, new NotElectableElectionCredentials()), new Vote(instanceTwo, new NotElectableElectionCredentials()));
DefaultWinnerStrategy strategy = new DefaultWinnerStrategy(clusterContext);
org.neo4j.cluster.InstanceId winner = strategy.pickWinner(votes);
// then
assertNull(winner);
}
use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.
the class SnapshotStateTest method baseNoSendTest.
public void baseNoSendTest(Map<InstanceId, URI> extraMembers) throws Throwable {
URI me = URI.create("cluster://me");
Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
final InstanceId myId = new InstanceId(1);
members.put(myId, me);
members.putAll(extraMembers);
ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
when(clusterConfiguration.getMembers()).thenReturn(members);
when(clusterConfiguration.getElected(ClusterConfiguration.COORDINATOR)).thenReturn(myId);
when(clusterConfiguration.getUriForId(myId)).thenReturn(me);
ClusterContext clusterContext = mock(ClusterContext.class);
when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
when(clusterContext.getMyId()).thenReturn(myId);
SnapshotContext context = mock(SnapshotContext.class);
when(context.getClusterContext()).thenReturn(clusterContext);
when(context.getSnapshotProvider()).thenReturn(mock(SnapshotProvider.class));
Message<SnapshotMessage> message = Message.to(SnapshotMessage.refreshSnapshot, me);
MessageHolder outgoing = mock(MessageHolder.class);
SnapshotState newState = (SnapshotState) SnapshotState.ready.handle(context, message, outgoing);
assertThat(newState, equalTo(SnapshotState.ready));
Mockito.verifyZeroInteractions(outgoing);
}
Aggregations