Search in sources :

Example 21 with ManualClock

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

the class ThroughputCalculatorTest method testCalculationDuringIdleTime.

@Test
public void testCalculationDuringIdleTime() {
    ManualClock clock = new ManualClock();
    ThroughputCalculator throughputCalculator = new ThroughputCalculator(clock);
    throughputCalculator.incomingDataSize(10);
    clock.advanceTime(Duration.ofMillis(1));
    throughputCalculator.pauseMeasurement();
    // This will be ignored because it is in idle now.
    clock.advanceTime(Duration.ofMillis(9));
    assertThat(throughputCalculator.calculateThroughput(), is(10L * 1_000));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 22 with ManualClock

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

the class ThroughputCalculatorTest method testIgnoringIdleTime.

@Test
public void testIgnoringIdleTime() {
    ManualClock clock = new ManualClock();
    ThroughputCalculator throughputCalculator = new ThroughputCalculator(clock);
    throughputCalculator.incomingDataSize(7);
    clock.advanceTime(Duration.ofMillis(1));
    throughputCalculator.pauseMeasurement();
    // This will be ignored because it is in idle now.
    clock.advanceTime(Duration.ofMillis(9));
    // This should resume the measurement time.
    throughputCalculator.incomingDataSize(3);
    clock.advanceTime(Duration.ofMillis(1));
    assertThat(throughputCalculator.calculateThroughput(), is(5L * 1_000));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 23 with ManualClock

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

the class ThroughputCalculatorTest method testCorrectThroughputCalculation.

@Test
public void testCorrectThroughputCalculation() {
    ManualClock clock = new ManualClock();
    ThroughputCalculator throughputCalculator = new ThroughputCalculator(clock);
    throughputCalculator.incomingDataSize(6666);
    clock.advanceTime(Duration.ofMillis(1));
    throughputCalculator.incomingDataSize(3333);
    clock.advanceTime(Duration.ofMillis(33));
    throughputCalculator.incomingDataSize(1);
    clock.advanceTime(Duration.ofMillis(66));
    assertThat(throughputCalculator.calculateThroughput(), is(10_000L * 1_000 / 100));
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 24 with ManualClock

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

the class WatermarksWithIdlenessTest method testIdleActiveIdle.

@Test
public void testIdleActiveIdle() {
    final ManualClock clock = new ManualClock(System.nanoTime());
    final IdlenessTimer timer = createTimerAndMakeIdle(clock, Duration.ofMillis(122));
    // active again
    timer.activity();
    assertFalse(timer.checkIfIdle());
    // idle again
    // start timer
    timer.checkIfIdle();
    clock.advanceTime(Duration.ofMillis(123));
    assertTrue(timer.checkIfIdle());
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) IdlenessTimer(org.apache.flink.api.common.eventtime.WatermarksWithIdleness.IdlenessTimer) Test(org.junit.Test)

Example 25 with ManualClock

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

the class WatermarksWithIdlenessTest method testActiveAfterIdleness.

@Test
public void testActiveAfterIdleness() {
    final ManualClock clock = new ManualClock(System.nanoTime());
    final IdlenessTimer timer = createTimerAndMakeIdle(clock, Duration.ofMillis(10));
    timer.activity();
    assertFalse(timer.checkIfIdle());
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) IdlenessTimer(org.apache.flink.api.common.eventtime.WatermarksWithIdleness.IdlenessTimer) 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