2626import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
2727import java .net .URI ;
2828import org .junit .jupiter .api .AfterEach ;
29- import org .junit .jupiter .api .BeforeEach ;
3029import org .junit .jupiter .api .Test ;
30+ import org .junit .jupiter .params .ParameterizedTest ;
31+ import org .junit .jupiter .params .provider .ValueSource ;
3132import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
3233import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
3334import software .amazon .awssdk .core .SdkSystemSetting ;
4142@ WireMockTest
4243class DynamoDbDefaultRetryFunctionalTest {
4344
44- private EnvironmentVariableHelper environmentVariableHelper ;
45+ private final EnvironmentVariableHelper environmentVariableHelper = new EnvironmentVariableHelper () ;
4546 private DynamoDbClient dynamoDbClient ;
4647
47- @ BeforeEach
48- void setup (WireMockRuntimeInfo wm ) {
49- environmentVariableHelper = new EnvironmentVariableHelper ();
50-
51- dynamoDbClient = DynamoDbClient .builder ()
52- .endpointOverride (URI .create (wm .getHttpBaseUrl ()))
53- .credentialsProvider (StaticCredentialsProvider .create (
54- AwsBasicCredentials .create ("test" , "test" )))
55- .region (Region .US_EAST_1 )
56- .build ();
57- }
58-
5948 @ AfterEach
6049 void tearDown () {
6150 environmentVariableHelper .reset ();
@@ -64,47 +53,49 @@ void tearDown() {
6453 }
6554 }
6655
67- @ Test
68- void listTables_whenNoRetryPolicySet_shouldAttempt9Times (WireMockRuntimeInfo wm ) {
69- stubFor (post (anyUrl ())
70- .willReturn (aResponse ().withStatus (503 )));
71- assertThatExceptionOfType (DynamoDbException .class )
72- .isThrownBy (() -> dynamoDbClient .listTables ());
73- int actualAttempts = wm .getWireMock ().getAllServeEvents ().size ();
74- assertThat (actualAttempts )
75- .as ("Default retry mode should result in 9 total attempts (1 initial + 8 retries)" )
76- .isEqualTo (9 );
77- }
56+ @ ParameterizedTest
57+ @ ValueSource (strings = {"adaptive" , "legacy" , "standard" })
58+ void listTables_whenRetryModeSet_shouldAttempt9Times (String retryMode , WireMockRuntimeInfo wm ) {
59+ // Set the retry mode environment variable
60+ environmentVariableHelper .set (SdkSystemSetting .AWS_RETRY_MODE .environmentVariable (), retryMode );
7861
79- @ Test
80- void listTables_whenRetryModeSetToStandard_shouldAttempt10Times (WireMockRuntimeInfo wm ) {
81- environmentVariableHelper .set (SdkSystemSetting .AWS_RETRY_MODE .environmentVariable (), "standard" );
82- dynamoDbClient .close ();
62+ // Build the DynamoDB client here instead of setup so that environment variable options gets picked for each tests
8363 dynamoDbClient = DynamoDbClient .builder ()
8464 .endpointOverride (URI .create (wm .getHttpBaseUrl ()))
8565 .credentialsProvider (StaticCredentialsProvider .create (
86- AwsBasicCredentials .create ("test " , "test " )))
66+ AwsBasicCredentials .create ("akid " , "skid " )))
8767 .region (Region .US_EAST_1 )
8868 .build ();
69+
8970 stubFor (post (anyUrl ())
9071 .willReturn (aResponse ().withStatus (503 )));
72+
9173 assertThatExceptionOfType (DynamoDbException .class )
9274 .isThrownBy (() -> dynamoDbClient .listTables ());
75+
9376 int actualAttempts = wm .getWireMock ().getAllServeEvents ().size ();
9477 assertThat (actualAttempts )
95- .as ("Standard retry mode should result in 9 total attempts (1 initial + 8 retries)" )
78+ .as ("Retry mode '%s' should result in 9 total attempts (1 initial + 8 retries)" , retryMode )
9679 .isEqualTo (9 );
9780 }
9881
9982 @ Test
10083 void listTables_whenUsingDefaultRetryMode_shouldAttempt9Times (WireMockRuntimeInfo wm ) {
84+ dynamoDbClient = DynamoDbClient .builder ()
85+ .endpointOverride (URI .create (wm .getHttpBaseUrl ()))
86+ .credentialsProvider (StaticCredentialsProvider .create (
87+ AwsBasicCredentials .create ("akid" , "skid" )))
88+ .region (Region .US_EAST_1 )
89+ .build ();
10190 stubFor (post (anyUrl ())
10291 .willReturn (aResponse ().withStatus (503 )));
10392 assertThatExceptionOfType (DynamoDbException .class )
10493 .isThrownBy (() -> dynamoDbClient .listTables ());
94+
10595 int actualAttempts = wm .getWireMock ().getAllServeEvents ().size ();
10696 assertThat (actualAttempts )
10797 .as ("Default retry mode should result in 9 total attempts (1 initial + 8 retries)" )
10898 .isEqualTo (9 );
10999 }
100+
110101}
0 commit comments