use of org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer in project incubator-ratis by apache.
the class DataStreamTestUtils method assertCloseReply.
static CompletableFuture<RaftClientReply> assertCloseReply(DataStreamOutputImpl out, DataStreamReply dataStreamReply, long bytesWritten, RaftPeerId leader, ClientId primaryClientId, ClientId clientId, boolean stepDownLeader) {
// Test close idempotent
Assert.assertSame(dataStreamReply, out.closeAsync().join());
Assert.assertEquals(dataStreamReply.getClientId(), clientId);
BaseTest.testFailureCase("writeAsync should fail", () -> out.writeAsync(DataStreamRequestByteBuffer.EMPTY_BYTE_BUFFER).join(), CompletionException.class, (Logger) null, AlreadyClosedException.class);
final DataStreamReplyByteBuffer buffer = (DataStreamReplyByteBuffer) dataStreamReply;
try {
final RaftClientReply reply = ClientProtoUtils.toRaftClientReply(buffer.slice());
assertRaftClientMessage(out.getHeader(), leader, reply, primaryClientId, stepDownLeader);
if (reply.isSuccess()) {
final ByteString bytes = reply.getMessage().getContent();
if (!bytes.equals(MOCK)) {
Assert.assertEquals(bytesWritten2ByteString(bytesWritten), bytes);
}
}
return CompletableFuture.completedFuture(reply);
} catch (Throwable t) {
return JavaUtils.completeExceptionally(t);
}
}
use of org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer in project incubator-ratis by apache.
the class NettyDataStreamUtils method encodeDataStreamReplyByteBuffer.
static void encodeDataStreamReplyByteBuffer(DataStreamReplyByteBuffer reply, Consumer<ByteBuf> out, ByteBufAllocator allocator) {
ByteBuffer headerBuf = getDataStreamReplyHeaderProtoByteBuf(reply);
final ByteBuf headerLenBuf = allocator.directBuffer(DataStreamPacketHeader.getSizeOfHeaderLen());
headerLenBuf.writeInt(headerBuf.remaining());
out.accept(headerLenBuf);
out.accept(Unpooled.wrappedBuffer(headerBuf));
out.accept(Unpooled.wrappedBuffer(reply.slice()));
}
Aggregations