Search in sources :

Example 11 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testNextFirstCheckpointBarrierOvertakesCancellationBarrier.

@Test
public void testNextFirstCheckpointBarrierOvertakesCancellationBarrier() throws Exception {
    int numberOfChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withSyncExecutor().build();
    long alignmentTimeout = 10000;
    Buffer checkpointBarrier = withTimeout(alignmentTimeout);
    send(checkpointBarrier, 0, gate);
    clock.advanceTime(Duration.ofSeconds(1));
    send(withTimeout(2, alignmentTimeout), 0, gate);
    clock.advanceTime(Duration.ofSeconds(1));
    send(toBuffer(new CancelCheckpointMarker(1L), true), 1, gate);
    clock.advanceTime(Duration.ofSeconds(1));
    send(withTimeout(2, alignmentTimeout), 1, gate);
    clock.advanceTime(Duration.ofSeconds(1));
    assertEquals(Duration.ofSeconds(2).toNanos(), target.lastAlignmentDurationNanos.get().longValue());
}
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) CancelCheckpointMarker(org.apache.flink.runtime.io.network.api.CancelCheckpointMarker) Test(org.junit.Test)

Example 12 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testActiveTimeoutBeforeFirstAnnouncementPassiveTimeout.

@Test
public void testActiveTimeoutBeforeFirstAnnouncementPassiveTimeout() throws Exception {
    // given: Two barriers from two channels.
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build()) {
        long alignmentCheckpointTimeout = 10;
        Buffer checkpointBarrier = withTimeout(alignmentCheckpointTimeout);
        getChannel(gate, 0).onBuffer(dataBuffer(), 0, 0);
        getChannel(gate, 0).onBuffer(checkpointBarrier.retainBuffer(), 1, 0);
        getChannel(gate, 1).onBuffer(dataBuffer(), 0, 0);
        getChannel(gate, 1).onBuffer(checkpointBarrier.retainBuffer(), 1, 0);
        assertEquals(0, target.getTriggeredCheckpointCounter());
        // when: The receiving of the first announcement is delayed on more than alignment
        // checkpoint timeout.
        clock.advanceTimeWithoutRunningCallables(alignmentCheckpointTimeout + 1, TimeUnit.MILLISECONDS);
        assertAnnouncement(gate);
        // we simulate active time out firing after the passive one
        clock.executeCallables();
        // then: Barriers should be reprioritized and the UC should be triggered.
        assertAnnouncement(gate);
        assertBarrier(gate);
        assertBarrier(gate);
        assertEquals(1, target.getTriggeredCheckpointCounter());
        assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault())));
        // Followed by overtaken buffers
        assertData(gate);
        assertData(gate);
    }
}
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 13 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testActiveTimeoutAlignmentOnFirstBarrier.

@Test
public void testActiveTimeoutAlignmentOnFirstBarrier() throws Exception {
    int numberOfChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withSyncExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(alignmentTimeout);
    send(checkpointBarrier, 0, gate);
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault())));
}
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 14 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testNoActiveTimeoutAlignmentAfterLastBarrier.

@Test
public void testNoActiveTimeoutAlignmentAfterLastBarrier() throws Exception {
    int numberOfChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withSyncExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(alignmentTimeout);
    send(checkpointBarrier, 0, gate);
    send(checkpointBarrier, 1, gate);
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    assertThat(target.getTriggeredCheckpointOptions(), not(contains(unaligned(CheckpointType.CHECKPOINT, getDefault()))));
}
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 15 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testAllChannelsUnblockedAfterAlignmentTimeout.

@Test
public void testAllChannelsUnblockedAfterAlignmentTimeout() throws Exception {
    int numberOfChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withSyncExecutor().build();
    long alignmentTimeout = 100;
    CheckpointBarrier checkpointBarrier = new CheckpointBarrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeout));
    Buffer checkpointBarrierBuffer = toBuffer(checkpointBarrier, false);
    // we set timer on announcement and test channels do not produce announcements by themselves
    send(EventSerializer.toBuffer(new EventAnnouncement(checkpointBarrier, 0), true), 0, gate);
    // emulate blocking channels on aligned barriers
    ((TestInputChannel) gate.getChannel(0)).setBlocked(true);
    send(checkpointBarrierBuffer, 0, gate);
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    send(EventSerializer.toBuffer(new EventAnnouncement(checkpointBarrier, 0), true), 1, gate);
    // emulate blocking channels on aligned barriers
    ((TestInputChannel) gate.getChannel(1)).setBlocked(true);
    send(checkpointBarrierBuffer, 1, gate);
    assertThat(target.getTriggeredCheckpointOptions().size(), equalTo(1));
    assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault())));
    assertFalse(((TestInputChannel) gate.getChannel(0)).isBlocked());
    assertFalse(((TestInputChannel) gate.getChannel(1)).isBlocked());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) 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) EventAnnouncement(org.apache.flink.runtime.io.network.api.EventAnnouncement) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) 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