use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView in project flink by apache.
the class PartitionRequestQueueTest method testBufferWriting.
private void testBufferWriting(ResultSubpartitionView view) throws IOException {
// setup
ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view;
final InputChannelID receiverId = new InputChannelID();
final PartitionRequestQueue queue = new PartitionRequestQueue();
final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, Integer.MAX_VALUE, queue);
final EmbeddedChannel channel = new EmbeddedChannel(queue);
reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0);
// notify about buffer availability and encode one buffer
reader.notifyDataAvailable();
channel.runPendingTasks();
Object read = channel.readOutbound();
assertNotNull(read);
if (read instanceof NettyMessage.ErrorResponse) {
((NettyMessage.ErrorResponse) read).cause.printStackTrace();
}
assertThat(read, instanceOf(NettyMessage.BufferResponse.class));
read = channel.readOutbound();
assertNull(read);
}
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(BufferAvailabilityListener.class))).thenAnswer(new Answer<ResultSubpartitionView>() {
@Override
public ResultSubpartitionView answer(InvocationOnMock invocationOnMock) throws Throwable {
BufferAvailabilityListener listener = (BufferAvailabilityListener) invocationOnMock.getArguments()[2];
listener.notifyDataAvailable();
return new CancelPartitionRequestTest.InfiniteSubpartitionView(outboundBuffers, sync);
}
});
NettyProtocol protocol = new NettyProtocol(partitionManager, mock(TaskEventDispatcher.class)) {
@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 {
for (int retry = 0; retry < NETTY_INIT_MAX_RETRY_TIMES; retry++) {
try {
serverAndClient = initServerAndClient(protocol, createConfig());
break;
} catch (Exception e) {
if (retry >= NETTY_INIT_MAX_RETRY_TIMES - 1) {
throw new RuntimeException("Failed to initialize netty server and client, retried " + retry + " times.", e);
}
if (e instanceof BindException || ExceptionUtils.findThrowableWithMessage(e, "Address already in use").isPresent()) {
continue;
}
throw e;
}
}
Channel ch = connect(serverAndClient);
// Write something to trigger close by server
ch.writeAndFlush(new NettyMessage.PartitionRequest(new ResultPartitionID(), 0, new InputChannelID(), Integer.MAX_VALUE));
// 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