use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method shouldRequireValidBackoff.
public void shouldRequireValidBackoff() {
shouldFail(() -> new RetryPolicy().withBackoff(0, 0, null), NullPointerException.class);
shouldFail(() -> new RetryPolicy().withMaxDuration(1, TimeUnit.MILLISECONDS).withBackoff(100, 120, TimeUnit.MILLISECONDS), IllegalStateException.class);
shouldFail(() -> new RetryPolicy().withBackoff(-3, 10, TimeUnit.MILLISECONDS), IllegalArgumentException.class);
shouldFail(() -> new RetryPolicy().withBackoff(100, 10, TimeUnit.MILLISECONDS), IllegalArgumentException.class);
shouldFail(() -> new RetryPolicy().withBackoff(5, 10, TimeUnit.MILLISECONDS, .5), IllegalArgumentException.class);
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method testCanAbortForResultPredicate.
public void testCanAbortForResultPredicate() {
RetryPolicy policy = new RetryPolicy().abortIf((Integer result) -> result > 100);
assertTrue(policy.canAbortFor(110, null));
assertFalse(policy.canAbortFor(50, null));
assertFalse(policy.canAbortFor(50, new IllegalArgumentException()));
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method testCanAbortForFailure.
@SuppressWarnings("unchecked")
public void testCanAbortForFailure() {
RetryPolicy policy = new RetryPolicy().abortOn(Exception.class);
assertTrue(policy.canAbortFor(null, new Exception()));
assertTrue(policy.canAbortFor(null, new IllegalArgumentException()));
policy = new RetryPolicy().abortOn(IllegalArgumentException.class, IOException.class);
assertTrue(policy.canAbortFor(null, new IllegalArgumentException()));
assertTrue(policy.canAbortFor(null, new IOException()));
assertFalse(policy.canAbortFor(null, new RuntimeException()));
assertFalse(policy.canAbortFor(null, new IllegalStateException()));
policy = new RetryPolicy().abortOn(Arrays.asList(IllegalArgumentException.class));
assertTrue(policy.canAbortFor(null, new IllegalArgumentException()));
assertFalse(policy.canAbortFor(null, new RuntimeException()));
assertFalse(policy.canAbortFor(null, new IllegalStateException()));
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method testCopy.
public void testCopy() {
RetryPolicy rp = new RetryPolicy();
rp.withBackoff(2, 20, TimeUnit.SECONDS, 2.5);
rp.withMaxDuration(60, TimeUnit.SECONDS);
rp.withMaxRetries(3);
RetryPolicy rp2 = rp.copy();
assertEquals(rp.getDelay().toNanos(), rp2.getDelay().toNanos());
assertEquals(rp.getDelayFactor(), rp2.getDelayFactor());
assertEquals(rp.getMaxDelay().toNanos(), rp2.getMaxDelay().toNanos());
assertEquals(rp.getMaxDuration().toNanos(), rp2.getMaxDuration().toNanos());
assertEquals(rp.getMaxRetries(), rp2.getMaxRetries());
}
use of net.jodah.failsafe.RetryPolicy in project failsafe by jhalterman.
the class RetryPolicyTest method testCanAbortForFailurePredicate.
public void testCanAbortForFailurePredicate() {
RetryPolicy policy = new RetryPolicy().abortOn(failure -> failure instanceof ConnectException);
assertTrue(policy.canAbortFor(null, new ConnectException()));
assertFalse(policy.canAbortFor(null, new IllegalArgumentException()));
}
Aggregations