Search in sources :

Example 1 with ResponseEnDecoderV3

use of org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseEnDecoderV3 in project bookkeeper by apache.

the class BookieProtoEncodingTest method testV3ResponseDecoderNoFallback.

@Test
public void testV3ResponseDecoderNoFallback() throws Exception {
    AddResponse v2Resp = AddResponse.create(BookieProtocol.CURRENT_PROTOCOL_VERSION, BookieProtocol.EOK, 1L, 2L);
    BookkeeperProtocol.Response v3Resp = BookkeeperProtocol.Response.newBuilder().setHeader(BKPacketHeader.newBuilder().setVersion(ProtocolVersion.VERSION_THREE).setTxnId(1L).setOperation(OperationType.ADD_ENTRY).build()).setStatus(StatusCode.EOK).setAddResponse(BookkeeperProtocol.AddResponse.newBuilder().setStatus(StatusCode.EOK).setLedgerId(1L).setEntryId(2L).build()).build();
    List<Object> outList = Lists.newArrayList();
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.fireChannelRead(any())).thenAnswer((iom) -> {
        outList.add(iom.getArgument(0));
        return null;
    });
    ResponseEnDeCoderPreV3 v2Encoder = new ResponseEnDeCoderPreV3(null);
    ResponseEnDecoderV3 v3Encoder = new ResponseEnDecoderV3(null);
    ResponseDecoder v3Decoder = new ResponseDecoder(null, false);
    try {
        v3Decoder.channelRead(ctx, v2Encoder.encode(v2Resp, UnpooledByteBufAllocator.DEFAULT));
        fail("V3 response decoder should fail on decoding v2 response");
    } catch (InvalidProtocolBufferException e) {
    // expected
    }
    assertEquals(0, outList.size());
    v3Decoder.channelRead(ctx, v3Encoder.encode(v3Resp, UnpooledByteBufAllocator.DEFAULT));
    assertEquals(1, outList.size());
}
Also used : ResponseEnDeCoderPreV3(org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseEnDeCoderPreV3) ResponseDecoder(org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseDecoder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ResponseEnDecoderV3(org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseEnDecoderV3) AddResponse(org.apache.bookkeeper.proto.BookieProtocol.AddResponse) Test(org.junit.Test)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ResponseDecoder (org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseDecoder)1 ResponseEnDeCoderPreV3 (org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseEnDeCoderPreV3)1 ResponseEnDecoderV3 (org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseEnDecoderV3)1 AddResponse (org.apache.bookkeeper.proto.BookieProtocol.AddResponse)1 Test (org.junit.Test)1