Search in sources :

Example 1 with TestingResultPartitionManager

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

the class UnionInputGateTest method testUpdateInputChannel.

@Test
public void testUpdateInputChannel() throws Exception {
    final SingleInputGate inputGate1 = createInputGate(1);
    TestInputChannel inputChannel1 = new TestInputChannel(inputGate1, 0);
    inputGate1.setInputChannels(inputChannel1);
    final SingleInputGate inputGate2 = createInputGate(1);
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(new NoOpResultSubpartitionView());
    InputChannel unknownInputChannel2 = InputChannelBuilder.newBuilder().setPartitionManager(partitionManager).buildUnknownChannel(inputGate2);
    inputGate2.setInputChannels(unknownInputChannel2);
    UnionInputGate unionInputGate = new UnionInputGate(inputGate1, inputGate2);
    ResultPartitionID resultPartitionID = unknownInputChannel2.getPartitionId();
    ResourceID location = ResourceID.generate();
    inputGate2.updateInputChannel(location, createRemoteWithIdAndLocation(resultPartitionID.getPartitionId(), location));
    assertThat(unionInputGate.getChannel(0), Matchers.is(inputChannel1));
    // Check that updated input channel is visible via UnionInputGate
    assertThat(unionInputGate.getChannel(1), Matchers.is(inputGate2.getChannel(0)));
}
Also used : NoOpResultSubpartitionView(org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 2 with TestingResultPartitionManager

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

the class LocalInputChannelTest method testAnnounceBufferSize.

@Test(expected = IllegalStateException.class)
public void testAnnounceBufferSize() throws Exception {
    // given: Initialized local input channel.
    AtomicInteger lastBufferSize = new AtomicInteger(0);
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(InputChannelTestUtils.createResultSubpartitionView(true));
    SingleInputGate inputGate = createSingleInputGate(1);
    LocalInputChannel localChannel = createLocalInputChannel(inputGate, partitionManager);
    localChannel.requestSubpartition();
    localChannel.announceBufferSize(10);
    // when: Release all resources.
    localChannel.releaseAllResources();
    // then: Announcement buffer size should lead to exception.
    localChannel.announceBufferSize(12);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 3 with TestingResultPartitionManager

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

the class LocalInputChannelTest method testGetNextAfterPartitionReleased.

/**
 * Tests that reading from a channel when after the partition has been released are handled and
 * don't lead to NPEs.
 */
@Test
public void testGetNextAfterPartitionReleased() throws Exception {
    ResultSubpartitionView subpartitionView = InputChannelTestUtils.createResultSubpartitionView(false);
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    LocalInputChannel channel = createLocalInputChannel(new SingleInputGateBuilder().build(), partitionManager);
    channel.requestSubpartition();
    assertFalse(channel.getNextBuffer().isPresent());
    // release the subpartition view
    subpartitionView.releaseAllResources();
    try {
        channel.getNextBuffer();
        fail("Did not throw expected CancelTaskException");
    } catch (CancelTaskException ignored) {
    }
    channel.releaseAllResources();
    assertFalse(channel.getNextBuffer().isPresent());
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 4 with TestingResultPartitionManager

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

the class LocalInputChannelTest method testReceivingBuffersInUseBeforeSubpartitionViewInitialization.

@Test
public void testReceivingBuffersInUseBeforeSubpartitionViewInitialization() throws Exception {
    // given: Local input channel without initialized subpartition view.
    ResultSubpartitionView subpartitionView = InputChannelTestUtils.createResultSubpartitionView(createFilledFinishedBufferConsumer(4096), createFilledFinishedBufferConsumer(4096), createFilledFinishedBufferConsumer(4096));
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    final SingleInputGate inputGate = createSingleInputGate(1);
    final LocalInputChannel localChannel = createLocalInputChannel(inputGate, partitionManager);
    inputGate.setInputChannels(localChannel);
    // then: Buffers in use should be equal to 0 until subpartition view initialization.
    assertEquals(0, localChannel.getBuffersInUseCount());
    // when: The subpartition view is initialized.
    localChannel.requestSubpartition();
    // then: Buffers in use should show correct value.
    assertEquals(3, localChannel.getBuffersInUseCount());
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 5 with TestingResultPartitionManager

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

the class LocalInputChannelTest method testCheckpointingInflightData.

@Test
public void testCheckpointingInflightData() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().build();
    PipelinedResultPartition parent = (PipelinedResultPartition) PartitionTestUtils.createPartition(ResultPartitionType.PIPELINED, NoOpFileChannelManager.INSTANCE);
    ResultSubpartition subpartition = parent.getAllPartitions()[0];
    ResultSubpartitionView subpartitionView = subpartition.createReadView(() -> {
    });
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    final RecordingChannelStateWriter stateWriter = new RecordingChannelStateWriter();
    LocalInputChannel channel = createLocalInputChannel(inputGate, partitionManager, 0, 0, b -> b.setStateWriter(stateWriter));
    inputGate.setInputChannels(channel);
    channel.requestSubpartition();
    final CheckpointStorageLocationReference location = getDefault();
    CheckpointOptions options = CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, location);
    stateWriter.start(0, options);
    final CheckpointBarrier barrier = new CheckpointBarrier(0, 123L, options);
    channel.checkpointStarted(barrier);
    // add 1 buffer before barrier and 1 buffer afterwards. Only the first buffer should be
    // written.
    subpartition.add(createFilledFinishedBufferConsumer(1));
    assertTrue(channel.getNextBuffer().isPresent());
    subpartition.add(EventSerializer.toBufferConsumer(barrier, true));
    assertTrue(channel.getNextBuffer().isPresent());
    subpartition.add(createFilledFinishedBufferConsumer(2));
    assertTrue(channel.getNextBuffer().isPresent());
    assertArrayEquals(stateWriter.getAddedInput().get(channel.getChannelInfo()).stream().mapToInt(Buffer::getSize).toArray(), new int[] { 1 });
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) PipelinedResultPartition(org.apache.flink.runtime.io.network.partition.PipelinedResultPartition) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) ResultSubpartition(org.apache.flink.runtime.io.network.partition.ResultSubpartition) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) Test(org.junit.Test)

Aggregations

TestingResultPartitionManager (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager)9 Test (org.junit.Test)9 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)8 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)5 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)3 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)3 PipelinedResultPartition (org.apache.flink.runtime.io.network.partition.PipelinedResultPartition)3 ResultSubpartition (org.apache.flink.runtime.io.network.partition.ResultSubpartition)3 RecordingChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)1 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)1 BufferBuilderTestUtils.createFilledFinishedBufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createFilledFinishedBufferConsumer)1 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)1 NoOpResultSubpartitionView (org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView)1 ResultPartitionBuilder (org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1 CheckpointStorageLocationReference (org.apache.flink.runtime.state.CheckpointStorageLocationReference)1