Search in sources :

Example 21 with KvStateInternalRequest

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

Example 22 with KvStateInternalRequest

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());
}
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)22 KvStateResponse (org.apache.flink.queryablestate.messages.KvStateResponse)22 Test (org.junit.Test)22 MessageSerializer (org.apache.flink.queryablestate.network.messages.MessageSerializer)21 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)19 AtomicKvStateRequestStats (org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats)17 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)12 KvStateID (org.apache.flink.queryablestate.KvStateID)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 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)7 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)7 AbstractStateBackend (org.apache.flink.runtime.state.AbstractStateBackend)7 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)7 ConnectException (java.net.ConnectException)6 InetSocketAddress (java.net.InetSocketAddress)6 UnknownHostException (java.net.UnknownHostException)6 ExecutionException (java.util.concurrent.ExecutionException)6 RequestFailure (org.apache.flink.queryablestate.network.messages.RequestFailure)5