Search in sources :

Example 21 with MessageSerializer

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());
}
Also used : MessageSerializer(org.apache.flink.queryablestate.network.messages.MessageSerializer) KvStateInternalRequest(org.apache.flink.queryablestate.messages.KvStateInternalRequest) KvStateResponse(org.apache.flink.queryablestate.messages.KvStateResponse) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

KvStateInternalRequest (org.apache.flink.queryablestate.messages.KvStateInternalRequest)21 KvStateResponse (org.apache.flink.queryablestate.messages.KvStateResponse)21 MessageSerializer (org.apache.flink.queryablestate.network.messages.MessageSerializer)21 Test (org.junit.Test)21 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)18 AtomicKvStateRequestStats (org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats)16 KvStateID (org.apache.flink.queryablestate.KvStateID)11 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)11 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)11 KvStateServerHandler (org.apache.flink.queryablestate.server.KvStateServerHandler)10 ClosedChannelException (java.nio.channels.ClosedChannelException)7 ConnectException (java.net.ConnectException)6 UnknownHostException (java.net.UnknownHostException)6 ExecutionException (java.util.concurrent.ExecutionException)6 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)6 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)6 AbstractStateBackend (org.apache.flink.runtime.state.AbstractStateBackend)6 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)6 InetSocketAddress (java.net.InetSocketAddress)5 RequestFailure (org.apache.flink.queryablestate.network.messages.RequestFailure)5