Search in sources :

Example 16 with BufferProvider

use of org.apache.flink.runtime.io.network.buffer.BufferProvider in project flink by apache.

the class PartitionRequestClientHandlerTest method testReceivePartitionNotFoundException.

/**
	 * Verifies that {@link RemoteInputChannel#onFailedPartitionRequest()} is called when a
	 * {@link PartitionNotFoundException} is received.
	 */
@Test
public void testReceivePartitionNotFoundException() throws Exception {
    // Minimal mock of a remote input channel
    final BufferProvider bufferProvider = mock(BufferProvider.class);
    when(bufferProvider.requestBuffer()).thenReturn(TestBufferFactory.createBuffer());
    final RemoteInputChannel inputChannel = mock(RemoteInputChannel.class);
    when(inputChannel.getInputChannelId()).thenReturn(new InputChannelID());
    when(inputChannel.getBufferProvider()).thenReturn(bufferProvider);
    final ErrorResponse partitionNotFound = new ErrorResponse(new PartitionNotFoundException(new ResultPartitionID()), inputChannel.getInputChannelId());
    final PartitionRequestClientHandler client = new PartitionRequestClientHandler();
    client.addInputChannel(inputChannel);
    // Mock channel context
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.channel()).thenReturn(mock(Channel.class));
    client.channelActive(ctx);
    client.channelRead(ctx, partitionNotFound);
    verify(inputChannel, times(1)).onFailedPartitionRequest();
}
Also used : PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ErrorResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse) Test(org.junit.Test)

Example 17 with BufferProvider

use of org.apache.flink.runtime.io.network.buffer.BufferProvider in project flink by apache.

the class PartitionRequestQueueTest method testProducerFailedException.

@Test
public void testProducerFailedException() throws Exception {
    PartitionRequestQueue queue = new PartitionRequestQueue();
    ResultPartitionProvider partitionProvider = mock(ResultPartitionProvider.class);
    ResultPartitionID rpid = new ResultPartitionID();
    BufferProvider bufferProvider = mock(BufferProvider.class);
    ResultSubpartitionView view = mock(ResultSubpartitionView.class);
    when(view.isReleased()).thenReturn(true);
    when(view.getFailureCause()).thenReturn(new RuntimeException("Expected test exception"));
    when(partitionProvider.createSubpartitionView(eq(rpid), eq(0), eq(bufferProvider), any(BufferAvailabilityListener.class))).thenReturn(view);
    EmbeddedChannel ch = new EmbeddedChannel(queue);
    SequenceNumberingViewReader seqView = new SequenceNumberingViewReader(new InputChannelID(), queue);
    seqView.requestSubpartitionView(partitionProvider, rpid, 0, bufferProvider);
    // Enqueue the erroneous view
    queue.notifyReaderNonEmpty(seqView);
    ch.runPendingTasks();
    // Read the enqueued msg
    Object msg = ch.readOutbound();
    assertEquals(msg.getClass(), NettyMessage.ErrorResponse.class);
    NettyMessage.ErrorResponse err = (NettyMessage.ErrorResponse) msg;
    assertTrue(err.cause instanceof CancelTaskException);
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) Test(org.junit.Test)

Aggregations

BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)17 Test (org.junit.Test)11 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)5 TestInfiniteBufferProvider (org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider)5 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 IOException (java.io.IOException)3 MemorySegment (org.apache.flink.core.memory.MemorySegment)3 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)3 ResultPartitionWriter (org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter)3 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)3 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)3 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)3 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Queue (java.util.Queue)2 ExecutorService (java.util.concurrent.ExecutorService)2