Search in sources :

Example 1 with TestInputChannel

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

the class TestCheckpointedInputGateBuilder method buildMixedGate.

private SingleInputGate buildMixedGate(Integer... testChannelIds) throws IOException {
    Set<Integer> testChannelIdSet = new HashSet<>(Arrays.asList(testChannelIds));
    SingleInputGate gate = buildRemoteGate();
    InputChannel[] channels = new InputChannel[numChannels];
    for (int i = 0; i < numChannels; i++) {
        if (testChannelIdSet.contains(i)) {
            channels[i] = new TestInputChannel(gate, i, false, true);
        } else {
            channels[i] = gate.getChannel(i);
        }
    }
    gate.setInputChannels(channels);
    return gate;
}
Also used : TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) HashSet(java.util.HashSet)

Example 2 with TestInputChannel

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

the class AlternatingCheckpointsTest method testHasInflightDataBeforeProcessBarrier.

@Test
public void testHasInflightDataBeforeProcessBarrier() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    inputGate.setInputChannels(new TestInputChannel(inputGate, 0), new TestInputChannel(inputGate, 1));
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(inputGate);
    final long id = 1;
    barrierHandler.processBarrier(new CheckpointBarrier(id, clock.relativeTimeMillis(), new CheckpointOptions(CHECKPOINT, getDefault())), new InputChannelInfo(0, 0), false);
    assertFalse(barrierHandler.getAllBarriersReceivedFuture(id).isDone());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Example 3 with TestInputChannel

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

the class AlternatingCheckpointsTest method testPreviousHandlerReset.

@Test
public void testPreviousHandlerReset() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    TestInputChannel[] channels = { new TestInputChannel(inputGate, 0), new TestInputChannel(inputGate, 1) };
    inputGate.setInputChannels(channels);
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(inputGate);
    for (int i = 0; i < 4; i++) {
        int channel = i % 2;
        SnapshotType type = channel == 0 ? SavepointType.savepoint(SavepointFormatType.CANONICAL) : CHECKPOINT;
        target.setNextExpectedCheckpointId(-1);
        if (type.isSavepoint()) {
            channels[channel].setBlocked(true);
        }
        barrierHandler.processBarrier(new CheckpointBarrier(i, clock.relativeTimeMillis(), new CheckpointOptions(type, getDefault())), new InputChannelInfo(0, channel), false);
        if (type.isSavepoint()) {
            assertTrue(channels[channel].isBlocked());
            assertFalse(channels[(channel + 1) % 2].isBlocked());
        } else {
            assertFalse(channels[0].isBlocked());
            assertFalse(channels[1].isBlocked());
        }
        assertTrue(barrierHandler.isCheckpointPending());
        assertFalse(barrierHandler.getAllBarriersReceivedFuture(i).isDone());
        channels[0].setBlocked(false);
        channels[1].setBlocked(false);
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) SnapshotType(org.apache.flink.runtime.checkpoint.SnapshotType) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Example 4 with TestInputChannel

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

the class AlternatingCheckpointsTest method testTimeoutAlignmentBeforeFirstBarrier.

@Test
public void testTimeoutAlignmentBeforeFirstBarrier() throws Exception {
    // given: Local channels.
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withMailboxExecutor().build();
    long alignedCheckpointTimeout = 100;
    // when: Aligned checkpoint timeout expired before the first barrier received.
    Buffer checkpointBarrier = withTimeout(1, alignedCheckpointTimeout);
    clock.advanceTime(alignedCheckpointTimeout + 1, TimeUnit.MILLISECONDS);
    ((TestInputChannel) gate.getChannel(0)).read(checkpointBarrier.retainBuffer());
    // then: The UC is triggered as soon as the first barrier is received.
    assertBarrier(gate);
    assertEquals(1, target.getTriggeredCheckpointCounter());
}
Also used : TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 5 with TestInputChannel

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

the class AlternatingCheckpointsTest method testOutOfOrderBarrier.

@Test
public void testOutOfOrderBarrier() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    TestInputChannel firstChannel = new TestInputChannel(inputGate, 0);
    TestInputChannel secondChannel = new TestInputChannel(inputGate, 1);
    inputGate.setInputChannels(firstChannel, secondChannel);
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(inputGate);
    long checkpointId = 10;
    long outOfOrderSavepointId = 5;
    barrierHandler.processBarrier(new CheckpointBarrier(checkpointId, clock.relativeTimeMillis(), new CheckpointOptions(CHECKPOINT, getDefault())), new InputChannelInfo(0, 0), false);
    secondChannel.setBlocked(true);
    barrierHandler.processBarrier(new CheckpointBarrier(outOfOrderSavepointId, clock.relativeTimeMillis(), new CheckpointOptions(SavepointType.savepoint(SavepointFormatType.CANONICAL), getDefault())), new InputChannelInfo(0, 1), false);
    assertEquals(checkpointId, barrierHandler.getLatestCheckpointId());
    assertFalse(secondChannel.isBlocked());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Aggregations

TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)12 Test (org.junit.Test)8 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)6 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)6 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)5 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)5 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)5 TestBufferFactory.createBuffer (org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer)5 TestCheckpointedInputGateBuilder (org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder)4 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)3 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)3 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1