Search in sources :

Example 1 with SingleDataStream

use of org.apache.ratis.datastream.DataStreamTestUtils.SingleDataStream 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 SingleDataStream

use of org.apache.ratis.datastream.DataStreamTestUtils.SingleDataStream 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)

Aggregations

MultiDataStreamStateMachine (org.apache.ratis.datastream.DataStreamTestUtils.MultiDataStreamStateMachine)2 SingleDataStream (org.apache.ratis.datastream.DataStreamTestUtils.SingleDataStream)2 RaftServer (org.apache.ratis.server.RaftServer)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