use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class HeartbeatIAmAliveProcessorTest method shouldNotCreateHeartbeatsForNonExistingInstances.
@Test
public void shouldNotCreateHeartbeatsForNonExistingInstances() throws Exception {
// GIVEN
MessageHolder outgoing = mock(MessageHolder.class);
ClusterContext mockContext = mock(ClusterContext.class);
ClusterConfiguration mockConfiguration = mock(ClusterConfiguration.class);
when(mockConfiguration.getMembers()).thenReturn(new HashMap<InstanceId, URI>() {
{
put(new InstanceId(1), URI.create("ha://1"));
put(new InstanceId(2), URI.create("ha://2"));
}
});
when(mockContext.getConfiguration()).thenReturn(mockConfiguration);
HeartbeatIAmAliveProcessor processor = new HeartbeatIAmAliveProcessor(outgoing, mockContext);
Message incoming = Message.to(mock(MessageType.class), URI.create("ha://someAwesomeInstanceInJapan")).setHeader(Message.FROM, "some://value").setHeader(Message.INSTANCE_ID, "5");
// WHEN
processor.process(incoming);
// THEN
verifyZeroInteractions(outgoing);
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class HeartbeatStateTest method shouldAddInstanceIdHeaderInCatchUpMessages.
@Test
public void shouldAddInstanceIdHeaderInCatchUpMessages() throws Throwable {
// Given
InstanceId instanceId = new InstanceId(1);
HeartbeatState heartbeat = HeartbeatState.heartbeat;
ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.getInstance(), "cluster://1", "cluster://2");
configuration.joined(instanceId, URI.create("cluster://1"));
InstanceId otherInstance = new InstanceId(2);
configuration.joined(otherInstance, URI.create("cluster://2"));
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(Executor.class), NullLogProvider.getInstance(), Mockito.mock(ObjectInputStreamFactory.class), Mockito.mock(ObjectOutputStreamFactory.class), Mockito.mock(AcceptorInstanceStore.class), Mockito.mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
int lastDeliveredInstanceId = 100;
context.getLearnerContext().setLastDeliveredInstanceId(lastDeliveredInstanceId);
// This gap will trigger the catchUp message that we'll test against
lastDeliveredInstanceId += 20;
HeartbeatContext heartbeatContext = context.getHeartbeatContext();
Message received = Message.internal(HeartbeatMessage.i_am_alive, new HeartbeatMessage.IAmAliveState(otherInstance));
received.setHeader(Message.FROM, "cluster://2").setHeader(Message.INSTANCE_ID, "2").setHeader("last-learned", Integer.toString(lastDeliveredInstanceId));
// When
MessageHolder holder = mock(MessageHolder.class);
heartbeat.handle(heartbeatContext, received, holder);
// Then
verify(holder, times(1)).offer(Matchers.argThat(new MessageArgumentMatcher<LearnerMessage>().onMessageType(LearnerMessage.catchUp).withHeader(Message.INSTANCE_ID, "2")));
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class ArbiterBootstrapperIT method before.
@Before
public void before() throws Exception {
directory = testDirectory.directory("temp");
life = new LifeSupport();
// So that the clients get started as they are added
life.start();
clients = new ClusterClient[2];
for (int i = 1; i <= clients.length; i++) {
Map<String, String> config = stringMap();
config.put(cluster_server.name(), ":" + (5000 + i));
config.put(server_id.name(), "" + i);
config.put(initial_hosts.name(), ":5001");
LifeSupport moduleLife = new LifeSupport();
ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.embeddedDefaults(config), NullLogService.getInstance(), new ServerIdElectionCredentialsProvider());
ClusterClient client = clusterClientModule.clusterClient;
CountDownLatch latch = new CountDownLatch(1);
client.addClusterListener(new ClusterListener.Adapter() {
@Override
public void enteredCluster(ClusterConfiguration configuration) {
latch.countDown();
client.removeClusterListener(this);
}
});
life.add(moduleLife);
clients[i - 1] = client;
assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
}
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class ClusterInstance method newClusterInstance.
public static ClusterInstance newClusterInstance(InstanceId id, URI uri, Monitors monitors, ClusterConfiguration configuration, int maxSurvivableFailedMembers, LogProvider logging) {
MultiPaxosServerFactory factory = new MultiPaxosServerFactory(configuration, logging, monitors.newMonitor(StateMachines.Monitor.class));
ClusterInstanceInput input = new ClusterInstanceInput();
ClusterInstanceOutput output = new ClusterInstanceOutput(uri);
ObjectStreamFactory objStreamFactory = new ObjectStreamFactory();
ProverTimeouts timeouts = new ProverTimeouts(uri);
InMemoryAcceptorInstanceStore acceptorInstances = new InMemoryAcceptorInstanceStore();
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(maxSurvivableFailedMembers);
DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
final MultiPaxosContext context = new MultiPaxosContext(id, Iterables.<ElectionRole, ElectionRole>iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(configuration.getName(), logging, configuration.getMemberURIs()), executor, logging, objStreamFactory, objStreamFactory, acceptorInstances, timeouts, new DefaultElectionCredentialsProvider(id, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()), config);
context.getClusterContext().setBoundAt(uri);
SnapshotContext snapshotContext = new SnapshotContext(context.getClusterContext(), context.getLearnerContext());
DelayedDirectExecutor taskExecutor = new DelayedDirectExecutor(logging);
ProtocolServer ps = factory.newProtocolServer(id, input, output, DIRECT_EXECUTOR, taskExecutor, timeouts, context, snapshotContext);
return new ClusterInstance(DIRECT_EXECUTOR, logging, factory, ps, context, acceptorInstances, timeouts, input, output, uri);
}
use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.
the class Prover method bootstrapCluster.
private void bootstrapCluster() throws Exception {
String instance1 = "cluster://localhost:5001";
String instance2 = "cluster://localhost:5002";
String instance3 = "cluster://localhost:5003";
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), instance1, instance2, instance3);
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI(instance1), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI(instance2), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI(instance3), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.create, new URI(instance3), "defaultcluster").setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance3)));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance2), new Object[] { "defaultcluster", new URI[] { new URI(instance3) } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance2)));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance1), new Object[] { "defaultcluster", new URI[] { new URI(instance3) } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance1)));
state.addPendingActions(new InstanceCrashedAction(instance3));
unexploredKnownStates.add(state);
db.newState(state);
}
Aggregations