Search in sources :

Example 6 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class RetryTrackerTest method when_attemptsNegative_retryIndefinitely.

@Test
public void when_attemptsNegative_retryIndefinitely() {
    RetryStrategy strategy = RetryStrategies.custom().maxAttempts(-1).build();
    RetryTracker tracker = new RetryTracker(strategy, timeSupplier);
    assertFalse(tracker.needsToWait());
    for (int i = 0; i < 1_000_000; i++) {
        tracker.attemptFailed();
        assertTrue(tracker.shouldTryAgain());
        assertTrue(tracker.needsToWait());
        advanceTime(tracker.getNextWaitTimeMs());
        assertFalse(tracker.needsToWait());
    }
}
Also used : RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class RetryTrackerTest method when_exponentialBackoff.

@Test
public void when_exponentialBackoff() {
    RetryStrategy strategy = RetryStrategies.custom().intervalFunction((IntervalFunction) attempt -> attempt * 1000L).build();
    RetryTracker tracker = new RetryTracker(strategy, timeSupplier);
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertTrue(tracker.needsToWait());
    advanceTime(999);
    assertTrue(tracker.needsToWait());
    advanceTime(1);
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertTrue(tracker.needsToWait());
    advanceTime(1999);
    assertTrue(tracker.needsToWait());
    advanceTime(1);
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertTrue(tracker.needsToWait());
    advanceTime(2999);
    assertTrue(tracker.needsToWait());
    advanceTime(1);
    assertFalse(tracker.needsToWait());
}
Also used : RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) IntervalFunction(com.hazelcast.jet.retry.IntervalFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

RetryStrategy (com.hazelcast.jet.retry.RetryStrategy)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 IntervalFunction (com.hazelcast.jet.retry.IntervalFunction)1 RetryTracker (com.hazelcast.jet.retry.impl.RetryTracker)1