use of org.apache.ratis.client.api.DataStreamOutput in project incubator-ratis by apache.
the class FileStoreWriter method streamWriteAndVerify.
public FileStoreWriter streamWriteAndVerify(RoutingTable routingTable) {
final int size = fileSize.getSizeInt();
final DataStreamOutput dataStreamOutput = client.getStreamOutput(fileName, size, routingTable);
final List<CompletableFuture<DataStreamReply>> futures = new ArrayList<>();
final List<Integer> sizes = new ArrayList<>();
for (int offset = 0; offset < size; ) {
final int remaining = size - offset;
final int length = Math.min(remaining, bufferSize);
final boolean close = length == remaining;
LOG.trace("write {}, offset={}, length={}, close? {}", fileName, offset, length, close);
final ByteBuffer bf = DataStreamTestUtils.initBuffer(0, length);
futures.add(close ? dataStreamOutput.writeAsync(bf, StandardWriteOption.CLOSE) : dataStreamOutput.writeAsync(bf));
sizes.add(length);
offset += length;
}
DataStreamReply reply = dataStreamOutput.closeAsync().join();
Assert.assertTrue(reply.isSuccess());
// check writeAsync requests
for (int i = 0; i < futures.size(); i++) {
reply = futures.get(i).join();
Assert.assertTrue(reply.isSuccess());
Assert.assertEquals(sizes.get(i).longValue(), reply.getBytesWritten());
Assert.assertEquals(reply.getType(), RaftProtos.DataStreamPacketHeaderProto.Type.STREAM_DATA);
}
return this;
}
Aggregations