use of com.hazelcast.jet.retry.IntervalFunction in project hazelcast by hazelcast.
the class TestUtil method warmupPartitions.
private static void warmupPartitions(HazelcastInstance instance) {
if (instance == null) {
return;
}
final int maxRetryCount = 15;
IntervalFunction intervalFunction = IntervalFunctions.exponentialBackoffWithCap(10L, 2, 1000L);
PartitionService ps = instance.getPartitionService();
for (Partition partition : ps.getPartitions()) {
int i = 1;
while (partition.getOwner() == null) {
if (i > maxRetryCount) {
fail("The owner of Partition{partitionId=" + partition.getPartitionId() + "}" + " could not be obtained after " + maxRetryCount + " retries.");
}
sleepMillis((int) intervalFunction.waitAfterAttempt(i));
++i;
}
}
}
use of com.hazelcast.jet.retry.IntervalFunction 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());
}
use of com.hazelcast.jet.retry.IntervalFunction in project hazelcast by hazelcast.
the class IntervalFunctionTest method constant.
@Test
public void constant() {
IntervalFunction fun = IntervalFunction.constant(1000L);
assertEquals(1000L, fun.waitAfterAttempt(1));
assertEquals(1000L, fun.waitAfterAttempt(2));
assertEquals(1000L, fun.waitAfterAttempt(3));
}
use of com.hazelcast.jet.retry.IntervalFunction in project hazelcast by hazelcast.
the class IntervalFunctionTest method exponentialBackoff.
@Test
public void exponentialBackoff() {
IntervalFunction fun = IntervalFunction.exponentialBackoff(1000L, 2.0);
assertEquals(1000L, fun.waitAfterAttempt(1));
assertEquals(2000L, fun.waitAfterAttempt(2));
assertEquals(4000L, fun.waitAfterAttempt(3));
assertEquals(8000L, fun.waitAfterAttempt(4));
}
Aggregations