Search in sources :

Example 1 with RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel in project flink by apache.

the class ClientTransportErrorHandlingTest method testChannelClosedOnExceptionDuringErrorNotification.

/**
	 * Verifies that the channel is closed if there is an error *during* error notification.
	 */
@Test
public void testChannelClosedOnExceptionDuringErrorNotification() throws Exception {
    EmbeddedChannel ch = createEmbeddedChannel();
    PartitionRequestClientHandler handler = getClientHandler(ch);
    RemoteInputChannel rich = addInputChannel(handler);
    doThrow(new RuntimeException("Expected test exception")).when(rich).onError(any(Throwable.class));
    ch.pipeline().fireExceptionCaught(new Exception());
    assertFalse(ch.isActive());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) 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)

Example 2 with RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel in project flink by apache.

the class ClientTransportErrorHandlingTest method testWrappingOfRemoteErrorMessage.

/**
	 * Verifies that {@link NettyMessage.ErrorResponse} messages are correctly wrapped in
	 * {@link RemoteTransportException} instances.
	 */
@Test
public void testWrappingOfRemoteErrorMessage() throws Exception {
    EmbeddedChannel ch = createEmbeddedChannel();
    PartitionRequestClientHandler 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);
    }
    // Error msg for channel[0]
    ch.pipeline().fireChannelRead(new NettyMessage.ErrorResponse(new RuntimeException("Expected test exception"), rich[0].getInputChannelId()));
    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.");
    }
    verify(rich[0], times(1)).onError(isA(RemoteTransportException.class));
    verify(rich[1], never()).onError(any(Throwable.class));
    // Fatal error for all channels
    ch.pipeline().fireChannelRead(new NettyMessage.ErrorResponse(new RuntimeException("Expected test 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.");
    }
    verify(rich[0], times(2)).onError(isA(RemoteTransportException.class));
    verify(rich[1], times(1)).onError(isA(RemoteTransportException.class));
}
Also used : RemoteTransportException(org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) 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)

Example 3 with RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel in project flink by apache.

the class ClientTransportErrorHandlingTest method testExceptionOnWrite.

/**
	 * Verifies that failed client requests via {@link PartitionRequestClient} are correctly
	 * attributed to the respective {@link RemoteInputChannel}.
	 */
@Test
public void testExceptionOnWrite() throws Exception {
    NettyProtocol protocol = new NettyProtocol() {

        @Override
        public ChannelHandler[] getServerChannelHandlers() {
            return new ChannelHandler[0];
        }

        @Override
        public ChannelHandler[] getClientChannelHandlers() {
            return new PartitionRequestProtocol(mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class), mock(NetworkBufferPool.class)).getClientChannelHandlers();
        }
    };
    // We need a real server and client in this test, because Netty's EmbeddedChannel is
    // not failing the ChannelPromise of failed writes.
    NettyServerAndClient serverAndClient = initServerAndClient(protocol, createConfig());
    Channel ch = connect(serverAndClient);
    PartitionRequestClientHandler handler = getClientHandler(ch);
    // Last outbound handler throws Exception after 1st write
    ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {

        int writeNum = 0;

        @Override
        public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
            if (writeNum >= 1) {
                throw new RuntimeException("Expected test exception.");
            }
            writeNum++;
            ctx.write(msg, promise);
        }
    });
    PartitionRequestClient requestClient = new PartitionRequestClient(ch, handler, mock(ConnectionID.class), mock(PartitionRequestClientFactory.class));
    // Create input channels
    RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(), createRemoteInputChannel() };
    final CountDownLatch sync = new CountDownLatch(1);
    // Do this with explicit synchronization. Otherwise this is not robust against slow timings
    // of the callback (e.g. we cannot just verify that it was called once, because there is
    // a chance that we do this too early).
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            sync.countDown();
            return null;
        }
    }).when(rich[1]).onError(isA(LocalTransportException.class));
    // First request is successful
    ChannelFuture f = requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[0], 0);
    assertTrue(f.await().isSuccess());
    // Second request is *not* successful
    f = requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[1], 0);
    assertFalse(f.await().isSuccess());
    // Only the second channel should be notified about the error
    verify(rich[0], times(0)).onError(any(LocalTransportException.class));
    // 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 the channel error.");
    }
    shutdown(serverAndClient);
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) ChannelHandler(io.netty.channel.ChannelHandler) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ChannelFuture(io.netty.channel.ChannelFuture) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) LocalTransportException(org.apache.flink.runtime.io.network.netty.exception.LocalTransportException) CountDownLatch(java.util.concurrent.CountDownLatch) LocalTransportException(org.apache.flink.runtime.io.network.netty.exception.LocalTransportException) RemoteTransportException(org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException) IOException(java.io.IOException) ConnectionID(org.apache.flink.runtime.io.network.ConnectionID) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) Test(org.junit.Test)

Example 4 with RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel in project flink by apache.

the class ClientTransportErrorHandlingTest method addInputChannel.

private RemoteInputChannel addInputChannel(PartitionRequestClientHandler clientHandler) throws IOException {
    RemoteInputChannel rich = createRemoteInputChannel();
    clientHandler.addInputChannel(rich);
    return rich;
}
Also used : RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)

Example 5 with RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel in project flink by apache.

the class PartitionRequestClientHandlerTest method testReceiveEmptyBuffer.

/**
	 * Tests a fix for FLINK-1761.
	 *
	 * <p> FLINK-1761 discovered an IndexOutOfBoundsException, when receiving buffers of size 0.
	 */
@Test
public void testReceiveEmptyBuffer() throws Exception {
    // Minimal mock of a remote input channel
    final BufferProvider bufferProvider = mock(BufferProvider.class);
    when(bufferProvider.requestBuffer()).thenReturn(TestBufferFactory.createBuffer());
    final RemoteInputChannel inputChannel = mock(RemoteInputChannel.class);
    when(inputChannel.getInputChannelId()).thenReturn(new InputChannelID());
    when(inputChannel.getBufferProvider()).thenReturn(bufferProvider);
    // An empty buffer of size 0
    final Buffer emptyBuffer = TestBufferFactory.createBuffer();
    emptyBuffer.setSize(0);
    final BufferResponse receivedBuffer = createBufferResponse(emptyBuffer, 0, inputChannel.getInputChannelId());
    final PartitionRequestClientHandler client = new PartitionRequestClientHandler();
    client.addInputChannel(inputChannel);
    // Read the empty buffer
    client.channelRead(mock(ChannelHandlerContext.class), receivedBuffer);
    // This should not throw an exception
    verify(inputChannel, never()).onError(any(Throwable.class));
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) BufferResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) Test(org.junit.Test)

Aggregations

RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)17 Test (org.junit.Test)15 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)8 RemoteTransportException (org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException)7 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 IOException (java.io.IOException)5 ConnectionID (org.apache.flink.runtime.io.network.ConnectionID)5 JobID (org.apache.flink.api.common.JobID)4 ConnectionManager (org.apache.flink.runtime.io.network.ConnectionManager)4 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)4 BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)4 LocalTransportException (org.apache.flink.runtime.io.network.netty.exception.LocalTransportException)4 InputChannelTestUtils.createDummyConnectionManager (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createDummyConnectionManager)4 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)4 IntermediateDataSetID (org.apache.flink.runtime.jobgraph.IntermediateDataSetID)4 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)4 UnregisteredTaskMetricsGroup (org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup)4 TaskActions (org.apache.flink.runtime.taskmanager.TaskActions)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4