use of org.apache.flink.queryablestate.network.messages.MessageSerializer in project flink by apache.
the class MessageSerializerTest method testResponseSerialization.
/**
* Tests response serialization.
*/
@Test
public void testResponseSerialization() throws Exception {
long requestId = Integer.MAX_VALUE + 72727278L;
byte[] serializedResult = randomByteArray(1024);
final KvStateResponse response = new KvStateResponse(serializedResult);
final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
ByteBuf buf = MessageSerializer.serializeResponse(alloc, requestId, response);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST_RESULT, MessageSerializer.deserializeHeader(buf));
assertEquals(requestId, MessageSerializer.getRequestId(buf));
KvStateResponse responseDeser = serializer.deserializeResponse(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertArrayEquals(serializedResult, responseDeser.getContent());
}
Aggregations