use of org.apache.bookkeeper.proto.BookieProtoEncoding.ResponseEnDeCoderPreV3 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());
}
Aggregations