Search in sources :

Example 36 with ManualClock

use of org.apache.flink.util.clock.ManualClock in project flink by apache.

the class CheckpointRequestDeciderTest method testTiming.

private void testTiming(CheckpointTriggerRequest request, TriggerExpectation expectation) {
    final long pause = 10;
    final ManualClock clock = new ManualClock();
    final CheckpointRequestDecider decider = new CheckpointRequestDecider(1, NO_OP, clock, pause, () -> 0, () -> 0, Integer.MAX_VALUE);
    final long lastCompletionMs = clock.relativeTimeMillis();
    final boolean isTriggering = false;
    switch(expectation) {
        case IMMEDIATELY:
            assertTrue(decider.chooseRequestToExecute(request, isTriggering, lastCompletionMs).isPresent());
            break;
        case AFTER_PAUSE:
            assertFalse(decider.chooseRequestToExecute(request, isTriggering, lastCompletionMs).isPresent());
            clock.advanceTime(pause, MILLISECONDS);
            assertTrue(decider.chooseQueuedRequestToExecute(isTriggering, lastCompletionMs).isPresent());
            break;
        case DROPPED:
            assertFalse(decider.chooseRequestToExecute(request, isTriggering, lastCompletionMs).isPresent());
            assertFailed(request, MINIMUM_TIME_BETWEEN_CHECKPOINTS);
            break;
        default:
            throw new IllegalArgumentException("unknown expectation: " + expectation);
    }
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock)

Example 37 with ManualClock

use of org.apache.flink.util.clock.ManualClock in project flink by apache.

the class TimerGaugeTest method testGetWithoutUpdate.

@Test
public void testGetWithoutUpdate() {
    ManualClock clock = new ManualClock(42_000_000);
    TimerGauge gauge = new TimerGauge(clock);
    gauge.markStart();
    clock.advanceTime(SLEEP, TimeUnit.MILLISECONDS);
    assertThat(gauge.getValue(), is(0L));
    gauge.markEnd();
    assertThat(gauge.getValue(), is(0L));
    assertThat(gauge.getMaxSingleMeasurement(), is(0L));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 38 with ManualClock

use of org.apache.flink.util.clock.ManualClock in project flink by apache.

the class TimerGaugeTest method testUpdateWithoutMarkingEnd.

@Test
public void testUpdateWithoutMarkingEnd() {
    ManualClock clock = new ManualClock(42_000_000);
    TimerGauge gauge = new TimerGauge(clock);
    gauge.markStart();
    clock.advanceTime(SLEEP, TimeUnit.MILLISECONDS);
    gauge.update();
    assertThat(gauge.getValue(), greaterThanOrEqualTo(SLEEP / View.UPDATE_INTERVAL_SECONDS));
    assertThat(gauge.getMaxSingleMeasurement(), is(SLEEP));
    // keep the measurement going for another update
    clock.advanceTime(SLEEP, TimeUnit.MILLISECONDS);
    gauge.update();
    assertThat(gauge.getValue(), greaterThanOrEqualTo(SLEEP / View.UPDATE_INTERVAL_SECONDS));
    // max single measurement is now spanning two updates
    assertThat(gauge.getMaxSingleMeasurement(), is(SLEEP * 2));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 39 with ManualClock

use of org.apache.flink.util.clock.ManualClock in project flink by apache.

the class TimerGaugeTest method testBasicUsage.

@Test
public void testBasicUsage() {
    ManualClock clock = new ManualClock(42_000_000);
    TimerGauge gauge = new TimerGauge(clock);
    gauge.update();
    assertThat(gauge.getValue(), is(0L));
    assertThat(gauge.getMaxSingleMeasurement(), is(0L));
    gauge.markStart();
    clock.advanceTime(SLEEP, TimeUnit.MILLISECONDS);
    gauge.markEnd();
    gauge.update();
    assertThat(gauge.getValue(), greaterThanOrEqualTo(SLEEP / View.UPDATE_INTERVAL_SECONDS));
    assertThat(gauge.getMaxSingleMeasurement(), is(SLEEP));
    // Check that the getMaxSingleMeasurement can go down after an update
    gauge.markStart();
    clock.advanceTime(SLEEP / 2, TimeUnit.MILLISECONDS);
    gauge.markEnd();
    gauge.update();
    assertThat(gauge.getMaxSingleMeasurement(), is(SLEEP / 2));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 40 with ManualClock

use of org.apache.flink.util.clock.ManualClock in project flink by apache.

the class DeploymentStateTimeMetricsTest method testGetCurrentTime_notResetOnSecondaryDeployment.

@Test
void testGetCurrentTime_notResetOnSecondaryDeployment() {
    final ManualClock clock = new ManualClock(Duration.ofMillis(5).toNanos());
    final DeploymentStateTimeMetrics metrics = new DeploymentStateTimeMetrics(JobType.BATCH, settings, clock);
    final ExecutionAttemptID id1 = new ExecutionAttemptID();
    final ExecutionAttemptID id2 = new ExecutionAttemptID();
    metrics.onStateUpdate(id1, ExecutionState.CREATED, ExecutionState.SCHEDULED);
    metrics.onStateUpdate(id2, ExecutionState.CREATED, ExecutionState.SCHEDULED);
    metrics.onStateUpdate(id1, ExecutionState.SCHEDULED, ExecutionState.DEPLOYING);
    clock.advanceTime(Duration.ofMillis(5));
    metrics.onStateUpdate(id2, ExecutionState.SCHEDULED, ExecutionState.DEPLOYING);
    clock.advanceTime(Duration.ofMillis(5));
    assertThat(metrics.getCurrentTime()).isEqualTo(10L);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Test(org.junit.jupiter.api.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