Search in sources :

Example 56 with RetryPolicy

use of net.jodah.failsafe.RetryPolicy in project samza by apache.

the class TestTableRetryPolicy method testRandomRetry.

@Test
public void testRandomRetry() {
    TableRetryPolicy retryPolicy = new TableRetryPolicy();
    retryPolicy.withRandomBackoff(Duration.ofMillis(1000), Duration.ofMillis(2000));
    // no-op
    retryPolicy.withJitter(Duration.ofMillis(100));
    Assert.assertEquals(TableRetryPolicy.BackoffType.RANDOM, retryPolicy.getBackoffType());
    RetryPolicy fsRetry = FailsafeAdapter.valueOf(retryPolicy);
    Assert.assertEquals(1000, fsRetry.getDelayMin().toMillis());
    Assert.assertEquals(2000, fsRetry.getDelayMax().toMillis());
    Assert.assertEquals("{\"randomMin\":{\"seconds\":1,\"nanos\":0},\"randomMax\":{\"seconds\":2,\"nanos\":0}," + "\"exponentialFactor\":0.0,\"backoffType\":\"RANDOM\",\"retryPredicate\":{}}", retryPolicy.toConfig(null, null).get("TableRetryPolicy"));
}
Also used : RetryPolicy(net.jodah.failsafe.RetryPolicy) Test(org.junit.Test)

Aggregations

RetryPolicy (net.jodah.failsafe.RetryPolicy)56 Failsafe (net.jodah.failsafe.Failsafe)16 IOException (java.io.IOException)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 TimeUnit (java.util.concurrent.TimeUnit)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Executors (java.util.concurrent.Executors)5 Test (org.junit.Test)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Test (org.testng.annotations.Test)5 ConnectException (java.net.ConnectException)4 Duration (java.time.Duration)4 Map (java.util.Map)4 FailsafeException (net.jodah.failsafe.FailsafeException)4 Assert.assertEquals (org.testng.Assert.assertEquals)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3