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)));
}
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);
}
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());
}
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());
}
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 });
}
Aggregations