Search in sources :

Example 1 with MultiDataStreamStateMachine

use of org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine in project incubator-ratis by apache.

the class DataStreamClusterTests method assertLogEntry.

void assertLogEntry(CLUSTER cluster, RaftClientRequest request) throws Exception {
    for (RaftServer proxy : cluster.getServers()) {
        final RaftServer.Division impl = proxy.getDivision(cluster.getGroupId());
        final MultiDataStreamStateMachine stateMachine = (MultiDataStreamStateMachine) impl.getStateMachine();
        final SingleDataStream s = stateMachine.getSingleDataStream(request);
        Assert.assertFalse(s.getDataChannel().isOpen());
        DataStreamTestUtils.assertLogEntry(impl, s);
    }
}
Also used : RaftServer(org.apache.ratis.server.RaftServer) MultiDataStreamStateMachine(org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine) SingleDataStream(org.apache.ratis.datastream.DataStreamTestUtils.SingleDataStream)

Example 2 with MultiDataStreamStateMachine

use of org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine in project incubator-ratis by apache.

the class DataStreamAsyncClusterTests method runTestDataStream.

void runTestDataStream(CLUSTER cluster, boolean stepDownLeader) throws Exception {
    RaftTestUtil.waitForLeader(cluster);
    final List<CompletableFuture<Long>> futures = new ArrayList<>();
    futures.add(CompletableFuture.supplyAsync(() -> runTestDataStream(cluster, 5, 10, 1_000_000, 10, stepDownLeader), executor));
    futures.add(CompletableFuture.supplyAsync(() -> runTestDataStream(cluster, 2, 20, 1_000, 5_000, stepDownLeader), executor));
    final long maxIndex = futures.stream().map(CompletableFuture::join).max(Long::compareTo).orElseThrow(IllegalStateException::new);
    if (stepDownLeader) {
        final RaftPeerId oldLeader = cluster.getLeader().getId();
        final CompletableFuture<RaftPeerId> changeLeader = futures.get(0).thenApplyAsync(dummy -> {
            try {
                return RaftTestUtil.changeLeader(cluster, oldLeader);
            } catch (Exception e) {
                throw new CompletionException("Failed to change leader from " + oldLeader, e);
            }
        });
        LOG.info("Changed leader from {} to {}", oldLeader, changeLeader.join());
    }
    // wait for all servers to catch up
    try (RaftClient client = cluster.createClient()) {
        RaftClientReply reply = client.async().watch(maxIndex, ReplicationLevel.ALL).join();
        Assert.assertTrue(reply.isSuccess());
    }
    // assert all streams are linked
    for (RaftServer proxy : cluster.getServers()) {
        final RaftServer.Division impl = proxy.getDivision(cluster.getGroupId());
        final MultiDataStreamStateMachine stateMachine = (MultiDataStreamStateMachine) impl.getStateMachine();
        for (SingleDataStream s : stateMachine.getStreams()) {
            Assert.assertFalse(s.getDataChannel().isOpen());
            DataStreamTestUtils.assertLogEntry(impl, s);
        }
    }
}
Also used : RaftServer(org.apache.ratis.server.RaftServer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) CompletableFuture(java.util.concurrent.CompletableFuture) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) MultiDataStreamStateMachine(org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine) CompletionException(java.util.concurrent.CompletionException) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) SingleDataStream(org.apache.ratis.datastream.DataStreamTestUtils.SingleDataStream) RaftClient(org.apache.ratis.client.RaftClient)

Example 3 with MultiDataStreamStateMachine

use of org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine in project incubator-ratis by apache.

the class TestNettyDataStreamWithMock method mockDivision.

RaftServer.Division mockDivision(RaftServer server, RaftClient client) {
    final RaftServer.Division division = mock(RaftServer.Division.class);
    when(division.getRaftServer()).thenReturn(server);
    when(division.getRaftClient()).thenReturn(client);
    when(division.getRaftConf()).thenAnswer(i -> getRaftConf());
    final MultiDataStreamStateMachine stateMachine = new MultiDataStreamStateMachine();
    when(division.getStateMachine()).thenReturn(stateMachine);
    final DataStreamMap streamMap = RaftServerTestUtil.newDataStreamMap(server.getId());
    when(division.getDataStreamMap()).thenReturn(streamMap);
    return division;
}
Also used : RaftServer(org.apache.ratis.server.RaftServer) MultiDataStreamStateMachine(org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine) DataStreamMap(org.apache.ratis.server.DataStreamMap)

Aggregations

MultiDataStreamStateMachine (org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine)3 RaftServer (org.apache.ratis.server.RaftServer)3 SingleDataStream (org.apache.ratis.datastream.DataStreamTestUtils.SingleDataStream)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 RaftClient (org.apache.ratis.client.RaftClient)1 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 DataStreamMap (org.apache.ratis.server.DataStreamMap)1