Java Code Examples for org.apache.flink.queryablestate.network.messages.MessageSerializer#deserializeServerFailure()
The following examples show how to use
org.apache.flink.queryablestate.network.messages.MessageSerializer#deserializeServerFailure() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KvStateServerHandlerTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests that the channel is closed if an Exception reaches the channel handler. */ @Test public void testCloseChannelOnExceptionCaught() 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(handler); channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception")); ByteBuf buf = (ByteBuf) readInboundBlocking(channel); buf.skipBytes(4); // skip frame length // Verify the response assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf)); Throwable response = MessageSerializer.deserializeServerFailure(buf); assertTrue(response.getMessage().contains("Expected test Exception")); channel.closeFuture().await(READ_TIMEOUT_MILLIS); assertFalse(channel.isActive()); }
Example 2
Source File: KvStateServerHandlerTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that the channel is closed if an Exception reaches the channel handler. */ @Test public void testCloseChannelOnExceptionCaught() 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(handler); channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception")); ByteBuf buf = (ByteBuf) readInboundBlocking(channel); buf.skipBytes(4); // skip frame length // Verify the response assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf)); Throwable response = MessageSerializer.deserializeServerFailure(buf); assertTrue(response.getMessage().contains("Expected test Exception")); channel.closeFuture().await(READ_TIMEOUT_MILLIS); assertFalse(channel.isActive()); }
Example 3
Source File: MessageSerializerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests server failure serialization. */ @Test public void testServerFailureSerialization() throws Exception { IllegalStateException cause = new IllegalStateException("Expected test"); ByteBuf buf = MessageSerializer.serializeServerFailure(alloc, cause); int frameLength = buf.readInt(); assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf)); Throwable request = MessageSerializer.deserializeServerFailure(buf); assertEquals(buf.readerIndex(), frameLength + 4); assertEquals(cause.getClass(), request.getClass()); assertEquals(cause.getMessage(), request.getMessage()); }
Example 4
Source File: ClientHandler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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); } }
Example 5
Source File: MessageSerializerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests server failure serialization. */ @Test public void testServerFailureSerialization() throws Exception { IllegalStateException cause = new IllegalStateException("Expected test"); ByteBuf buf = MessageSerializer.serializeServerFailure(alloc, cause); int frameLength = buf.readInt(); assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf)); Throwable request = MessageSerializer.deserializeServerFailure(buf); assertEquals(buf.readerIndex(), frameLength + 4); assertEquals(cause.getClass(), request.getClass()); assertEquals(cause.getMessage(), request.getMessage()); }
Example 6
Source File: ClientHandler.java From flink with Apache License 2.0 | 5 votes |
@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); } }
Example 7
Source File: MessageSerializerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests server failure serialization. */ @Test public void testServerFailureSerialization() throws Exception { IllegalStateException cause = new IllegalStateException("Expected test"); ByteBuf buf = MessageSerializer.serializeServerFailure(alloc, cause); int frameLength = buf.readInt(); assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf)); Throwable request = MessageSerializer.deserializeServerFailure(buf); assertEquals(buf.readerIndex(), frameLength + 4); assertEquals(cause.getClass(), request.getClass()); assertEquals(cause.getMessage(), request.getMessage()); }
Example 8
Source File: KvStateServerHandlerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that the channel is closed if an Exception reaches the channel handler. */ @Test public void testCloseChannelOnExceptionCaught() 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(handler); channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception")); ByteBuf buf = (ByteBuf) readInboundBlocking(channel); buf.skipBytes(4); // skip frame length // Verify the response assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf)); Throwable response = MessageSerializer.deserializeServerFailure(buf); buf.release(); assertTrue(response.getMessage().contains("Expected test Exception")); channel.closeFuture().await(READ_TIMEOUT_MILLIS); assertFalse(channel.isActive()); }
Example 9
Source File: ClientHandler.java From flink with Apache License 2.0 | 5 votes |
@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); } }