|
9 | 9 | package org.elasticsearch.repositories.s3; |
10 | 10 |
|
11 | 11 | import com.amazonaws.AmazonWebServiceRequest; |
| 12 | +import com.amazonaws.retry.PredefinedRetryPolicies; |
12 | 13 | import com.amazonaws.services.s3.model.AmazonS3Exception; |
13 | 14 |
|
14 | 15 | import org.elasticsearch.cluster.metadata.RepositoryMetadata; |
|
19 | 20 |
|
20 | 21 | import java.io.IOException; |
21 | 22 |
|
| 23 | +import static org.hamcrest.CoreMatchers.equalTo; |
22 | 24 | import static org.mockito.Mockito.mock; |
23 | 25 |
|
24 | 26 | public class S3ServiceTests extends ESTestCase { |
@@ -47,19 +49,33 @@ public void testRetryOn403RetryPolicy() { |
47 | 49 | e.setStatusCode(403); |
48 | 50 | e.setErrorCode("InvalidAccessKeyId"); |
49 | 51 |
|
50 | | - // Retry on 403 invalid access key id |
| 52 | + // AWS default retry condition does not retry on 403 |
| 53 | + assertFalse(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9))); |
| 54 | + |
| 55 | + // The retryable 403 condition retries on 403 invalid access key id |
51 | 56 | assertTrue( |
52 | 57 | S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition().shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9)) |
53 | 58 | ); |
54 | 59 |
|
55 | | - // Not retry if not 403 or not invalid access key id |
56 | 60 | if (randomBoolean()) { |
| 61 | + // Random for another error status that is not 403 |
57 | 62 | e.setStatusCode(randomValueOtherThan(403, () -> between(0, 600))); |
| 63 | + // Retryable 403 condition delegates to the AWS default retry condition. Its result must be consistent with the decision |
| 64 | + // by the AWS default, e.g. some error status like 429 is retryable by default, the retryable 403 condition respects it. |
| 65 | + boolean actual = S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition() |
| 66 | + .shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9)); |
| 67 | + boolean expected = PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry( |
| 68 | + mock(AmazonWebServiceRequest.class), |
| 69 | + e, |
| 70 | + between(0, 9) |
| 71 | + ); |
| 72 | + assertThat(actual, equalTo(expected)); |
58 | 73 | } else { |
| 74 | + // Not retry for 403 with error code that is not invalid access key id |
59 | 75 | e.setErrorCode(randomAlphaOfLength(10)); |
| 76 | + assertFalse( |
| 77 | + S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition().shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9)) |
| 78 | + ); |
60 | 79 | } |
61 | | - assertFalse( |
62 | | - S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition().shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9)) |
63 | | - ); |
64 | 80 | } |
65 | 81 | } |
0 commit comments