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);
}
}
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);
}
}
}
Aggregations