use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ExponentialDelayRestartBackoffTimeStrategyTest method testJitterNoHigherThanMax.
@Test
public void testJitterNoHigherThanMax() throws Exception {
double jitterFactor = 1;
long maxBackoffMS = 7L;
final ExponentialDelayRestartBackoffTimeStrategy restartStrategy = new ExponentialDelayRestartBackoffTimeStrategy(new ManualClock(), 1L, maxBackoffMS, 2.0, 8L, jitterFactor);
assertCorrectRandomRange(restartStrategy::getBackoffTime, 0L, 1L, 2L);
restartStrategy.notifyFailure(failure);
assertCorrectRandomRange(restartStrategy::getBackoffTime, 0L, 1L, 2L, 3L, 4L);
restartStrategy.notifyFailure(failure);
assertCorrectRandomRange(restartStrategy::getBackoffTime, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L);
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ThroughputCalculatorTest method testMultiplyIdleEnd.
@Test
public void testMultiplyIdleEnd() {
ManualClock clock = new ManualClock();
ThroughputCalculator throughputCalculator = new ThroughputCalculator(clock);
throughputCalculator.incomingDataSize(10);
// It won't be ignored.
clock.advanceTime(Duration.ofMillis(3));
throughputCalculator.resumeMeasurement();
// It won't be ignored.
clock.advanceTime(Duration.ofMillis(3));
throughputCalculator.resumeMeasurement();
// It won't be ignored.
clock.advanceTime(Duration.ofMillis(3));
throughputCalculator.resumeMeasurement();
clock.advanceTime(Duration.ofMillis(1));
// resumeMeasurement should not reset the time because pauseMeasurement was not called.
assertThat(throughputCalculator.calculateThroughput(), is(1_000L));
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ThroughputCalculatorTest method testResetValueAfterCalculation.
@Test
public void testResetValueAfterCalculation() {
ManualClock clock = new ManualClock();
ThroughputCalculator throughputCalculator = new ThroughputCalculator(clock);
throughputCalculator.incomingDataSize(666);
clock.advanceTime(Duration.ofMillis(100));
assertThat(throughputCalculator.calculateThroughput(), is(6660L));
// It should be the same as previous time.
assertThat(throughputCalculator.calculateThroughput(), is(6660L));
clock.advanceTime(Duration.ofMillis(1));
assertThat(throughputCalculator.calculateThroughput(), is(0L));
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ThroughputCalculatorTest method testNotRestartTimerOnCalculationDuringIdleTime.
@Test
public void testNotRestartTimerOnCalculationDuringIdleTime() {
ManualClock clock = new ManualClock();
ThroughputCalculator throughputCalculator = new ThroughputCalculator(clock);
throughputCalculator.pauseMeasurement();
// Should not resume measurement.
throughputCalculator.calculateThroughput();
// This will be ignored because it is still in idle.
clock.advanceTime(Duration.ofMillis(9));
// Resume measurement.
throughputCalculator.incomingDataSize(10);
clock.advanceTime(Duration.ofMillis(1));
assertThat(throughputCalculator.calculateThroughput(), is(10L * 1_000));
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ZooKeeperCompletedCheckpointStoreITCase method testChekpointingPausesAndResumeWhenTooManyCheckpoints.
/**
* FLINK-17073 tests that there is no request triggered when there are too many checkpoints
* waiting to clean and that it resumes when the number of waiting checkpoints as gone below the
* threshold.
*/
@Test
public void testChekpointingPausesAndResumeWhenTooManyCheckpoints() throws Exception {
ManualClock clock = new ManualClock();
clock.advanceTime(1, TimeUnit.DAYS);
int maxCleaningCheckpoints = 1;
CheckpointsCleaner checkpointsCleaner = new CheckpointsCleaner();
CheckpointRequestDecider checkpointRequestDecider = new CheckpointRequestDecider(maxCleaningCheckpoints, unused -> {
}, clock, 1, new AtomicInteger(0)::get, checkpointsCleaner::getNumberOfCheckpointsToClean);
final int maxCheckpointsToRetain = 1;
ManuallyTriggeredScheduledExecutor executor = new ManuallyTriggeredScheduledExecutor();
CompletedCheckpointStore checkpointStore = createRecoveredCompletedCheckpointStore(maxCheckpointsToRetain, executor);
int nbCheckpointsToInject = 3;
for (int i = 1; i <= nbCheckpointsToInject; i++) {
// add checkpoints to clean, the ManuallyTriggeredScheduledExecutor.execute() just
// queues the runnables but does not execute them.
TestCompletedCheckpoint completedCheckpoint = new TestCompletedCheckpoint(new JobID(), i, i, Collections.emptyMap(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE));
checkpointStore.addCheckpointAndSubsumeOldestOne(completedCheckpoint, checkpointsCleaner, () -> {
});
}
int nbCheckpointsSubmittedForCleaning = nbCheckpointsToInject - maxCheckpointsToRetain;
// wait for cleaning request submission by checkpointsStore
CommonTestUtils.waitUntilCondition(() -> checkpointsCleaner.getNumberOfCheckpointsToClean() == nbCheckpointsSubmittedForCleaning, Deadline.fromNow(Duration.ofSeconds(3)));
assertEquals(nbCheckpointsSubmittedForCleaning, checkpointsCleaner.getNumberOfCheckpointsToClean());
// checkpointing is on hold because checkpointsCleaner.getNumberOfCheckpointsToClean() >
// maxCleaningCheckpoints
assertFalse(checkpointRequestDecider.chooseRequestToExecute(regularCheckpoint(), false, 0).isPresent());
// make the executor execute checkpoint requests.
executor.triggerAll();
// wait for a checkpoint to be cleaned
CommonTestUtils.waitUntilCondition(() -> checkpointsCleaner.getNumberOfCheckpointsToClean() < nbCheckpointsSubmittedForCleaning, Deadline.fromNow(Duration.ofSeconds(3)));
// some checkpoints were cleaned
assertTrue(checkpointsCleaner.getNumberOfCheckpointsToClean() < nbCheckpointsSubmittedForCleaning);
// checkpointing is resumed because checkpointsCleaner.getNumberOfCheckpointsToClean() <=
// maxCleaningCheckpoints
assertTrue(checkpointRequestDecider.chooseRequestToExecute(regularCheckpoint(), false, 0).isPresent());
checkpointStore.shutdown(JobStatus.FINISHED, checkpointsCleaner);
}
Aggregations