Search in sources :

Example 6 with NetworkClientHandler

use of org.apache.flink.runtime.io.network.NetworkClientHandler in project flink by apache.

the class ClientTransportErrorHandlingTest method testExceptionOnRemoteClose.

/**
 * Verifies that unexpected remote closes are reported as an instance of {@link
 * RemoteTransportException}.
 */
@Test
public void testExceptionOnRemoteClose() throws Exception {
    NettyProtocol protocol = new NettyProtocol(mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class)) {

        @Override
        public ChannelHandler[] getServerChannelHandlers() {
            return new ChannelHandler[] { // Close on read
            new ChannelInboundHandlerAdapter() {

                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                    ctx.channel().close();
                }
            } };
        }
    };
    NettyServerAndClient serverAndClient = initServerAndClient(protocol, createConfig());
    Channel ch = connect(serverAndClient);
    NetworkClientHandler handler = getClientHandler(ch);
    // Create input channels
    RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(), createRemoteInputChannel() };
    final CountDownLatch sync = new CountDownLatch(rich.length);
    Answer<Void> countDownLatch = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            sync.countDown();
            return null;
        }
    };
    for (RemoteInputChannel r : rich) {
        doAnswer(countDownLatch).when(r).onError(any(Throwable.class));
        handler.addInputChannel(r);
    }
    // Write something to trigger close by server
    ch.writeAndFlush(Unpooled.buffer().writerIndex(16));
    // Wait for the notification
    if (!sync.await(TestingUtils.TESTING_DURATION.toMillis(), TimeUnit.MILLISECONDS)) {
        fail("Timed out after waiting for " + TestingUtils.TESTING_DURATION.toMillis() + " ms to be notified about remote connection close.");
    }
    // All the registered channels should be notified.
    for (RemoteInputChannel r : rich) {
        verify(r).onError(isA(RemoteTransportException.class));
    }
    shutdown(serverAndClient);
}
Also used : RemoteTransportException(org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException) NetworkClientHandler(org.apache.flink.runtime.io.network.NetworkClientHandler) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) ChannelHandlerContext(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext) ChannelHandler(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler) CountDownLatch(java.util.concurrent.CountDownLatch) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) ChannelInboundHandlerAdapter(org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.Test)

Example 7 with NetworkClientHandler

use of org.apache.flink.runtime.io.network.NetworkClientHandler in project flink by apache.

the class ClientTransportErrorHandlingTest method testExceptionCaught.

/**
 * Verifies that fired Exceptions are handled correctly by the pipeline.
 */
@Test
public void testExceptionCaught() throws Exception {
    EmbeddedChannel ch = createEmbeddedChannel();
    NetworkClientHandler handler = getClientHandler(ch);
    // Create input channels
    RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(), createRemoteInputChannel() };
    for (RemoteInputChannel r : rich) {
        when(r.getInputChannelId()).thenReturn(new InputChannelID());
        handler.addInputChannel(r);
    }
    ch.pipeline().fireExceptionCaught(new Exception());
    try {
        // Exception should not reach end of pipeline...
        ch.checkException();
    } catch (Exception e) {
        fail("The exception reached the end of the pipeline and " + "was not handled correctly by the last handler.");
    }
    // ...but all the registered channels should be notified.
    for (RemoteInputChannel r : rich) {
        verify(r).onError(isA(LocalTransportException.class));
    }
}
Also used : NetworkClientHandler(org.apache.flink.runtime.io.network.NetworkClientHandler) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) LocalTransportException(org.apache.flink.runtime.io.network.netty.exception.LocalTransportException) LocalTransportException(org.apache.flink.runtime.io.network.netty.exception.LocalTransportException) RemoteTransportException(org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException) IOException(java.io.IOException) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) Test(org.junit.Test)

Aggregations

NetworkClientHandler (org.apache.flink.runtime.io.network.NetworkClientHandler)7 RemoteTransportException (org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException)7 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)7 IOException (java.io.IOException)6 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)6 Test (org.junit.Test)6 LocalTransportException (org.apache.flink.runtime.io.network.netty.exception.LocalTransportException)4 Channel (org.apache.flink.shaded.netty4.io.netty.channel.Channel)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 TaskEventDispatcher (org.apache.flink.runtime.io.network.TaskEventDispatcher)2 NettyServerAndClient (org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient)2 ResultPartitionProvider (org.apache.flink.runtime.io.network.partition.ResultPartitionProvider)2 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)2 ChannelHandler (org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler)2 ChannelHandlerContext (org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext)2 ExecutionException (java.util.concurrent.ExecutionException)1 ConnectionID (org.apache.flink.runtime.io.network.ConnectionID)1 PartitionRequestClient (org.apache.flink.runtime.io.network.PartitionRequestClient)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1