Search in sources :

Example 11 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class MultiPaxosTest method testFailure.

@Test
public void testFailure() throws Exception {
    ScriptableNetworkFailureLatencyStrategy networkLatency = new ScriptableNetworkFailureLatencyStrategy();
    NetworkMock network = new NetworkMock(NullLogService.getInstance(), new Monitors(), 50, new MultipleFailureLatencyStrategy(networkLatency), new MessageTimeoutStrategy(new FixedTimeoutStrategy(1000)));
    List<TestProtocolServer> nodes = new ArrayList<TestProtocolServer>();
    TestProtocolServer server = network.addServer(1, URI.create("cluster://server1"));
    server.newClient(Cluster.class).create("default");
    network.tickUntilDone();
    nodes.add(server);
    for (int i = 1; i < 3; i++) {
        TestProtocolServer protocolServer = network.addServer(i + 1, new URI("cluster://server" + (i + 1)));
        protocolServer.newClient(Cluster.class).join("default", new URI("cluster://server1"));
        network.tick(10);
        nodes.add(protocolServer);
    }
    final AtomicBroadcast atomicBroadcast = nodes.get(0).newClient(AtomicBroadcast.class);
    ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
    final AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);
    atomicBroadcast.broadcast(serializer.broadcast(new DaPayload()));
    networkLatency.nodeIsDown("cluster://server2");
    networkLatency.nodeIsDown("cluster://server3");
    atomicBroadcast.broadcast(serializer.broadcast(new DaPayload()));
    network.tick(100);
    networkLatency.nodeIsUp("cluster://server3");
    network.tick(1000);
    for (TestProtocolServer node : nodes) {
        node.newClient(Cluster.class).leave();
        network.tick(10);
    }
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) FixedTimeoutStrategy(org.neo4j.cluster.timeout.FixedTimeoutStrategy) NetworkMock(org.neo4j.cluster.NetworkMock) ScriptableNetworkFailureLatencyStrategy(org.neo4j.cluster.ScriptableNetworkFailureLatencyStrategy) MultipleFailureLatencyStrategy(org.neo4j.cluster.MultipleFailureLatencyStrategy) AtomicBroadcast(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast) ArrayList(java.util.ArrayList) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) URI(java.net.URI) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) TestProtocolServer(org.neo4j.cluster.TestProtocolServer) Monitors(org.neo4j.kernel.monitoring.Monitors) MessageTimeoutStrategy(org.neo4j.cluster.timeout.MessageTimeoutStrategy) Test(org.junit.Test)

Example 12 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class MultiPaxosServerFactory method constructSupportingInfrastructureFor.

/**
     * Sets up the supporting infrastructure and communication hooks for our state machines. This is here to support
     * an external requirement for assembling protocol servers given an existing set of state machines (used to prove
     * correctness).
     */
public ProtocolServer constructSupportingInfrastructureFor(InstanceId me, MessageSource input, MessageSender output, DelayedDirectExecutor executor, Timeouts timeouts, Executor stateMachineExecutor, final MultiPaxosContext context, StateMachine[] machines) {
    StateMachines stateMachines = new StateMachines(logging, stateMachinesMonitor, input, output, timeouts, executor, stateMachineExecutor, me);
    for (StateMachine machine : machines) {
        stateMachines.addStateMachine(machine);
    }
    final ProtocolServer server = new ProtocolServer(me, stateMachines, logging);
    server.addBindingListener(new BindingListener() {

        @Override
        public void listeningAt(URI me) {
            context.getClusterContext().setBoundAt(me);
        }
    });
    stateMachines.addMessageProcessor(new HeartbeatRefreshProcessor(stateMachines.getOutgoing(), context.getClusterContext()));
    input.addMessageProcessor(new HeartbeatIAmAliveProcessor(stateMachines.getOutgoing(), context.getClusterContext()));
    Cluster cluster = server.newClient(Cluster.class);
    cluster.addClusterListener(new HeartbeatJoinListener(stateMachines.getOutgoing()));
    cluster.addClusterListener(new HeartbeatLeftListener(context.getHeartbeatContext(), logging));
    context.getHeartbeatContext().addHeartbeatListener(new HeartbeatReelectionListener(server.newClient(Election.class), logging));
    context.getClusterContext().addClusterListener(new ClusterLeaveReelectionListener(server.newClient(Election.class), logging));
    StateMachineRules rules = new StateMachineRules(stateMachines.getOutgoing()).rule(ClusterState.start, ClusterMessage.create, ClusterState.entered, internal(AtomicBroadcastMessage.entered), internal(ProposerMessage.join), internal(AcceptorMessage.join), internal(LearnerMessage.join), internal(HeartbeatMessage.join), internal(ElectionMessage.created), internal(SnapshotMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.joining, internal(AcceptorMessage.join), internal(LearnerMessage.join), internal(AtomicBroadcastMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.entered, internal(AtomicBroadcastMessage.entered), internal(ProposerMessage.join), internal(AcceptorMessage.join), internal(LearnerMessage.join), internal(HeartbeatMessage.join), internal(ElectionMessage.join), internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.configurationChanged, ClusterState.entered, internal(AtomicBroadcastMessage.entered), internal(ProposerMessage.join), internal(AcceptorMessage.join), internal(LearnerMessage.join), internal(HeartbeatMessage.join), internal(ElectionMessage.join), internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.joinFailure, ClusterState.start, internal(AtomicBroadcastMessage.leave), internal(AcceptorMessage.leave), internal(LearnerMessage.leave), internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, internal(AtomicBroadcastMessage.leave), internal(AcceptorMessage.leave), internal(LearnerMessage.leave), internal(HeartbeatMessage.leave), internal(SnapshotMessage.leave), internal(ElectionMessage.leave), internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, internal(AtomicBroadcastMessage.leave), internal(AcceptorMessage.leave), internal(LearnerMessage.leave), internal(HeartbeatMessage.leave), internal(ElectionMessage.leave), internal(SnapshotMessage.leave), internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.configurationChanged, ClusterState.start, internal(AtomicBroadcastMessage.leave), internal(AcceptorMessage.leave), internal(LearnerMessage.leave), internal(HeartbeatMessage.leave), internal(ElectionMessage.leave), internal(SnapshotMessage.leave), internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.leaveTimedout, ClusterState.start, internal(AtomicBroadcastMessage.leave), internal(AcceptorMessage.leave), internal(LearnerMessage.leave), internal(HeartbeatMessage.leave), internal(ElectionMessage.leave), internal(SnapshotMessage.leave), internal(ProposerMessage.leave));
    stateMachines.addStateTransitionListener(rules);
    return server;
}
Also used : ClusterLeaveReelectionListener(org.neo4j.cluster.protocol.election.ClusterLeaveReelectionListener) HeartbeatReelectionListener(org.neo4j.cluster.protocol.election.HeartbeatReelectionListener) StateMachine(org.neo4j.cluster.statemachine.StateMachine) StateMachineRules(org.neo4j.cluster.statemachine.StateMachineRules) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) URI(java.net.URI) HeartbeatIAmAliveProcessor(org.neo4j.cluster.protocol.heartbeat.HeartbeatIAmAliveProcessor) HeartbeatRefreshProcessor(org.neo4j.cluster.protocol.heartbeat.HeartbeatRefreshProcessor) HeartbeatJoinListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatJoinListener) HeartbeatLeftListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatLeftListener)

