Created
March 14, 2021 07:26
-
-
Save tq-jappy/f48595e07374aea672aaed94233e6d61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import com.amazonaws.AmazonClientException; | |
import com.amazonaws.AmazonWebServiceRequest; | |
import com.amazonaws.ClientConfiguration; | |
import com.amazonaws.retry.PredefinedRetryPolicies; | |
import com.amazonaws.retry.RetryPolicy; | |
import com.amazonaws.services.dynamodbv2.model.InternalServerErrorException; | |
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException; | |
public class AwsSdkBackoffSimulation { | |
public static void main(String[] args) { | |
RetryPolicy.BackoffStrategy backoffStrategy1 = new ClientConfiguration() | |
.getRetryPolicy() | |
.getBackoffStrategy(); | |
RetryPolicy.BackoffStrategy backoffStrategy2 = new ClientConfiguration() | |
.withRetryPolicy(PredefinedRetryPolicies.DYNAMODB_DEFAULT) | |
.getRetryPolicy() | |
.getBackoffStrategy(); | |
AmazonClientException error = new InternalServerErrorException("error"); | |
ProvisionedThroughputExceededException throttleError = new ProvisionedThroughputExceededException("error"); | |
throttleError.setErrorCode("ThrottlingException"); | |
for (int i = 0; i < 10; i++) { | |
System.out.println(String.format("%03d, DEFAULT: %6d, DYNAMODB_DEFAULT: %6d, DEFAULT(throttleError): %6d, DYNAMODB_DEFAULT(throttleError): %6d", | |
i, | |
backoffStrategy1.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, error, i), | |
backoffStrategy2.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, error, i), | |
backoffStrategy1.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, throttleError, i), | |
backoffStrategy2.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, throttleError, i))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
サンプル実行結果