use of org.apache.flink.runtime.io.network.partition.ResultPartitionManager in project flink by apache.
the class PartitionRequestServerHandlerTest method testNewBufferSize.
@Test
public void testNewBufferSize() {
final InputChannelID inputChannelID = new InputChannelID();
final PartitionRequestQueue partitionRequestQueue = new PartitionRequestQueue();
final TestViewReader testViewReader = new TestViewReader(inputChannelID, 2, partitionRequestQueue);
final PartitionRequestServerHandler serverHandler = new PartitionRequestServerHandler(new ResultPartitionManager(), new TaskEventDispatcher(), partitionRequestQueue);
final EmbeddedChannel channel = new EmbeddedChannel(serverHandler);
partitionRequestQueue.notifyReaderCreated(testViewReader);
// Write the message of new buffer size to server
channel.writeInbound(new NettyMessage.NewBufferSize(666, inputChannelID));
channel.runPendingTasks();
assertEquals(666, testViewReader.bufferSize);
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionManager in project flink by apache.
the class PartitionRequestServerHandlerTest method testResponsePartitionNotFoundException.
/**
* Tests that {@link PartitionRequestServerHandler} responds {@link ErrorResponse} with wrapped
* {@link PartitionNotFoundException} after receiving invalid {@link PartitionRequest}.
*/
@Test
public void testResponsePartitionNotFoundException() {
final PartitionRequestServerHandler serverHandler = new PartitionRequestServerHandler(new ResultPartitionManager(), new TaskEventDispatcher(), new PartitionRequestQueue());
final EmbeddedChannel channel = new EmbeddedChannel(serverHandler);
final ResultPartitionID partitionId = new ResultPartitionID();
// Write the message of partition request to server
channel.writeInbound(new PartitionRequest(partitionId, 0, new InputChannelID(), 2));
channel.runPendingTasks();
// Read the response message after handling partition request
final Object msg = channel.readOutbound();
assertThat(msg, instanceOf(ErrorResponse.class));
final ErrorResponse err = (ErrorResponse) msg;
assertThat(err.cause, instanceOf(PartitionNotFoundException.class));
final ResultPartitionID actualPartitionId = ((PartitionNotFoundException) err.cause).getPartitionId();
assertThat(partitionId, is(actualPartitionId));
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionManager in project flink by apache.
the class PartitionRequestServerHandlerTest method testReceivingNewBufferSizeBeforeReaderIsCreated.
@Test
public void testReceivingNewBufferSizeBeforeReaderIsCreated() {
final InputChannelID inputChannelID = new InputChannelID();
final PartitionRequestQueue partitionRequestQueue = new PartitionRequestQueue();
final TestViewReader testViewReader = new TestViewReader(inputChannelID, 2, partitionRequestQueue);
final PartitionRequestServerHandler serverHandler = new PartitionRequestServerHandler(new ResultPartitionManager(), new TaskEventDispatcher(), partitionRequestQueue);
final EmbeddedChannel channel = new EmbeddedChannel(serverHandler);
// Write the message of new buffer size to server without prepared reader.
channel.writeInbound(new NettyMessage.NewBufferSize(666, inputChannelID));
channel.runPendingTasks();
// If error happens outbound messages would be not empty.
assertTrue(channel.outboundMessages().toString(), channel.outboundMessages().isEmpty());
// New buffer size should be silently ignored because it is possible situation.
assertEquals(-1, testViewReader.bufferSize);
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionManager in project flink by apache.
the class SingleInputGateTest method testPartitionNotFoundExceptionWhileGetNextBuffer.
/**
* Tests that if the {@link PartitionNotFoundException} is set onto one {@link InputChannel},
* then it would be thrown directly via {@link SingleInputGate#getNext()}. So we could confirm
* the {@link SingleInputGate} would not swallow or transform the original exception.
*/
@Test
public void testPartitionNotFoundExceptionWhileGetNextBuffer() throws Exception {
final SingleInputGate inputGate = InputChannelTestUtils.createSingleInputGate(1);
final LocalInputChannel localChannel = createLocalInputChannel(inputGate, new ResultPartitionManager());
final ResultPartitionID partitionId = localChannel.getPartitionId();
inputGate.setInputChannels(localChannel);
localChannel.setError(new PartitionNotFoundException(partitionId));
try {
inputGate.getNext();
fail("Should throw a PartitionNotFoundException.");
} catch (PartitionNotFoundException notFound) {
assertThat(partitionId, is(notFound.getPartitionId()));
}
}
use of org.apache.flink.runtime.io.network.partition.ResultPartitionManager in project flink by apache.
the class CancelPartitionRequestTest method testDuplicateCancel.
@Test
public void testDuplicateCancel() throws Exception {
NettyServerAndClient serverAndClient = null;
try {
final TestPooledBufferProvider outboundBuffers = new TestPooledBufferProvider(16);
ResultPartitionManager partitions = mock(ResultPartitionManager.class);
ResultPartitionID pid = new ResultPartitionID();
final CountDownLatch sync = new CountDownLatch(1);
final ResultSubpartitionView view = spy(new InfiniteSubpartitionView(outboundBuffers, sync));
// Return infinite subpartition
when(partitions.createSubpartitionView(eq(pid), eq(0), any(BufferAvailabilityListener.class))).thenAnswer(new Answer<ResultSubpartitionView>() {
@Override
public ResultSubpartitionView answer(InvocationOnMock invocationOnMock) throws Throwable {
BufferAvailabilityListener listener = (BufferAvailabilityListener) invocationOnMock.getArguments()[2];
listener.notifyDataAvailable();
return view;
}
});
NettyProtocol protocol = new NettyProtocol(partitions, mock(TaskEventDispatcher.class));
serverAndClient = initServerAndClient(protocol);
Channel ch = connect(serverAndClient);
// Request for non-existing input channel => results in cancel request
InputChannelID inputChannelId = new InputChannelID();
ch.writeAndFlush(new PartitionRequest(pid, 0, inputChannelId, Integer.MAX_VALUE)).await();
// 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 cancelled partition.");
}
ch.writeAndFlush(new CancelPartitionRequest(inputChannelId)).await();
ch.close();
NettyTestUtil.awaitClose(ch);
verify(view, times(1)).releaseAllResources();
} finally {
shutdown(serverAndClient);
}
}
Aggregations