Search in sources :

Example 11 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testCleanStateAfterFullDeploymentCycle.

@Test
void testCleanStateAfterFullDeploymentCycle() {
    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);
    metrics.onStateUpdate(id1, ExecutionState.INITIALIZING, ExecutionState.RUNNING);
    metrics.onStateUpdate(id1, ExecutionState.RUNNING, ExecutionState.CANCELING);
    metrics.onStateUpdate(id1, ExecutionState.CANCELING, ExecutionState.CANCELED);
    assertThat(metrics.hasCleanState()).isEqualTo(true);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Test(org.junit.jupiter.api.Test)

Example 12 with ManualClock

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

the class DeploymentStateTimeMetricsTest method testCleanStateAfterEarlyDeploymentFailure.

@Test
void testCleanStateAfterEarlyDeploymentFailure() {
    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.FAILED);
    assertThat(metrics.hasCleanState()).isEqualTo(true);
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Test(org.junit.jupiter.api.Test)

Example 13 with ManualClock

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

the class SlotPoolBatchSlotRequestTest method testPendingBatchSlotRequestTimeoutAfterSlotRelease.

/**
 * Tests that a pending batch slot request times out after the last fulfilling slot gets
 * released.
 */
@Test
public void testPendingBatchSlotRequestTimeoutAfterSlotRelease() throws Exception {
    final ManualClock clock = new ManualClock();
    final Time batchSlotTimeout = Time.milliseconds(10000L);
    try (final DeclarativeSlotPoolBridge slotPool = createAndSetUpSlotPool(mainThreadExecutor, null, batchSlotTimeout, clock)) {
        SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, mainThreadExecutor, resourceProfile);
        final ResourceID taskManagerResourceId = 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);
        // initial batch slot timeout check
        advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, mainThreadExecutor, clock, batchSlotTimeout);
        assertThat(CompletableFuture.anyOf(slotFutures.toArray(COMPLETABLE_FUTURES_EMPTY_ARRAY)).isDone(), is(false));
        SlotPoolUtils.releaseTaskManager(slotPool, mainThreadExecutor, taskManagerResourceId);
        advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, mainThreadExecutor, clock, batchSlotTimeout);
        for (CompletableFuture<PhysicalSlot> slotFuture : slotFutures) {
            assertThat(slotFuture.isCompletedExceptionally(), is(true));
            try {
                slotFuture.get();
                fail("Expected that the slot future times out.");
            } catch (ExecutionException ee) {
                assertThat(ee, FlinkMatchers.containsCause(TimeoutException.class));
            }
        }
    }
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) Time(org.apache.flink.api.common.time.Time) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 14 with ManualClock

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

the class FailureRateRestartBackoffTimeStrategyTest method testFailuresExceedingRate.

@Test
public void testFailuresExceedingRate() {
    final int numFailures = 3;
    final long intervalMS = 10_000L;
    final FailureRateRestartBackoffTimeStrategy restartStrategy = new FailureRateRestartBackoffTimeStrategy(new ManualClock(), numFailures, intervalMS, 0);
    for (int failuresLeft = numFailures; failuresLeft > 0; failuresLeft--) {
        restartStrategy.notifyFailure(failure);
        assertTrue(restartStrategy.canRestart());
    }
    restartStrategy.notifyFailure(failure);
    assertFalse(restartStrategy.canRestart());
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) Test(org.junit.Test)

Example 15 with ManualClock

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

the class ExponentialDelayRestartBackoffTimeStrategyTest method testAlwaysRestart.

@Test
public void testAlwaysRestart() throws Exception {
    final ExponentialDelayRestartBackoffTimeStrategy restartStrategy = new ExponentialDelayRestartBackoffTimeStrategy(new ManualClock(), 1L, 3L, 2.0, 4L, 0.25);
    for (int i = 0; i < 13; i++) {
        assertTrue(restartStrategy.canRestart());
        restartStrategy.notifyFailure(failure);
    }
}
Also used : ManualClock(org.apache.flink.util.clock.ManualClock) 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