use of org.apache.flink.queryablestate.messages.KvStateInternalRequest in project flink by apache.
the class MessageSerializerTest method testRequestSerializationWithZeroLengthKeyAndNamespace.
/**
* Tests request serialization with zero-length serialized key and namespace.
*/
@Test
public void testRequestSerializationWithZeroLengthKeyAndNamespace() throws Exception {
long requestId = Integer.MAX_VALUE + 1337L;
KvStateID kvStateId = new KvStateID();
byte[] serializedKeyAndNamespace = new byte[0];
final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
assertEquals(requestId, MessageSerializer.getRequestId(buf));
KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertEquals(kvStateId, requestDeser.getKvStateId());
assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}
use of org.apache.flink.queryablestate.messages.KvStateInternalRequest 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