use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ExponentialDelayRestartBackoffTimeStrategyTest method testInitialBackoff.
@Test
public void testInitialBackoff() throws Exception {
long initialBackoffMS = 42L;
final ExponentialDelayRestartBackoffTimeStrategy restartStrategy = new ExponentialDelayRestartBackoffTimeStrategy(new ManualClock(), initialBackoffMS, 45L, 2.0, 8L, 0);
assertThat(restartStrategy.getBackoffTime(), is(initialBackoffMS));
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ExponentialDelayRestartBackoffTimeStrategyTest method testResetBackoff.
@Test
public void testResetBackoff() throws Exception {
final long initialBackoffMS = 1L;
final long resetBackoffThresholdMS = 8L;
final ManualClock clock = new ManualClock();
final ExponentialDelayRestartBackoffTimeStrategy restartStrategy = new ExponentialDelayRestartBackoffTimeStrategy(clock, initialBackoffMS, 5L, 2.0, resetBackoffThresholdMS, 0.25);
clock.advanceTime(resetBackoffThresholdMS + restartStrategy.getBackoffTime() - 1, TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertThat("Backoff should be increased", restartStrategy.getBackoffTime(), is(2L));
clock.advanceTime(resetBackoffThresholdMS + restartStrategy.getBackoffTime(), TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertThat("Backoff should be reset", restartStrategy.getBackoffTime(), is(initialBackoffMS));
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class ExponentialDelayRestartBackoffTimeStrategyTest method testMultipleSettings.
@Test
public void testMultipleSettings() throws Exception {
ManualClock clock = new ManualClock();
final long initialBackoffMS = 1L;
final long maxBackoffMS = 9L;
double backoffMultiplier = 2.0;
final long resetBackoffThresholdMS = 8L;
double jitterFactor = 0.25;
final ExponentialDelayRestartBackoffTimeStrategy restartStrategy = new ExponentialDelayRestartBackoffTimeStrategy(clock, initialBackoffMS, maxBackoffMS, backoffMultiplier, resetBackoffThresholdMS, jitterFactor);
// ensure initial data
assertTrue(restartStrategy.canRestart());
assertThat(restartStrategy.getBackoffTime(), is(initialBackoffMS));
// ensure backoff time is initial after the first failure
clock.advanceTime(50, TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertTrue(restartStrategy.canRestart());
assertThat(restartStrategy.getBackoffTime(), is(initialBackoffMS));
// ensure backoff increases until threshold is reached
clock.advanceTime(4, TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertTrue(restartStrategy.canRestart());
assertThat(restartStrategy.getBackoffTime(), is(2L));
clock.advanceTime(3, TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertTrue(restartStrategy.canRestart());
assertCorrectRandomRange(restartStrategy::getBackoffTime, 3L, 4L, 5L);
clock.advanceTime(7, TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertTrue(restartStrategy.canRestart());
assertCorrectRandomRange(restartStrategy::getBackoffTime, 6L, 7L, 8L, 9L);
// ensure backoff is reset after threshold is reached
clock.advanceTime(resetBackoffThresholdMS + 9 + 1, TimeUnit.MILLISECONDS);
restartStrategy.notifyFailure(failure);
assertTrue(restartStrategy.canRestart());
assertThat(restartStrategy.getBackoffTime(), is(1L));
// ensure backoff still increases
restartStrategy.notifyFailure(failure);
assertTrue(restartStrategy.canRestart());
assertThat(restartStrategy.getBackoffTime(), is(2L));
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class CheckpointBarrierTrackerTest method testTwoLastBarriersOneByOne.
@Test
public void testTwoLastBarriersOneByOne() throws Exception {
BufferOrEvent[] sequence = { // start checkpoint 1
createBarrier(1, 1), // start checkpoint 2
createBarrier(2, 1), // finish the checkpoint 1
createBarrier(1, 0), // finish the checkpoint 2
createBarrier(2, 0) };
ValidatingCheckpointHandler validator = new ValidatingCheckpointHandler();
ManualClock manualClock = new ManualClock();
inputGate = createCheckpointedInputGate(2, sequence, validator, manualClock);
for (BufferOrEvent boe : sequence) {
assertEquals(boe, inputGate.pollNext().get());
manualClock.advanceTime(Duration.ofSeconds(1));
}
assertEquals(Duration.ofSeconds(2).toNanos(), validator.lastAlignmentDurationNanos.get().longValue());
}
use of org.apache.flink.util.clock.ManualClock in project flink by apache.
the class CheckpointBarrierTrackerTest method testNextFirstCheckpointBarrierOvertakesCancellationBarrier.
@Test
public void testNextFirstCheckpointBarrierOvertakesCancellationBarrier() throws Exception {
BufferOrEvent[] sequence = { // start checkpoint 1
createBarrier(1, 1), // start checkpoint 2(just suppose checkpoint 1 was canceled)
createBarrier(2, 1), // cancellation barrier of checkpoint 1
createCancellationBarrier(1, 0), // finish the checkpoint 2
createBarrier(2, 0) };
ValidatingCheckpointHandler validator = new ValidatingCheckpointHandler();
ManualClock manualClock = new ManualClock();
inputGate = createCheckpointedInputGate(2, sequence, validator, manualClock);
for (BufferOrEvent boe : sequence) {
assertEquals(boe, inputGate.pollNext().get());
manualClock.advanceTime(Duration.ofSeconds(1));
}
assertEquals(Duration.ofSeconds(2).toNanos(), validator.lastAlignmentDurationNanos.get().longValue());
}
Aggregations