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);
}
}
Aggregations