Search in sources :

Example 16 with TestCheckpointedInputGateBuilder

use of org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder in project flink by apache.

the class AlternatingCheckpointsTest method testSwitchToUnalignedByUpstream.

/**
 * If a checkpoint announcement was processed from one channel and then UC-barrier arrives on
 * another channel, this UC barrier should be processed by the UC controller.
 */
@Test
public void testSwitchToUnalignedByUpstream() throws Exception {
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(2, getTestBarrierHandlerFactory(target)).build()) {
        CheckpointBarrier aligned = new CheckpointBarrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), Integer.MAX_VALUE));
        send(toBuffer(new EventAnnouncement(aligned, 0), true), 0, // process announcement but not the barrier
        gate);
        assertEquals(0, target.triggeredCheckpointCounter);
        send(toBuffer(aligned.asUnaligned(), true), 1, // pretend it came from upstream before the first (AC) barrier was picked
        gate);
        // up
        assertEquals(1, target.triggeredCheckpointCounter);
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EventAnnouncement(org.apache.flink.runtime.io.network.api.EventAnnouncement) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 17 with TestCheckpointedInputGateBuilder

use of org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder in project flink by apache.

the class AlternatingCheckpointsTest method testAlignedNeverTimeoutableCheckpoint.

@Test
public void testAlignedNeverTimeoutableCheckpoint() throws Exception {
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).build()) {
        Buffer neverTimeoutableCheckpoint = withTimeout(Integer.MAX_VALUE);
        send(neverTimeoutableCheckpoint, 0, gate);
        sendData(1000, 1, gate);
        assertEquals(0, target.getTriggeredCheckpointCounter());
        send(neverTimeoutableCheckpoint, 1, 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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 18 with TestCheckpointedInputGateBuilder

use of org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder in project flink by apache.

the class AlternatingCheckpointsTest method testNoActiveTimeoutAlignmentAfterClose.

@Test
public void testNoActiveTimeoutAlignmentAfterClose() throws Exception {
    int numberOfChannels = 2;
    ClockWithDelayedActions clockWithDelayedActions = new ClockWithDelayedActions() {

        @Override
        public Cancellable apply(Callable<?> callable, Duration delay) {
            super.apply(callable, delay);
            // do not unregister timers on cancel
            return () -> {
            };
        }
    };
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, TestBarrierHandlerFactory.forTarget(target).withActionRegistration(clockWithDelayedActions).withClock(clockWithDelayedActions)).withRemoteChannels().withSyncExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(alignmentTimeout);
    send(checkpointBarrier, 0, gate);
    gate.close();
    clockWithDelayedActions.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    assertThat(target.getTriggeredCheckpointOptions().size(), equalTo(0));
}
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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Duration(java.time.Duration) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 19 with TestCheckpointedInputGateBuilder

use of org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder in project flink by apache.

the class AlternatingCheckpointsTest method testChannelResetOnNewBarrier.

/**
 * Upon subsuming (or canceling) a checkpoint, channels should be notified regardless of whether
 * UC controller is currently being used or not. Otherwise, channels may not capture in-flight
 * buffers.
 */
@Test
public void testChannelResetOnNewBarrier() throws Exception {
    RecordingChannelStateWriter stateWriter = new RecordingChannelStateWriter();
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(2, getTestBarrierHandlerFactory(new ValidatingCheckpointHandler())).withChannelStateWriter(stateWriter).withRemoteChannels().withMailboxExecutor().build()) {
        sendBarrier(0, clock.relativeTimeMillis(), SavepointType.savepoint(SavepointFormatType.CANONICAL), gate, // using AC because UC would require ordering in gate while polling
        0);
        ((RemoteInputChannel) gate.getChannel(0)).onBuffer(createBuffer(1024), 1, // to be captured
        0);
        send(toBuffer(new CheckpointBarrier(1, clock.relativeTimeMillis(), unaligned(CheckpointType.CHECKPOINT, getDefault())), true), 1, gate);
        assertFalse(stateWriter.getAddedInput().isEmpty());
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) Test(org.junit.Test)

Example 20 with TestCheckpointedInputGateBuilder

use of org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder in project flink by apache.

the class AlternatingCheckpointsTest method testTimeoutAlignmentWhenLocalBarrierFirst.

@Test
public void testTimeoutAlignmentWhenLocalBarrierFirst() throws Exception {
    // given: Gate with remote and local channels.
    int numChannels = 3;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withMixedChannels(0).withMailboxExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(1, alignmentTimeout);
    // when: Execute the first checkpoint when announcement received first.
    ((TestInputChannel) gate.getChannel(0)).read(checkpointBarrier.retainBuffer());
    (getChannel(gate, 1)).onBuffer(checkpointBarrier.retainBuffer(), 0, 0);
    (getChannel(gate, 2)).onBuffer(checkpointBarrier.retainBuffer(), 0, 0);
    assertAnnouncement(gate);
    assertAnnouncement(gate);
    assertBarrier(gate);
    assertBarrier(gate);
    assertBarrier(gate);
    // then: The checkpoint executed successfully.
    assertEquals(1, target.getTriggeredCheckpointCounter());
    // given: The time in the future.
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    checkpointBarrier = withTimeout(2, alignmentTimeout);
    // when: Execute the second checkpoint when barrier from local channel without announcement
    // received first.
    ((TestInputChannel) gate.getChannel(0)).read(checkpointBarrier.retainBuffer());
    assertBarrier(gate);
    // then: Nothing happens because the alignment timeout should only start after this barrier.
    assertEquals(1, target.getTriggeredCheckpointCounter());
    // when: Receiving the barrier from second channel(with/without) announcement after time
    // more than alignment timeout.
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    (getChannel(gate, 1)).onBuffer(checkpointBarrier.retainBuffer(), 1, 0);
    assertAnnouncement(gate);
    assertBarrier(gate);
    // then: The checkpoint should started as unaligned.
    assertEquals(2, target.getTriggeredCheckpointCounter());
    List<CheckpointOptions> checkpointOptions = target.getTriggeredCheckpointOptions();
    assertEquals(AlignmentType.UNALIGNED, checkpointOptions.get(checkpointOptions.size() - 1).getAlignment());
}
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) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Test(org.junit.Test)

Aggregations

TestCheckpointedInputGateBuilder (org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder)27 Test (org.junit.Test)27 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)18 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)18 TestBufferFactory.createBuffer (org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer)18 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)4 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)4 RecordingChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter)2 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)2 EventAnnouncement (org.apache.flink.runtime.io.network.api.EventAnnouncement)2 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)2 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)1 SnapshotType (org.apache.flink.runtime.checkpoint.SnapshotType)1