Search in sources :

Example 6 with RequestFailure

use of org.apache.flink.queryablestate.network.messages.RequestFailure in project flink by apache.

the class KvStateServerHandlerTest method testQueryUnknownKvStateID.

/**
 * Tests the failure response with {@link UnknownKvStateIdException} as cause on queries for
 * unregistered KvStateIDs.
 */
@Test
public void testQueryUnknownKvStateID() throws Exception {
    KvStateRegistry registry = new KvStateRegistry();
    AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();
    MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
    KvStateServerHandler handler = new KvStateServerHandler(testServer, registry, serializer, stats);
    EmbeddedChannel channel = new EmbeddedChannel(getFrameDecoder(), handler);
    long requestId = Integer.MAX_VALUE + 182828L;
    KvStateInternalRequest request = new KvStateInternalRequest(new KvStateID(), new byte[0]);
    ByteBuf serRequest = MessageSerializer.serializeRequest(channel.alloc(), requestId, request);
    // Write the request and wait for the response
    channel.writeInbound(serRequest);
    ByteBuf buf = (ByteBuf) readInboundBlocking(channel);
    // skip frame length
    buf.skipBytes(4);
    // Verify the response
    assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf));
    RequestFailure response = MessageSerializer.deserializeRequestFailure(buf);
    buf.release();
    assertEquals(requestId, response.getRequestId());
    assertTrue("Did not respond with expected failure cause", response.getCause() instanceof UnknownKvStateIdException);
    assertEquals(1L, stats.getNumRequests());
    assertEquals(1L, stats.getNumFailed());
}
Also used : KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) MessageSerializer(org.apache.flink.queryablestate.network.messages.MessageSerializer) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) UnknownKvStateIdException(org.apache.flink.queryablestate.exceptions.UnknownKvStateIdException) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) KvStateServerHandler(org.apache.flink.queryablestate.server.KvStateServerHandler) KvStateInternalRequest(org.apache.flink.queryablestate.messages.KvStateInternalRequest) KvStateResponse(org.apache.flink.queryablestate.messages.KvStateResponse) KvStateID(org.apache.flink.queryablestate.KvStateID) RequestFailure(org.apache.flink.queryablestate.network.messages.RequestFailure) AtomicKvStateRequestStats(org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats) Test(org.junit.Test)

Example 7 with RequestFailure

use of org.apache.flink.queryablestate.network.messages.RequestFailure in project flink by apache.

the class ClientHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    try {
        ByteBuf buf = (ByteBuf) msg;
        MessageType msgType = MessageSerializer.deserializeHeader(buf);
        if (msgType == MessageType.REQUEST_RESULT) {
            long requestId = MessageSerializer.getRequestId(buf);
            RESP result = serializer.deserializeResponse(buf);
            callback.onRequestResult(requestId, result);
        } else if (msgType == MessageType.REQUEST_FAILURE) {
            RequestFailure failure = MessageSerializer.deserializeRequestFailure(buf);
            callback.onRequestFailure(failure.getRequestId(), failure.getCause());
        } else if (msgType == MessageType.SERVER_FAILURE) {
            throw MessageSerializer.deserializeServerFailure(buf);
        } else {
            throw new IllegalStateException("Unexpected response type '" + msgType + "'");
        }
    } catch (Throwable t1) {
        try {
            callback.onFailure(t1);
        } catch (Throwable t2) {
            LOG.error("Failed to notify callback about failure", t2);
        }
    } finally {
        ReferenceCountUtil.release(msg);
    }
}
Also used : RequestFailure(org.apache.flink.queryablestate.network.messages.RequestFailure) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) MessageType(org.apache.flink.queryablestate.network.messages.MessageType)

Aggregations

RequestFailure (org.apache.flink.queryablestate.network.messages.RequestFailure)7 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)7 Test (org.junit.Test)6 KvStateInternalRequest (org.apache.flink.queryablestate.messages.KvStateInternalRequest)5 KvStateResponse (org.apache.flink.queryablestate.messages.KvStateResponse)5 MessageSerializer (org.apache.flink.queryablestate.network.messages.MessageSerializer)5 AtomicKvStateRequestStats (org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats)5 KvStateServerHandler (org.apache.flink.queryablestate.server.KvStateServerHandler)5 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)5 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)5 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)3 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)3 AbstractStateBackend (org.apache.flink.runtime.state.AbstractStateBackend)3 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)3 KvStateID (org.apache.flink.queryablestate.KvStateID)2 JobID (org.apache.flink.api.common.JobID)1 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)1 VoidNamespace (org.apache.flink.queryablestate.client.VoidNamespace)1 UnknownKeyOrNamespaceException (org.apache.flink.queryablestate.exceptions.UnknownKeyOrNamespaceException)1 UnknownKvStateIdException (org.apache.flink.queryablestate.exceptions.UnknownKvStateIdException)1