RetryOnExceptionsCondition implements RetryCondition { @Override public boolean shouldRetry(RetryPolicyContext context) { if (context.exception() != null) { for (Class<? extends Exception> exceptionClass : exceptionsToRetryOn) { if (exceptionMatches(context, exceptionClass)) { return true; } if (wrappedCauseMatches(context, exceptionClass)) { return true; } } } return false; } RetryOnExceptionsCondition(List<Class<? extends Exception>> exceptionsToRetryOn); @Override boolean shouldRetry(RetryPolicyContext context);  }
@Test public void noExceptionInContext_ReturnsFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withException(null))); }
@Test public void retryableServiceException_ReturnsTrue() { assertTrue(condition.shouldRetry(RetryPolicyContexts.withException(new RetryableServiceException()))); }
@Test public void nonRetryableServiceException_ReturnsFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withException(new NonRetryableServiceException()))); }
@Test public void retryableClientException_ReturnsTrue() { assertTrue(condition.shouldRetry(RetryPolicyContexts.withException(new RetryableClientException()))); }
@Test public void nonRetryableClientException_ReturnsFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withException(new NonRetryableClientException()))); }
@Test public void retryableWrappedClientException_ReturnsTrue() { assertTrue(condition.shouldRetry(RetryPolicyContexts.withException(new SdkClientException(new SocketTimeoutException("foo"))))); }
@Test public void nonRetryableWrappedClientException_ReturnsFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withException(new SdkClientException(new ConnectException("foo"))))); }
@Test public void genericClientException_ReturnsFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withException(new SdkClientException("foo")))); }
@Test public void genericBaseException_ReturnsFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withException(new SdkBaseException("foo")))); }
@Test public void noRetryableExceptions_ReturnsFalse() { final RetryCondition noExceptionsCondition = new RetryOnExceptionsCondition( Collections.<Class<? extends Exception>>emptyList()); assertFalse(noExceptionsCondition.shouldRetry(RetryPolicyContexts.withException(new RetryableServiceException()))); }