Search in sources :

Example 41 with ManualClock

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

the class SlotPoolBatchSlotRequestTest method testPendingBatchSlotRequestDoesNotTimeoutIfFulfillingSlotExists.

/**
 * Tests that a batch slot request won't time out if there exists a slot in the SlotPool which
 * fulfills the requested {@link ResourceProfile}.
 */
@Test
public void testPendingBatchSlotRequestDoesNotTimeoutIfFulfillingSlotExists() throws Exception {
    final Time batchSlotTimeout = Time.milliseconds(2L);
    final ManualClock clock = new ManualClock();
    try (final DeclarativeSlotPoolBridge slotPool = createAndSetUpSlotPool(mainThreadExecutor, null, batchSlotTimeout, clock)) {
        SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, mainThreadExecutor, resourceProfile);
        SlotPoolUtils.offerSlots(slotPool, mainThreadExecutor, Arrays.asList(resourceProfile));
        final CompletableFuture<PhysicalSlot> firstPendingSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, mainThreadExecutor, ResourceProfile.UNKNOWN);
        final CompletableFuture<PhysicalSlot> secondPendingSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, mainThreadExecutor, resourceProfile);
        final List<CompletableFuture<PhysicalSlot>> slotFutures = Arrays.asList(firstPendingSlotFuture, secondPendingSlotFuture);
        advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, mainThreadExecutor, clock, batchSlotTimeout);
        for (CompletableFuture<PhysicalSlot> slotFuture : slotFutures) {
            assertThat(slotFuture.isDone(), is(false));
        }
    }
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) CompletableFuture(java.util.concurrent.CompletableFuture) Time(org.apache.flink.api.common.time.Time) Test(org.junit.Test)

Example 42 with ManualClock

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

the class ComponentClosingUtilsTest method setup.

@Before
public void setup() {
    clock = new ManualClock();
    ComponentClosingUtils.setClock(clock);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Before(org.junit.Before)

Example 43 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testGetCurrentTime.

@Test
void testGetCurrentTime() {
    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.getCurrentTime()).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