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());
}
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);
}
}
Aggregations