|
1 | 1 | package software.amazon.awssdk.services.dynamodb;
|
2 | 2 |
|
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import java.time.Duration; |
| 6 | +import org.junit.After; |
| 7 | +import org.junit.Before; |
3 | 8 | import org.junit.Test;
|
4 | 9 | import software.amazon.awssdk.core.SdkSystemSetting;
|
5 | 10 | import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
|
6 | 11 | import software.amazon.awssdk.core.retry.RetryPolicy;
|
7 |
| -import software.amazon.awssdk.profiles.ProfileFileSystemSetting; |
| 12 | +import software.amazon.awssdk.core.retry.backoff.BackoffStrategy; |
| 13 | +import software.amazon.awssdk.core.retry.backoff.FullJitterBackoffStrategy; |
8 | 14 | import software.amazon.awssdk.testutils.EnvironmentVariableHelper;
|
9 | 15 |
|
10 |
| -import static org.assertj.core.api.Assertions.assertThat; |
11 |
| - |
12 | 16 | public class DynamoDbRetryPolicyTest {
|
13 | 17 |
|
14 |
| - private static final EnvironmentVariableHelper ENVIRONMENT_VARIABLE_HELPER = new EnvironmentVariableHelper(); |
| 18 | + private EnvironmentVariableHelper environmentVariableHelper; |
| 19 | + |
| 20 | + @Before |
| 21 | + public void setup() { |
| 22 | + environmentVariableHelper = new EnvironmentVariableHelper(); |
| 23 | + } |
| 24 | + |
| 25 | + @After |
| 26 | + public void reset() { |
| 27 | + environmentVariableHelper.reset(); |
| 28 | + } |
15 | 29 |
|
16 | 30 | @Test
|
17 | 31 | public void test_numRetries_with_standardRetryPolicy() {
|
18 |
| - ENVIRONMENT_VARIABLE_HELPER.set(SdkSystemSetting.AWS_RETRY_MODE.environmentVariable(), "standard"); |
19 |
| - System.setProperty(ProfileFileSystemSetting.AWS_PROFILE.property(), "default"); |
| 32 | + environmentVariableHelper.set(SdkSystemSetting.AWS_RETRY_MODE.environmentVariable(), "standard"); |
20 | 33 | final SdkClientConfiguration sdkClientConfiguration = SdkClientConfiguration.builder().build();
|
21 | 34 | final RetryPolicy retryPolicy = DynamoDbRetryPolicy.resolveRetryPolicy(sdkClientConfiguration);
|
22 | 35 | assertThat(retryPolicy.numRetries()).isEqualTo(8);
|
23 | 36 | }
|
24 | 37 |
|
25 | 38 | @Test
|
26 | 39 | public void test_numRetries_with_legacyRetryPolicy() {
|
27 |
| - ENVIRONMENT_VARIABLE_HELPER.set(SdkSystemSetting.AWS_RETRY_MODE.environmentVariable(), "legacy"); |
28 |
| - System.setProperty(ProfileFileSystemSetting.AWS_PROFILE.property(), "default"); |
| 40 | + environmentVariableHelper.set(SdkSystemSetting.AWS_RETRY_MODE.environmentVariable(), "legacy"); |
29 | 41 | final SdkClientConfiguration sdkClientConfiguration = SdkClientConfiguration.builder().build();
|
30 | 42 | final RetryPolicy retryPolicy = DynamoDbRetryPolicy.resolveRetryPolicy(sdkClientConfiguration);
|
31 | 43 | assertThat(retryPolicy.numRetries()).isEqualTo(8);
|
32 | 44 | }
|
33 | 45 |
|
| 46 | + @Test |
| 47 | + public void test_backoffBaseDelay_with_standardRetryPolicy() { |
| 48 | + environmentVariableHelper.set(SdkSystemSetting.AWS_RETRY_MODE.environmentVariable(), "standard"); |
| 49 | + SdkClientConfiguration sdkClientConfiguration = SdkClientConfiguration.builder().build(); |
| 50 | + RetryPolicy retryPolicy = DynamoDbRetryPolicy.resolveRetryPolicy(sdkClientConfiguration); |
| 51 | + BackoffStrategy backoffStrategy = retryPolicy.backoffStrategy(); |
| 52 | + |
| 53 | + assertThat(backoffStrategy).isInstanceOfSatisfying(FullJitterBackoffStrategy.class, fjbs -> { |
| 54 | + assertThat(fjbs.toBuilder().baseDelay()).isEqualTo(Duration.ofMillis(25)); |
| 55 | + }); |
| 56 | + } |
34 | 57 |
|
35 | 58 | }
|
0 commit comments