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