use of org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl in project incubator-ratis by apache.
the class DataStreamAsyncClusterTests method runTestDataStream.
long runTestDataStream(CLUSTER cluster, int numStreams, int bufferSize, int bufferNum, boolean stepDownLeader) {
final Iterable<RaftServer> servers = CollectionUtils.as(cluster.getServers(), s -> s);
final RaftPeerId leader = cluster.getLeader().getId();
final List<CompletableFuture<RaftClientReply>> futures = new ArrayList<>();
final RaftPeer primaryServer = CollectionUtils.random(cluster.getGroup().getPeers());
try (RaftClient client = cluster.createClient(primaryServer)) {
ClientId primaryClientId = getPrimaryClientId(cluster, primaryServer);
for (int i = 0; i < numStreams; i++) {
final DataStreamOutputImpl out = (DataStreamOutputImpl) client.getDataStreamApi().stream(null, getRoutingTable(cluster.getGroup().getPeers(), primaryServer));
futures.add(CompletableFuture.supplyAsync(() -> DataStreamTestUtils.writeAndCloseAndAssertReplies(servers, leader, out, bufferSize, bufferNum, primaryClientId, client.getId(), stepDownLeader).join(), executor));
}
Assert.assertEquals(numStreams, futures.size());
return futures.stream().map(CompletableFuture::join).map(RaftClientReply::getLogIndex).max(Long::compareTo).orElseThrow(IllegalStateException::new);
} catch (IOException e) {
throw new CompletionException(e);
}
}
use of org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl in project incubator-ratis by apache.
the class DataStreamClusterTests method transferToWritableByteChannel.
static CheckedConsumer<DataStreamOutputImpl, Exception> transferToWritableByteChannel(File f, int size) {
return new CheckedConsumer<DataStreamOutputImpl, Exception>() {
@Override
public void accept(DataStreamOutputImpl out) throws Exception {
try (FileInputStream in = new FileInputStream(f)) {
final long transferred = in.getChannel().transferTo(0, size, out.getWritableByteChannel());
Assert.assertEquals(size, transferred);
}
}
@Override
public String toString() {
return "transferToWritableByteChannel";
}
};
}
use of org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl in project incubator-ratis by apache.
the class DataStreamClusterTests method runTestDataStreamOutput.
void runTestDataStreamOutput(CLUSTER cluster) throws Exception {
final RaftClientRequest request;
final CompletableFuture<RaftClientReply> reply;
final RaftPeer primaryServer = CollectionUtils.random(cluster.getGroup().getPeers());
try (RaftClient client = cluster.createClient(primaryServer)) {
try (final DataStreamOutputImpl out = (DataStreamOutputImpl) client.getDataStreamApi().stream(null, getRoutingTable(cluster.getGroup().getPeers(), primaryServer))) {
request = out.getHeader();
reply = out.getRaftClientReplyFuture();
// write using DataStreamOutput
DataStreamTestUtils.writeAndAssertReplies(out, 1000, 10);
}
}
watchOrSleep(cluster, reply.join().getLogIndex());
assertLogEntry(cluster, request);
}
use of org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl in project incubator-ratis by apache.
the class DataStreamClusterTests method writeAsyncDefaultFileRegion.
static CheckedConsumer<DataStreamOutputImpl, Exception> writeAsyncDefaultFileRegion(File f, int size) {
return new CheckedConsumer<DataStreamOutputImpl, Exception>() {
@Override
public void accept(DataStreamOutputImpl out) {
final DataStreamReply dataStreamReply = out.writeAsync(f).join();
DataStreamTestUtils.assertSuccessReply(Type.STREAM_DATA, size, dataStreamReply);
}
@Override
public String toString() {
return "writeAsyncDefaultFileRegion";
}
};
}
use of org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl in project incubator-ratis by apache.
the class DataStreamClusterTests method runTestWriteFile.
void runTestWriteFile(CLUSTER cluster, int i, CheckedConsumer<DataStreamOutputImpl, Exception> testCase) throws Exception {
final RaftClientRequest request;
final CompletableFuture<RaftClientReply> reply;
final RaftPeer primaryServer = CollectionUtils.random(cluster.getGroup().getPeers());
try (RaftClient client = cluster.createClient(primaryServer)) {
try (final DataStreamOutputImpl out = (DataStreamOutputImpl) client.getDataStreamApi().stream(null, getRoutingTable(cluster.getGroup().getPeers(), primaryServer))) {
request = out.getHeader();
reply = out.getRaftClientReplyFuture();
final Timestamp start = Timestamp.currentTime();
testCase.accept(out);
LOG.info("{}: {} elapsed {}ms", i, testCase, start.elapsedTimeMs());
}
}
watchOrSleep(cluster, reply.join().getLogIndex());
assertLogEntry(cluster, request);
}
Aggregations