Search in sources :

Example 16 with RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel 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 RemoteInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel in project flink by apache.

the class InputGateConcurrentTest method testConsumptionWithMixedChannels.

@Test
public void testConsumptionWithMixedChannels() throws Exception {
    final int numChannels = 61;
    final int numLocalChannels = 20;
    final int buffersPerChannel = 1000;
    // fill the local/remote decision
    List<Boolean> localOrRemote = new ArrayList<>(numChannels);
    for (int i = 0; i < numChannels; i++) {
        localOrRemote.add(i < numLocalChannels);
    }
    Collections.shuffle(localOrRemote);
    final ConnectionManager connManager = createDummyConnectionManager();
    final ResultPartition resultPartition = mock(ResultPartition.class);
    final PipelinedSubpartition[] localPartitions = new PipelinedSubpartition[numLocalChannels];
    final ResultPartitionManager resultPartitionManager = createResultPartitionManager(localPartitions);
    final Source[] sources = new Source[numChannels];
    final SingleInputGate gate = new SingleInputGate("Test Task Name", new JobID(), new IntermediateDataSetID(), ResultPartitionType.PIPELINED, 0, numChannels, mock(TaskActions.class), new UnregisteredTaskMetricsGroup.DummyTaskIOMetricGroup());
    for (int i = 0, local = 0; i < numChannels; i++) {
        if (localOrRemote.get(i)) {
            // local channel
            PipelinedSubpartition psp = new PipelinedSubpartition(0, resultPartition);
            localPartitions[local++] = psp;
            sources[i] = new PipelinedSubpartitionSource(psp);
            LocalInputChannel channel = new LocalInputChannel(gate, i, new ResultPartitionID(), resultPartitionManager, mock(TaskEventDispatcher.class), new UnregisteredTaskMetricsGroup.DummyTaskIOMetricGroup());
            gate.setInputChannel(new IntermediateResultPartitionID(), channel);
        } else {
            //remote channel
            RemoteInputChannel channel = new RemoteInputChannel(gate, i, new ResultPartitionID(), mock(ConnectionID.class), connManager, 0, 0, new UnregisteredTaskMetricsGroup.DummyTaskIOMetricGroup());
            gate.setInputChannel(new IntermediateResultPartitionID(), channel);
            sources[i] = new RemoteChannelSource(channel);
        }
    }
    ProducerThread producer = new ProducerThread(sources, numChannels * buffersPerChannel, 4, 10);
    ConsumerThread consumer = new ConsumerThread(gate, numChannels * buffersPerChannel);
    producer.start();
    consumer.start();
    // the 'sync()' call checks for exceptions and failed assertions
    producer.sync();
    consumer.sync();
}
Also used : ArrayList(java.util.ArrayList) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ConnectionManager(org.apache.flink.runtime.io.network.ConnectionManager) InputChannelTestUtils.createDummyConnectionManager(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createDummyConnectionManager) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) UnregisteredTaskMetricsGroup(org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup) TaskActions(org.apache.flink.runtime.taskmanager.TaskActions) InputChannelTestUtils.createResultPartitionManager(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createResultPartitionManager) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) ConnectionID(org.apache.flink.runtime.io.network.ConnectionID) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) LocalInputChannel(org.apache.flink.runtime.io.network.partition.consumer.LocalInputChannel) JobID(org.apache.flink.api.common.JobID) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) Test(org.junit.Test)

Aggregations

RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)17 Test (org.junit.Test)15 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)8 RemoteTransportException (org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException)7 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 IOException (java.io.IOException)5 ConnectionID (org.apache.flink.runtime.io.network.ConnectionID)5 JobID (org.apache.flink.api.common.JobID)4 ConnectionManager (org.apache.flink.runtime.io.network.ConnectionManager)4 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)4 BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)4 LocalTransportException (org.apache.flink.runtime.io.network.netty.exception.LocalTransportException)4 InputChannelTestUtils.createDummyConnectionManager (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createDummyConnectionManager)4 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)4 IntermediateDataSetID (org.apache.flink.runtime.jobgraph.IntermediateDataSetID)4 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)4 UnregisteredTaskMetricsGroup (org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup)4 TaskActions (org.apache.flink.runtime.taskmanager.TaskActions)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4