Search in sources :

Example 6 with ResultPartitionManager

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);
}
Also used : InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) Test(org.junit.Test)

Example 7 with ResultPartitionManager

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));
}
Also used : PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) ErrorResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse) Test(org.junit.Test)

Example 8 with ResultPartitionManager

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);
}
Also used : InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) Test(org.junit.Test)

Example 9 with ResultPartitionManager

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()));
    }
}
Also used : PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) Test(org.junit.Test)

Example 10 with ResultPartitionManager

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);
    }
}
Also used : TestPooledBufferProvider(org.apache.flink.runtime.io.network.util.TestPooledBufferProvider) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) CancelPartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) CancelPartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) Test(org.junit.Test)

Aggregations

ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)27 Test (org.junit.Test)22 TaskEventDispatcher (org.apache.flink.runtime.io.network.TaskEventDispatcher)13 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)12 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)9 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)7 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)7 TestingResultPartitionManager (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager)7 IOException (java.io.IOException)6 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)6 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)6 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)6 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)6 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)6 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)6 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 JobID (org.apache.flink.api.common.JobID)5 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)5 Executor (java.util.concurrent.Executor)4