Search in sources :

Example 1 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testTimeoutAlignmentOnFirstBarrier.

/**
 * This test tries to make sure that the first time out happens after processing {@link
 * EventAnnouncement} but before/during processing the first {@link CheckpointBarrier}.
 */
@Test
public void testTimeoutAlignmentOnFirstBarrier() throws Exception {
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(alignmentTimeout);
    for (int i = 0; i < numChannels; i++) {
        (getChannel(gate, i)).onBuffer(checkpointBarrier.retainBuffer(), 0, 0);
    }
    assertEquals(0, target.getTriggeredCheckpointCounter());
    for (int i = 0; i < numChannels; i++) {
        assertAnnouncement(gate);
    }
    assertEquals(0, target.getTriggeredCheckpointCounter());
    clock.advanceTime(alignmentTimeout * 4, TimeUnit.MILLISECONDS);
    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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 2 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testAlignedAfterTimedOut.

@Test
public void testAlignedAfterTimedOut() throws Exception {
    int numChannels = 1;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    long alignmentTimeOut = 100L;
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build()) {
        Buffer barrier1 = barrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut));
        ((RemoteInputChannel) gate.getChannel(0)).onBuffer(barrier1.retainBuffer(), 0, 0);
        assertAnnouncement(gate);
        clock.advanceTime(alignmentTimeOut + 1, TimeUnit.MILLISECONDS);
        assertBarrier(gate);
        assertEquals(1, target.getTriggeredCheckpointCounter());
        Buffer barrier2 = barrier(2, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut));
        ((RemoteInputChannel) gate.getChannel(0)).onBuffer(barrier2.retainBuffer(), 1, 0);
        assertAnnouncement(gate);
        assertBarrier(gate);
        assertEquals(2, target.getTriggeredCheckpointCounter());
        assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault()), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut)));
    }
}
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) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) Test(org.junit.Test)

Example 3 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testStartNewCheckpointViaAnnouncement.

/**
 * This test verifies a special case that the checkpoint handler starts the new checkpoint via
 * received barrier announcement from the first channel, then {@link EndOfPartitionEvent} from
 * the second channel and then the barrier from the first channel. In this case we should ensure
 * the {@link SingleCheckpointBarrierHandler#markAlignmentStart(long, long)} should be called.
 * More information is available in https://issues.apache.org/jira/browse/FLINK-24068.
 */
@Test
public void testStartNewCheckpointViaAnnouncement() throws Exception {
    int numChannels = 3;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    long alignmentTimeOut = 10000L;
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build()) {
        getChannel(gate, 0).onBuffer(barrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut)), 0, 0);
        getChannel(gate, 1).onBuffer(endOfPartition(), 0, 0);
        // The barrier announcement would start the checkpoint.
        assertAnnouncement(gate);
        // When received the EndOfPartition from channel 1 markAlignmentStart should be called.
        assertEvent(gate, EndOfPartitionEvent.class);
        assertTrue(gate.getCheckpointBarrierHandler().isDuringAlignment());
        // Received barrier from channel 0.
        assertBarrier(gate);
        // The last barrier from channel 2 finalize the checkpoint.
        getChannel(gate, 2).onBuffer(barrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut)), 0, 0);
        assertAnnouncement(gate);
        assertBarrier(gate);
        assertThat(target.triggeredCheckpoints, contains(1L));
    }
}
Also used : TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 4 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testTimeoutAlignmentAfterReceivedEndOfPartition.

@Test
public void testTimeoutAlignmentAfterReceivedEndOfPartition() throws Exception {
    int numChannels = 3;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    long alignmentTimeOut = 100L;
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build()) {
        getChannel(gate, 0).onBuffer(barrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut)), 0, 0);
        assertAnnouncement(gate);
        assertBarrier(gate);
        // Advances time but do not execute the registered callable which would turns into
        // unaligned checkpoint.
        clock.advanceTimeWithoutRunningCallables(alignmentTimeOut + 1, TimeUnit.MILLISECONDS);
        // The EndOfPartition should convert the checkpoint into unaligned.
        getChannel(gate, 1).onBuffer(dataBuffer(), 0, 0);
        getChannel(gate, 1).onBuffer(endOfPartition(), 1, 0);
        assertData(gate);
        assertEvent(gate, EndOfPartitionEvent.class);
        getChannel(gate, 2).onBuffer(dataBuffer(), 0, 0);
        getChannel(gate, 2).onBuffer(endOfPartition(), 1, 0);
        assertData(gate);
        assertEvent(gate, EndOfPartitionEvent.class);
        assertEquals(1, target.getTriggeredCheckpointCounter());
        assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault())));
    }
}
Also used : TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 5 with TestCheckpointedInputGateBuilder

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

the class AlternatingCheckpointsTest method testTimeoutAlignmentOnAnnouncementForSecondCheckpoint.

/**
 * This test tries to make sure that the first time out happens after processing {@link
 * EventAnnouncement} but before/during processing the first {@link CheckpointBarrier} of at
 * least second checkpoint.
 */
@Test
public void testTimeoutAlignmentOnAnnouncementForSecondCheckpoint() throws Exception {
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build();
    long alignmentTimeout = 100;
    performFirstCheckpoint(numChannels, target, gate, alignmentTimeout);
    assertEquals(1, target.getTriggeredCheckpointCounter());
    Buffer checkpointBarrier = withTimeout(2, alignmentTimeout);
    for (int i = 0; i < numChannels; i++) {
        (getChannel(gate, i)).onBuffer(dataBuffer(), 1, 0);
        (getChannel(gate, i)).onBuffer(checkpointBarrier.retainBuffer(), 2, 0);
    }
    assertEquals(1, target.getTriggeredCheckpointCounter());
    for (int i = 0; i < numChannels; i++) {
        assertAnnouncement(gate);
    }
    assertEquals(1, target.getTriggeredCheckpointCounter());
    clock.advanceTime(alignmentTimeout * 4, TimeUnit.MILLISECONDS);
    // the barrier should overtake the data buffers
    assertBarrier(gate);
    assertEquals(2, 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)

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