use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class NetworkMock method newTestProtocolServer.
protected TestProtocolServer newTestProtocolServer(int serverId, URI serverUri) {
ProtocolServerFactory protocolServerFactory = new MultiPaxosServerFactory(new ClusterConfiguration("default", logService.getInternalLogProvider()), logService.getInternalLogProvider(), monitors.newMonitor(StateMachines.Monitor.class));
ServerIdElectionCredentialsProvider electionCredentialsProvider = new ServerIdElectionCredentialsProvider();
electionCredentialsProvider.listeningAt(serverUri);
TestProtocolServer protocolServer = new TestProtocolServer(logService.getInternalLogProvider(), timeoutStrategy, protocolServerFactory, serverUri, new InstanceId(serverId), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
protocolServer.addStateTransitionListener(new StateTransitionLogger(logService.getInternalLogProvider(), new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory())));
return protocolServer;
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class MultiPaxosContextTest method shouldDeepClone.
@Test
public void shouldDeepClone() throws Exception {
// Given
ObjectStreamFactory objStream = new ObjectStreamFactory();
AcceptorInstanceStore acceptorInstances = mock(AcceptorInstanceStore.class);
Executor executor = mock(Executor.class);
Timeouts timeouts = mock(Timeouts.class);
ClusterConfiguration clusterConfig = new ClusterConfiguration("myCluster", NullLogProvider.getInstance());
ElectionCredentialsProvider electionCredentials = mock(ElectionCredentialsProvider.class);
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.<ElectionRole>emptyList(), clusterConfig, executor, NullLogProvider.getInstance(), objStream, objStream, acceptorInstances, timeouts, electionCredentials, config);
// When
MultiPaxosContext snapshot = ctx.snapshot(NullLogProvider.getInstance(), timeouts, executor, acceptorInstances, objStream, objStream, electionCredentials);
// Then
assertEquals(ctx, snapshot);
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class MultiPaxosServer method config.
public void config() {
ClusterConfiguration configuration = ((ClusterContext) server.getStateMachines().getStateMachine(ClusterMessage.class).getContext()).getConfiguration();
Collection<InstanceId> failed = ((HeartbeatContext) server.getStateMachines().getStateMachine(HeartbeatMessage.class).getContext()).getFailed();
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration 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.ClusterConfiguration 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());
}
Aggregations