Search in sources :

Example 1 with IntervalFunction

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;
        }
    }
}
Also used : Partition(com.hazelcast.partition.Partition) PartitionService(com.hazelcast.partition.PartitionService) Endpoint(com.hazelcast.cluster.Endpoint) IntervalFunction(com.hazelcast.jet.retry.IntervalFunction)

Example 2 with IntervalFunction

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

Example 3 with IntervalFunction

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));
}
Also used : IntervalFunction(com.hazelcast.jet.retry.IntervalFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with IntervalFunction

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));
}
Also used : IntervalFunction(com.hazelcast.jet.retry.IntervalFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IntervalFunction (com.hazelcast.jet.retry.IntervalFunction)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 Endpoint (com.hazelcast.cluster.Endpoint)1 RetryStrategy (com.hazelcast.jet.retry.RetryStrategy)1 Partition (com.hazelcast.partition.Partition)1 PartitionService (com.hazelcast.partition.PartitionService)1