Search in sources :

Example 11 with InputChannelID

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

the class PartitionRequestQueueTest method testProducerFailedException.

@Test
public void testProducerFailedException() throws Exception {
    PartitionRequestQueue queue = new PartitionRequestQueue();
    ResultPartitionProvider partitionProvider = mock(ResultPartitionProvider.class);
    ResultPartitionID rpid = new ResultPartitionID();
    BufferProvider bufferProvider = mock(BufferProvider.class);
    ResultSubpartitionView view = mock(ResultSubpartitionView.class);
    when(view.isReleased()).thenReturn(true);
    when(view.getFailureCause()).thenReturn(new RuntimeException("Expected test exception"));
    when(partitionProvider.createSubpartitionView(eq(rpid), eq(0), eq(bufferProvider), any(BufferAvailabilityListener.class))).thenReturn(view);
    EmbeddedChannel ch = new EmbeddedChannel(queue);
    SequenceNumberingViewReader seqView = new SequenceNumberingViewReader(new InputChannelID(), queue);
    seqView.requestSubpartitionView(partitionProvider, rpid, 0, bufferProvider);
    // Enqueue the erroneous view
    queue.notifyReaderNonEmpty(seqView);
    ch.runPendingTasks();
    // Read the enqueued msg
    Object msg = ch.readOutbound();
    assertEquals(msg.getClass(), NettyMessage.ErrorResponse.class);
    NettyMessage.ErrorResponse err = (NettyMessage.ErrorResponse) msg;
    assertTrue(err.cause instanceof CancelTaskException);
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) Test(org.junit.Test)

Example 12 with InputChannelID

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

the class ServerTransportErrorHandlingTest method testRemoteClose.

/**
	 * Verifies remote closes trigger the release of all resources.
	 */
@Test
public void testRemoteClose() throws Exception {
    final TestPooledBufferProvider outboundBuffers = new TestPooledBufferProvider(16);
    final CountDownLatch sync = new CountDownLatch(1);
    final ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    when(partitionManager.createSubpartitionView(any(ResultPartitionID.class), anyInt(), any(BufferProvider.class), any(BufferAvailabilityListener.class))).thenAnswer(new Answer<ResultSubpartitionView>() {

        @Override
        public ResultSubpartitionView answer(InvocationOnMock invocationOnMock) throws Throwable {
            BufferAvailabilityListener listener = (BufferAvailabilityListener) invocationOnMock.getArguments()[3];
            listener.notifyBuffersAvailable(Long.MAX_VALUE);
            return new CancelPartitionRequestTest.InfiniteSubpartitionView(outboundBuffers, sync);
        }
    });
    NettyProtocol protocol = new NettyProtocol() {

        @Override
        public ChannelHandler[] getServerChannelHandlers() {
            return new PartitionRequestProtocol(partitionManager, mock(TaskEventDispatcher.class), mock(NetworkBufferPool.class)).getServerChannelHandlers();
        }

        @Override
        public ChannelHandler[] getClientChannelHandlers() {
            return new ChannelHandler[] { new NettyMessage.NettyMessageEncoder(), // Close on read
            new ChannelInboundHandlerAdapter() {

                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                    ctx.channel().close();
                }
            } };
        }
    };
    NettyTestUtil.NettyServerAndClient serverAndClient = null;
    try {
        serverAndClient = initServerAndClient(protocol, createConfig());
        Channel ch = connect(serverAndClient);
        // Write something to trigger close by server
        ch.writeAndFlush(new NettyMessage.PartitionRequest(new ResultPartitionID(), 0, new InputChannelID()));
        // 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 released partition.");
        }
    } finally {
        shutdown(serverAndClient);
    }
}
Also used : TestPooledBufferProvider(org.apache.flink.runtime.io.network.util.TestPooledBufferProvider) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) TestPooledBufferProvider(org.apache.flink.runtime.io.network.util.TestPooledBufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) Channel(io.netty.channel.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.Test)

Aggregations

InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)12 Test (org.junit.Test)12 BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)8 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)7 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 Channel (io.netty.channel.Channel)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)4 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)4 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)3 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)3 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)3 TestPooledBufferProvider (org.apache.flink.runtime.io.network.util.TestPooledBufferProvider)3 IOException (java.io.IOException)2 TaskEventDispatcher (org.apache.flink.runtime.io.network.TaskEventDispatcher)2 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)2 CancelPartitionRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest)2