Skip to content

Commit 3b5cdbd

Browse files
authored
External names used for retry modes only support 'adaptive' (#5265)
* Externally named retry modes only support 'adaptive' Behind the scenes this will be mapped to RetryMode.ADAPTIVE_V2 which makes it a non-backwards compatible behavioral change. * Sneak in a fix from the previous PR * Fix a test that expects adaptive to map to `RetryMode.ADAPTIVE` * Fix typos in the comments
1 parent c8ac21e commit 3b5cdbd

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

core/aws-core/src/main/java/software/amazon/awssdk/awscore/retry/AwsRetryStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static RetryStrategy addRetryConditions(RetryStrategy strategy) {
7979
}
8080

8181
/**
82-
* Returns a retry strategy that do not retry.
82+
* Returns a retry strategy that does not retry.
8383
*
8484
* @return A retry strategy that do not retry.
8585
*/

core/retries/src/main/java/software/amazon/awssdk/retries/DefaultRetryStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private DefaultRetryStrategy() {
3030
}
3131

3232
/**
33-
* Returns a retry strategy that do not retry.
33+
* Returns a retry strategy that does not retry.
3434
*/
3535
public static StandardRetryStrategy doNotRetry() {
3636
return standardStrategyBuilder()

core/sdk-core/src/main/java/software/amazon/awssdk/core/retry/RetryMode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ private static Optional<RetryMode> fromString(String string) {
197197
case "standard":
198198
return Optional.of(STANDARD);
199199
case "adaptive":
200-
return Optional.of(ADAPTIVE);
201-
case "adaptive_v2":
202200
return Optional.of(ADAPTIVE_V2);
203201
default:
204202
throw new IllegalStateException("Unsupported retry policy mode configured: " + string);

core/sdk-core/src/test/java/software/amazon/awssdk/core/retry/RetryModeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public static Collection<Object> data() {
5050
// Test resolution
5151
new TestData("legacy", null, null, null, RetryMode.LEGACY),
5252
new TestData("standard", null, null, null, RetryMode.STANDARD),
53-
new TestData("adaptive", null, null, null, RetryMode.ADAPTIVE),
53+
new TestData("adaptive", null, null, null, RetryMode.ADAPTIVE_V2),
5454
new TestData("lEgAcY", null, null, null, RetryMode.LEGACY),
5555
new TestData("sTanDaRd", null, null, null, RetryMode.STANDARD),
56-
new TestData("aDaPtIvE", null, null, null, RetryMode.ADAPTIVE),
56+
new TestData("aDaPtIvE", null, null, null, RetryMode.ADAPTIVE_V2),
5757

5858
// Test precedence
5959
new TestData("standard", "legacy", "PropertySetToLegacy", RetryMode.LEGACY, RetryMode.STANDARD),

services/dynamodb/src/test/java/software/amazon/awssdk/services/dynamodb/DynamoDbRetryPolicyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void resolve_retryModeSetWithSupplier_resolvesFromSupplier() {
8888
RetryStrategy retryStrategy = DynamoDbRetryPolicy.resolveRetryStrategy(sdkClientConfiguration);
8989
RetryMode retryMode = SdkDefaultRetryStrategy.retryMode(retryStrategy);
9090

91-
assertThat(retryMode).isEqualTo(RetryMode.ADAPTIVE);
91+
assertThat(retryMode).isEqualTo(RetryMode.ADAPTIVE_V2);
9292
}
9393

9494
@Test

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/retry/BaseRetrySetupTest.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void setupRetryPolicy(BuilderT builder, RetryScenario scenario) {
9494
RetryModeSetup setup = scenario.setup();
9595
switch (setup) {
9696
case PROFILE_USING_MODE:
97-
setupProfile(builder, scenario.mode());
97+
setupProfile(builder, scenario);
9898
break;
9999
case CLIENT_OVERRIDE_USING_MODE:
100100
builder.overrideConfiguration(o -> o.retryPolicy(mode));
@@ -115,7 +115,7 @@ private void setupRetryStrategy(BuilderT builder, RetryScenario scenario) {
115115
// client.
116116
switch (scenario.setup()) {
117117
case PROFILE_USING_MODE:
118-
setupProfile(builder, scenario.mode());
118+
setupProfile(builder, scenario);
119119
break;
120120
case CLIENT_OVERRIDE_USING_MODE:
121121
builder.overrideConfiguration(o -> o.retryStrategy(mode));
@@ -130,8 +130,8 @@ private void setupRetryStrategy(BuilderT builder, RetryScenario scenario) {
130130
}
131131
}
132132

133-
private void setupProfile(BuilderT builder, RetryMode mode) {
134-
String modeName = mode.toString().toLowerCase(Locale.ROOT);
133+
private void setupProfile(BuilderT builder, RetryScenario scenario) {
134+
String modeName = scenario.modeExternalName();
135135
ProfileFile profileFile = ProfileFile.builder()
136136
.content(new StringInputStream("[profile retry_test]\n" +
137137
"retry_mode = " + modeName))
@@ -165,7 +165,7 @@ private BuilderT clientBuilder() {
165165

166166
private void setupScenarioBefore(RetryScenario scenario) {
167167
if (scenario.setup() == RetryModeSetup.SYSTEM_PROPERTY_USING_MODE) {
168-
System.setProperty("aws.retryMode", scenario.mode().name().toLowerCase(Locale.ROOT));
168+
System.setProperty("aws.retryMode", scenario.modeExternalName());
169169
}
170170
}
171171

@@ -236,6 +236,16 @@ private static boolean isSupportedScenario(RetryScenario scenario) {
236236
return false;
237237
}
238238

239+
// System property or profile do not support the internal "adaptive_v2" name, only adaptive,
240+
// and it's mapped to adaptive_v2. We mark here adaptive using profile or system property
241+
// and map in the tests "adaptive_v2" to "adaptive" such that everything comes together at
242+
// the end.
243+
if (scenario.mode() == RetryMode.ADAPTIVE
244+
&& (scenario.setup() == RetryModeSetup.PROFILE_USING_MODE
245+
|| scenario.setup() == RetryModeSetup.SYSTEM_PROPERTY_USING_MODE)) {
246+
return false;
247+
}
248+
239249
// Retry policies only support the legacy ADAPTIVE mode.
240250
if (scenario.retryImplementation() == RetryImplementation.POLICY
241251
&& scenario.mode() == RetryMode.ADAPTIVE_V2) {
@@ -323,6 +333,25 @@ public Builder toBuilder() {
323333
return new Builder(this);
324334
}
325335

336+
/**
337+
* Returns the name used externally of the given mode. This name is used in the profile `retry_mode` setting or in the
338+
* system property. Externally, "adaptive" gets mapped to RetryMode.ADAPTIVE_V2, and "adaptive_v2" is an internal name
339+
* only and not supported externally.
340+
*/
341+
public String modeExternalName() {
342+
switch (mode) {
343+
case ADAPTIVE:
344+
case ADAPTIVE_V2:
345+
return "adaptive";
346+
case LEGACY:
347+
return "legacy";
348+
case STANDARD:
349+
return "standard";
350+
default:
351+
throw new RuntimeException("Unsupported mode: " + mode);
352+
}
353+
}
354+
326355
@Override
327356
public String toString() {
328357
return mode + " " + retryImplementation + " " + setup;

0 commit comments

Comments
 (0)