Search in sources :

Example 6 with ManualClock

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

the class JobStatusMetricsTest method testTotalTimeMetric.

@Test
void testTotalTimeMetric() {
    final ManualClock clock = new ManualClock(0);
    final JobStatusMetrics jobStatusMetrics = new JobStatusMetrics(0L, enable(MetricOptions.JobStatusMetrics.STATE, MetricOptions.JobStatusMetrics.CURRENT_TIME, MetricOptions.JobStatusMetrics.TOTAL_TIME), clock);
    final StateTimeMetric metric = jobStatusMetrics.createTimeMetric(JobStatus.RUNNING);
    assertThat(metric.getTotalTime()).isEqualTo(0L);
    jobStatusMetrics.jobStatusChanges(new JobID(), JobStatus.RUNNING, clock.absoluteTimeMillis());
    clock.advanceTime(Duration.ofMillis(10));
    assertThat(metric.getTotalTime()).isEqualTo(10L);
    jobStatusMetrics.jobStatusChanges(new JobID(), JobStatus.RESTARTING, clock.absoluteTimeMillis());
    clock.advanceTime(Duration.ofMillis(4));
    assertThat(metric.getTotalTime()).isEqualTo(10L);
    jobStatusMetrics.jobStatusChanges(new JobID(), JobStatus.RUNNING, clock.absoluteTimeMillis());
    clock.advanceTime(Duration.ofMillis(1));
    assertThat(metric.getTotalTime()).isEqualTo(11L);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) JobID(org.apache.flink.api.common.JobID) Test(org.junit.jupiter.api.Test)

Example 7 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testGetTotalTime.

@Test
void testGetTotalTime() {
    final ManualClock clock = new ManualClock(Duration.ofMillis(5).toNanos());
    final DeploymentStateTimeMetrics metrics = new DeploymentStateTimeMetrics(JobType.BATCH, settings, clock);
    final ExecutionAttemptID id1 = new ExecutionAttemptID();
    metrics.onStateUpdate(id1, ExecutionState.CREATED, ExecutionState.SCHEDULED);
    metrics.onStateUpdate(id1, ExecutionState.SCHEDULED, ExecutionState.DEPLOYING);
    clock.advanceTime(Duration.ofMillis(5));
    metrics.onStateUpdate(id1, ExecutionState.DEPLOYING, ExecutionState.FINISHED);
    assertThat(metrics.getTotalTime()).isEqualTo(5L);
    final ExecutionAttemptID id2 = new ExecutionAttemptID();
    metrics.onStateUpdate(id2, ExecutionState.CREATED, ExecutionState.SCHEDULED);
    metrics.onStateUpdate(id2, ExecutionState.SCHEDULED, ExecutionState.DEPLOYING);
    clock.advanceTime(Duration.ofMillis(5));
    metrics.onStateUpdate(id2, ExecutionState.DEPLOYING, ExecutionState.FINISHED);
    assertThat(metrics.getTotalTime()).isEqualTo(10L);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Test(org.junit.jupiter.api.Test)

Example 8 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testInitialValues.

@Test
void testInitialValues() {
    final ManualClock clock = new ManualClock(Duration.ofMillis(5).toNanos());
    final DeploymentStateTimeMetrics deploymentStateTimeMetrics = new DeploymentStateTimeMetrics(JobType.BATCH, settings, clock);
    assertThat(deploymentStateTimeMetrics.getCurrentTime()).isEqualTo(0L);
    assertThat(deploymentStateTimeMetrics.getTotalTime()).isEqualTo(0L);
    assertThat(deploymentStateTimeMetrics.getBinary()).isEqualTo(0L);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.jupiter.api.Test)

Example 9 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testGetCurrentTimeResetOndDeployentEnd.

@Test
void testGetCurrentTimeResetOndDeployentEnd() {
    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(id1, ExecutionState.SCHEDULED, ExecutionState.DEPLOYING);
    metrics.onStateUpdate(id1, ExecutionState.DEPLOYING, ExecutionState.INITIALIZING);
    assertThat(metrics.getCurrentTime()).isEqualTo(0L);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Test(org.junit.jupiter.api.Test)

Example 10 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testGetTotalTimeIncludesCurrentTime.

@Test
void testGetTotalTimeIncludesCurrentTime() {
    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(id1, ExecutionState.SCHEDULED, ExecutionState.DEPLOYING);
    clock.advanceTime(Duration.ofMillis(5));
    assertThat(metrics.getTotalTime()).isEqualTo(5L);
}
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