26
26
import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
27
27
import java .net .URI ;
28
28
import org .junit .jupiter .api .AfterEach ;
29
- import org .junit .jupiter .api .BeforeEach ;
30
29
import org .junit .jupiter .api .Test ;
30
+ import org .junit .jupiter .params .ParameterizedTest ;
31
+ import org .junit .jupiter .params .provider .ValueSource ;
31
32
import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
32
33
import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
33
34
import software .amazon .awssdk .core .SdkSystemSetting ;
41
42
@ WireMockTest
42
43
class DynamoDbDefaultRetryFunctionalTest {
43
44
44
- private EnvironmentVariableHelper environmentVariableHelper ;
45
+ private final EnvironmentVariableHelper environmentVariableHelper = new EnvironmentVariableHelper () ;
45
46
private DynamoDbClient dynamoDbClient ;
46
47
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
-
59
48
@ AfterEach
60
49
void tearDown () {
61
50
environmentVariableHelper .reset ();
@@ -64,47 +53,49 @@ void tearDown() {
64
53
}
65
54
}
66
55
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 );
78
61
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
83
63
dynamoDbClient = DynamoDbClient .builder ()
84
64
.endpointOverride (URI .create (wm .getHttpBaseUrl ()))
85
65
.credentialsProvider (StaticCredentialsProvider .create (
86
- AwsBasicCredentials .create ("test " , "test " )))
66
+ AwsBasicCredentials .create ("akid " , "skid " )))
87
67
.region (Region .US_EAST_1 )
88
68
.build ();
69
+
89
70
stubFor (post (anyUrl ())
90
71
.willReturn (aResponse ().withStatus (503 )));
72
+
91
73
assertThatExceptionOfType (DynamoDbException .class )
92
74
.isThrownBy (() -> dynamoDbClient .listTables ());
75
+
93
76
int actualAttempts = wm .getWireMock ().getAllServeEvents ().size ();
94
77
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 )
96
79
.isEqualTo (9 );
97
80
}
98
81
99
82
@ Test
100
83
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 ();
101
90
stubFor (post (anyUrl ())
102
91
.willReturn (aResponse ().withStatus (503 )));
103
92
assertThatExceptionOfType (DynamoDbException .class )
104
93
.isThrownBy (() -> dynamoDbClient .listTables ());
94
+
105
95
int actualAttempts = wm .getWireMock ().getAllServeEvents ().size ();
106
96
assertThat (actualAttempts )
107
97
.as ("Default retry mode should result in 9 total attempts (1 initial + 8 retries)" )
108
98
.isEqualTo (9 );
109
99
}
100
+
110
101
}
0 commit comments