Search in sources :

Example 11 with ResultSubpartitionView

use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView 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

ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)11 BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)8 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)8 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)8 Test (org.junit.Test)8 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)7 TaskEventDispatcher (org.apache.flink.runtime.io.network.TaskEventDispatcher)5 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)4 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)4 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Channel (io.netty.channel.Channel)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)3 TestPooledBufferProvider (org.apache.flink.runtime.io.network.util.TestPooledBufferProvider)3 UnregisteredTaskMetricsGroup (org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup)3 JobID (org.apache.flink.api.common.JobID)2 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)2 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)2