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