use of org.neo4j.cluster.InstanceId 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.InstanceId in project neo4j by neo4j.
the class ElectionContextTest method electionBeingForgottenMustIncreaseElectionId.
@Test
public void electionBeingForgottenMustIncreaseElectionId() throws Exception {
// Given
final String coordinatorRole = "coordinator";
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);
ElectionContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config).getElectionContext();
ElectionContext.VoteRequest voteRequestBefore = context.voteRequestForRole(new ElectionRole(coordinatorRole));
context.forgetElection(coordinatorRole);
ElectionContext.VoteRequest voteRequestAfter = context.voteRequestForRole(new ElectionRole(coordinatorRole));
assertEquals(voteRequestBefore.getVersion() + 1, voteRequestAfter.getVersion());
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ElectionContextTest method testElectionNotOkMoreThanQuorumFailed.
@Test
public void testElectionNotOkMoreThanQuorumFailed() {
Set<InstanceId> failed = new HashSet<InstanceId>();
failed.add(new InstanceId(1));
failed.add(new InstanceId(2));
baseTestForElectionOk(failed, true);
}
use of org.neo4j.cluster.InstanceId 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.InstanceId in project neo4j by neo4j.
the class SnapshotStateTest method testNoSnapshotRequestIfCoordinatorInExistingCluster.
@Test
public void testNoSnapshotRequestIfCoordinatorInExistingCluster() throws Throwable {
Map<InstanceId, URI> extraMember = new HashMap<InstanceId, URI>();
URI other = URI.create("cluster://other");
extraMember.put(new InstanceId(2), other);
baseNoSendTest(extraMember);
}
Aggregations