ContainerCredentialsRetryPolicy implements CredentialsEndpointRetryPolicy { @Override public boolean shouldRetry(int retriesAttempted, CredentialsEndpointRetryParameters retryParams) { if (retriesAttempted >= MAX_RETRIES) { return false; } Integer statusCode = retryParams.getStatusCode(); if (statusCode != null && statusCode >= 500 && statusCode < 600) { return true; } if (retryParams.getException() != null && retryParams.getException() instanceof IOException) { return true; } return false; } private  ContainerCredentialsRetryPolicy(); static ContainerCredentialsRetryPolicy getInstance(); @Override boolean shouldRetry(int retriesAttempted, CredentialsEndpointRetryParameters retryParams);  }
@Test public void shouldRetry_ReturnsTrue_For5xxStatusCode() { assertTrue(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withStatusCode(501).build())); }
@Test public void shouldRetry_ReturnsFalse_ForNon5xxStatusCode() { assertFalse(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withStatusCode(404).build())); assertFalse(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withStatusCode(300).build())); assertFalse(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withStatusCode(202).build())); }
@Test public void shouldRetry_ReturnsTrue_ForIOException() { assertTrue(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withException(new IOException()).build())); }
@Test public void shouldRetry_ReturnsFalse_ForNonIOException() { assertFalse(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withException(new RuntimeException()).build())); assertFalse(retryPolicy.shouldRetry(1, CredentialsEndpointRetryParameters.builder().withException(new Exception()).build())); }
@Test public void shouldRetry_ReturnsFalse_WhenMaxRetriesExceeded() { assertFalse(retryPolicy.shouldRetry(5, CredentialsEndpointRetryParameters.builder().withStatusCode(501).build())); }