Java Code Examples for org.apache.flink.queryablestate.network.messages.MessageSerializer#serializeRequestFailure()
The following examples show how to use
org.apache.flink.queryablestate.network.messages.MessageSerializer#serializeRequestFailure() .
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: MessageSerializerTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests request failure serialization. */ @Test public void testKvStateRequestFailureSerialization() throws Exception { long requestId = Integer.MAX_VALUE + 1111222L; IllegalStateException cause = new IllegalStateException("Expected test"); ByteBuf buf = MessageSerializer.serializeRequestFailure(alloc, requestId, cause); int frameLength = buf.readInt(); assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf)); RequestFailure requestFailure = MessageSerializer.deserializeRequestFailure(buf); assertEquals(buf.readerIndex(), frameLength + 4); assertEquals(requestId, requestFailure.getRequestId()); assertEquals(cause.getClass(), requestFailure.getCause().getClass()); assertEquals(cause.getMessage(), requestFailure.getCause().getMessage()); }
Example 2
Source File: MessageSerializerTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests request failure serialization. */ @Test public void testKvStateRequestFailureSerialization() throws Exception { long requestId = Integer.MAX_VALUE + 1111222L; IllegalStateException cause = new IllegalStateException("Expected test"); ByteBuf buf = MessageSerializer.serializeRequestFailure(alloc, requestId, cause); int frameLength = buf.readInt(); assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf)); RequestFailure requestFailure = MessageSerializer.deserializeRequestFailure(buf); assertEquals(buf.readerIndex(), frameLength + 4); assertEquals(requestId, requestFailure.getRequestId()); assertEquals(cause.getClass(), requestFailure.getCause().getClass()); assertEquals(cause.getMessage(), requestFailure.getCause().getMessage()); }
Example 3
Source File: MessageSerializerTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests request failure serialization. */ @Test public void testKvStateRequestFailureSerialization() throws Exception { long requestId = Integer.MAX_VALUE + 1111222L; IllegalStateException cause = new IllegalStateException("Expected test"); ByteBuf buf = MessageSerializer.serializeRequestFailure(alloc, requestId, cause); int frameLength = buf.readInt(); assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf)); RequestFailure requestFailure = MessageSerializer.deserializeRequestFailure(buf); assertEquals(buf.readerIndex(), frameLength + 4); assertEquals(requestId, requestFailure.getRequestId()); assertEquals(cause.getClass(), requestFailure.getCause().getClass()); assertEquals(cause.getMessage(), requestFailure.getCause().getMessage()); }
Example 4
Source File: KvStateClientHandlerTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that on reads the expected callback methods are called and read * buffers are recycled. */ @Test public void testReadCallbacksAndBufferRecycling() throws Exception { final ClientHandlerCallback<KvStateResponse> callback = mock(ClientHandlerCallback.class); final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); final EmbeddedChannel channel = new EmbeddedChannel(new ClientHandler<>("Test Client", serializer, callback)); final byte[] content = new byte[0]; final KvStateResponse response = new KvStateResponse(content); // // Request success // ByteBuf buf = MessageSerializer.serializeResponse(channel.alloc(), 1222112277L, response); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onRequestResult(eq(1222112277L), any(KvStateResponse.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Request failure // buf = MessageSerializer.serializeRequestFailure( channel.alloc(), 1222112278, new RuntimeException("Expected test Exception")); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onRequestFailure(eq(1222112278L), isA(RuntimeException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Server failure // buf = MessageSerializer.serializeServerFailure( channel.alloc(), new RuntimeException("Expected test Exception")); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onFailure(isA(RuntimeException.class)); // // Unexpected messages // buf = channel.alloc().buffer(4).writeInt(1223823); // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onFailure(isA(IllegalStateException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Exception caught // channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception")); verify(callback, times(3)).onFailure(isA(RuntimeException.class)); // // Channel inactive // channel.pipeline().fireChannelInactive(); verify(callback, times(1)).onFailure(isA(ClosedChannelException.class)); }
Example 5
Source File: KvStateClientHandlerTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that on reads the expected callback methods are called and read * buffers are recycled. */ @Test public void testReadCallbacksAndBufferRecycling() throws Exception { final ClientHandlerCallback<KvStateResponse> callback = mock(ClientHandlerCallback.class); final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); final EmbeddedChannel channel = new EmbeddedChannel(new ClientHandler<>("Test Client", serializer, callback)); final byte[] content = new byte[0]; final KvStateResponse response = new KvStateResponse(content); // // Request success // ByteBuf buf = MessageSerializer.serializeResponse(channel.alloc(), 1222112277L, response); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onRequestResult(eq(1222112277L), any(KvStateResponse.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Request failure // buf = MessageSerializer.serializeRequestFailure( channel.alloc(), 1222112278, new RuntimeException("Expected test Exception")); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onRequestFailure(eq(1222112278L), isA(RuntimeException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Server failure // buf = MessageSerializer.serializeServerFailure( channel.alloc(), new RuntimeException("Expected test Exception")); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onFailure(isA(RuntimeException.class)); // // Unexpected messages // buf = channel.alloc().buffer(4).writeInt(1223823); // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onFailure(isA(IllegalStateException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Exception caught // channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception")); verify(callback, times(3)).onFailure(isA(RuntimeException.class)); // // Channel inactive // channel.pipeline().fireChannelInactive(); verify(callback, times(1)).onFailure(isA(ClosedChannelException.class)); }
Example 6
Source File: KvStateClientHandlerTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that on reads the expected callback methods are called and read * buffers are recycled. */ @Test public void testReadCallbacksAndBufferRecycling() throws Exception { final ClientHandlerCallback<KvStateResponse> callback = mock(ClientHandlerCallback.class); final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); final EmbeddedChannel channel = new EmbeddedChannel(new ClientHandler<>("Test Client", serializer, callback)); final byte[] content = new byte[0]; final KvStateResponse response = new KvStateResponse(content); // // Request success // ByteBuf buf = MessageSerializer.serializeResponse(channel.alloc(), 1222112277L, response); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onRequestResult(eq(1222112277L), any(KvStateResponse.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Request failure // buf = MessageSerializer.serializeRequestFailure( channel.alloc(), 1222112278, new RuntimeException("Expected test Exception")); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onRequestFailure(eq(1222112278L), isA(RuntimeException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Server failure // buf = MessageSerializer.serializeServerFailure( channel.alloc(), new RuntimeException("Expected test Exception")); buf.skipBytes(4); // skip frame length // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onFailure(isA(RuntimeException.class)); // // Unexpected messages // buf = channel.alloc().buffer(4).writeInt(1223823); // Verify callback channel.writeInbound(buf); verify(callback, times(1)).onFailure(isA(IllegalStateException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); // // Exception caught // channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception")); verify(callback, times(3)).onFailure(isA(RuntimeException.class)); // // Channel inactive // channel.pipeline().fireChannelInactive(); verify(callback, times(1)).onFailure(isA(ClosedChannelException.class)); }