Search in sources :

Example 36 with ClusterConfiguration

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);
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) MessageType(org.neo4j.cluster.com.message.MessageType) Test(org.junit.Test)

Example 37 with ClusterConfiguration

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")));
}
Also used : LearnerMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Executor(java.util.concurrent.Executor) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) MessageArgumentMatcher(org.neo4j.cluster.protocol.MessageArgumentMatcher) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) Test(org.junit.Test)

Example 38 with ClusterConfiguration

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));
    }
}
Also used : ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) Adapter(org.neo4j.cluster.protocol.cluster.ClusterListener.Adapter) ClusterClient(org.neo4j.cluster.client.ClusterClient) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) Before(org.junit.Before)

Example 39 with ClusterConfiguration

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);
}
Also used : Config(org.neo4j.kernel.configuration.Config) HighAvailabilityMemberInfoProvider(org.neo4j.kernel.ha.HighAvailabilityMemberInfoProvider) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) DefaultElectionCredentialsProvider(org.neo4j.kernel.ha.cluster.DefaultElectionCredentialsProvider) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) SnapshotContext(org.neo4j.cluster.protocol.snapshot.SnapshotContext) ProtocolServer(org.neo4j.cluster.ProtocolServer) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) MultiPaxosServerFactory(org.neo4j.cluster.MultiPaxosServerFactory) InMemoryAcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore)

Example 40 with ClusterConfiguration

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);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Monitors(org.neo4j.kernel.monitoring.Monitors) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI)

Aggregations

ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)42 InstanceId (org.neo4j.cluster.InstanceId)33 Test (org.junit.Test)29 Timeouts (org.neo4j.cluster.timeout.Timeouts)20 URI (java.net.URI)18 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)18 Config (org.neo4j.kernel.configuration.Config)17 Executor (java.util.concurrent.Executor)16 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)16 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)15 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)15 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)13 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)13 Message (org.neo4j.cluster.com.message.Message)10 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)10 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)8 HashMap (java.util.HashMap)7 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)7 ElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ElectionCredentialsProvider)6 LinkedList (java.util.LinkedList)5