Search in sources :

Example 1 with NetworkMock

use of org.neo4j.cluster.NetworkMock 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)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 MultipleFailureLatencyStrategy (org.neo4j.cluster.MultipleFailureLatencyStrategy)1 NetworkMock (org.neo4j.cluster.NetworkMock)1 ScriptableNetworkFailureLatencyStrategy (org.neo4j.cluster.ScriptableNetworkFailureLatencyStrategy)1 TestProtocolServer (org.neo4j.cluster.TestProtocolServer)1 AtomicBroadcast (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast)1 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)1 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)1 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)1 FixedTimeoutStrategy (org.neo4j.cluster.timeout.FixedTimeoutStrategy)1 MessageTimeoutStrategy (org.neo4j.cluster.timeout.MessageTimeoutStrategy)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1