Search in sources :

Example 1 with DataStreamReplyByteBuffer

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);
    }
}
Also used : RaftClientReply(org.apache.ratis.protocol.RaftClientReply) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) DataStreamReplyByteBuffer(org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer)

Example 2 with DataStreamReplyByteBuffer

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()));
}
Also used : DataStreamRequestByteBuf(org.apache.ratis.netty.server.DataStreamRequestByteBuf) ByteBuf(org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf) DataStreamRequestByteBuffer(org.apache.ratis.datastream.impl.DataStreamRequestByteBuffer) ByteBuffer(java.nio.ByteBuffer) DataStreamReplyByteBuffer(org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer)

Aggregations

DataStreamReplyByteBuffer (org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer)2 ByteBuffer (java.nio.ByteBuffer)1 DataStreamRequestByteBuffer (org.apache.ratis.datastream.impl.DataStreamRequestByteBuffer)1 DataStreamRequestByteBuf (org.apache.ratis.netty.server.DataStreamRequestByteBuf)1 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)1 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)1 ByteBuf (org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf)1