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