Skip to content

Commit

Permalink
aws2: update to use RetryStrategy (#608)
Browse files Browse the repository at this point in the history
The RetryPolicy classes are deprecated. Update to use the
newer RetryStrategy ([docs]).

[docs]: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/retry-strategy.html
  • Loading branch information
brharrington authored Aug 6, 2024
1 parent 2614ca8 commit dc123ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import software.amazon.awssdk.awscore.client.builder.AwsAsyncClientBuilder;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.awscore.client.builder.AwsSyncClientBuilder;
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
import software.amazon.awssdk.core.retry.RetryPolicy;
import software.amazon.awssdk.core.retry.backoff.BackoffStrategy;
import software.amazon.awssdk.core.retry.conditions.RetryCondition;
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
import software.amazon.awssdk.http.SdkHttpService;
import software.amazon.awssdk.http.async.SdkAsyncHttpService;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest;
Expand Down Expand Up @@ -94,13 +93,11 @@ private void setIfPresent(

private void setRetriesIfPresent(Config cfg, ClientOverrideConfiguration.Builder builder) {
if (cfg.hasPath("retry-policy.num-retries")) {
RetryPolicy retryPolicy = RetryPolicy.builder()
.backoffStrategy(BackoffStrategy.defaultStrategy())
.throttlingBackoffStrategy(BackoffStrategy.defaultThrottlingStrategy())
.numRetries(cfg.getInt("retry-policy.num-retries"))
.retryCondition(RetryCondition.defaultRetryCondition())
.build();
builder.retryPolicy(retryPolicy);
RetryStrategy retryStrategy = AwsRetryStrategy.defaultRetryStrategy()
.toBuilder()
.maxAttempts(cfg.getInt("retry-policy.num-retries") + 1)
.build();
builder.retryStrategy(retryStrategy);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void settingsTimeout() {
ClientOverrideConfiguration settings = factory.createClientConfig(cfg);
Assert.assertEquals(Duration.ofMillis(42000), settings.apiCallAttemptTimeout().get());
Assert.assertEquals(Duration.ofMillis(13000), settings.apiCallTimeout().get());
Assert.assertEquals(Integer.valueOf(5), settings.retryPolicy().get().numRetries());
Assert.assertEquals(6, settings.retryStrategy().get().maxAttempts());
}

@Test
Expand Down

0 comments on commit dc123ff

Please sign in to comment.