Example 13 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldRegisterItselfOnMonitors.

@Test
public void shouldRegisterItselfOnMonitors() {
    // given
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    Cluster cluster = mock(Cluster.class);
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    // when
    new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0)).init();
    // then
    verify(cluster).addClusterListener(any(ClusterListener.class));
}
Also used : ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 14 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldReturnAvailableAndAliveSlaves.

@Test
public void shouldReturnAvailableAndAliveSlaves() {
    // given
    Cluster cluster = mock(Cluster.class);
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID).availableAs(SLAVE, HA_URI, StoreId.DEFAULT)));
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    when(slaveFactory.newSlave(any(LifeSupport.class), any(ClusterMember.class), any(String.class), any(Integer.class))).thenReturn(mock(Slave.class));
    HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
    slaves.init();
    // when
    Iterable<Slave> memberSlaves = slaves.getSlaves();
    // then
    assertThat(count(memberSlaves), equalTo(1L));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 15 with Cluster

use of org.neo4j.cluster.protocol.cluster.Cluster in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldClearSlavesWhenNewMasterElected.

@Test
public void shouldClearSlavesWhenNewMasterElected() {
    // given
    Cluster cluster = mock(Cluster.class);
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID).availableAs(SLAVE, HA_URI, StoreId.DEFAULT)));
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    when(slaveFactory.newSlave(any(LifeSupport.class), any(ClusterMember.class), any(String.class), any(Integer.class))).thenReturn(mock(Slave.class), mock(Slave.class));
    HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
    slaves.init();
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    // when
    Slave slave1 = slaves.getSlaves().iterator().next();
    listener.getValue().elected(ClusterConfiguration.COORDINATOR, INSTANCE_ID, CLUSTER_URI);
    Slave slave2 = slaves.getSlaves().iterator().next();
    // then
    assertThat(slave2, not(sameInstance(slave1)));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Aggregations

Cluster (org.neo4j.cluster.protocol.cluster.Cluster)22 Test (org.junit.Test)19 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)17 Heartbeat (org.neo4j.cluster.protocol.heartbeat.Heartbeat)15 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)14 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)7 HostnamePort (org.neo4j.helpers.HostnamePort)5 URI (java.net.URI)4 DefaultSlaveFactory (org.neo4j.kernel.ha.com.master.DefaultSlaveFactory)4 SlaveFactory (org.neo4j.kernel.ha.com.master.SlaveFactory)4 Slave (org.neo4j.kernel.ha.com.master.Slave)3 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)3 InstanceId (org.neo4j.cluster.InstanceId)2 AtomicBroadcast (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast)2 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)2 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)2 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)2 HeartbeatListener (org.neo4j.cluster.protocol.heartbeat.HeartbeatListener)2 FixedTimeoutStrategy (org.neo4j.cluster.timeout.FixedTimeoutStrategy)2 MessageTimeoutStrategy (org.neo4j.cluster.timeout.MessageTimeoutStrategy)2