Search in sources :

Example 31 with ManualClock

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);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 32 with ManualClock

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));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 33 with ManualClock

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));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 34 with ManualClock

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));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 35 with ManualClock

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);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CheckpointRequestDeciderTest.regularCheckpoint(org.apache.flink.runtime.checkpoint.CheckpointRequestDeciderTest.regularCheckpoint) JobID(org.apache.flink.api.common.JobID) ManuallyTriggeredScheduledExecutor(org.apache.flink.util.concurrent.ManuallyTriggeredScheduledExecutor) Test(org.junit.Test)

Aggregations

ManualClock (org.apache.flink.util.clock.ManualClock)43 Test (org.junit.Test)30 Test (org.junit.jupiter.api.Test)10 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)7 IdlenessTimer (org.apache.flink.api.common.eventtime.WatermarksWithIdleness.IdlenessTimer)5 JobID (org.apache.flink.api.common.JobID)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 Time (org.apache.flink.api.common.time.Time)2 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)2 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CheckpointRequestDeciderTest.regularCheckpoint (org.apache.flink.runtime.checkpoint.CheckpointRequestDeciderTest.regularCheckpoint)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 ManuallyTriggeredScheduledExecutor (org.apache.flink.util.concurrent.ManuallyTriggeredScheduledExecutor)1 Before (org.junit.Before)1