|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.core.retry; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.AfterEach; |
| 22 | +import org.junit.jupiter.api.BeforeEach; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | +import org.junit.jupiter.params.ParameterizedTest; |
| 25 | +import org.junit.jupiter.params.provider.CsvSource; |
| 26 | +import software.amazon.awssdk.core.SdkSystemSetting; |
| 27 | +import software.amazon.awssdk.testutils.EnvironmentVariableHelper; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for the gated default {@link RetryMode} behavior controlled by |
| 31 | + * {@link SdkSystemSetting#AWS_NEW_RETRIES_2026}. |
| 32 | + */ |
| 33 | +class RetryModeGatedDefaultTest { |
| 34 | + |
| 35 | + @BeforeEach |
| 36 | + @AfterEach |
| 37 | + void cleanup() { |
| 38 | + System.clearProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property()); |
| 39 | + System.clearProperty(SdkSystemSetting.AWS_RETRY_MODE.property()); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void defaultRetryMode_returnsLegacy_whenGateIsUnset() { |
| 44 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(RetryMode.LEGACY); |
| 45 | + } |
| 46 | + |
| 47 | + @ParameterizedTest(name = "gate=\"{0}\" -> {1}") |
| 48 | + @CsvSource({ |
| 49 | + "false, LEGACY", |
| 50 | + "true, STANDARD" |
| 51 | + }) |
| 52 | + void defaultRetryMode_reflectsGate_whenSetViaSystemProperty(String gateValue, RetryMode expected) { |
| 53 | + System.setProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property(), gateValue); |
| 54 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(expected); |
| 55 | + } |
| 56 | + |
| 57 | + @ParameterizedTest(name = "gate=\"{0}\" -> {1}") |
| 58 | + @CsvSource({ |
| 59 | + "false, LEGACY", |
| 60 | + "true, STANDARD" |
| 61 | + }) |
| 62 | + void defaultRetryMode_reflectsGate_whenSetViaEnvVar(String gateValue, RetryMode expected) { |
| 63 | + EnvironmentVariableHelper.run(helper -> { |
| 64 | + helper.set(SdkSystemSetting.AWS_NEW_RETRIES_2026, gateValue); |
| 65 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(expected); |
| 66 | + }); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void defaultRetryMode_changesDynamically_whenGateSystemPropertyChangesAtRuntime() { |
| 71 | + // Initially unset — should be LEGACY |
| 72 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(RetryMode.LEGACY); |
| 73 | + |
| 74 | + // Enable gate — should switch to STANDARD |
| 75 | + System.setProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property(), "true"); |
| 76 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(RetryMode.STANDARD); |
| 77 | + |
| 78 | + // Disable gate — should revert to LEGACY |
| 79 | + System.setProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property(), "false"); |
| 80 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(RetryMode.LEGACY); |
| 81 | + |
| 82 | + // Clear gate — should fall back to default (LEGACY) |
| 83 | + System.clearProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property()); |
| 84 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(RetryMode.LEGACY); |
| 85 | + } |
| 86 | + |
| 87 | + @ParameterizedTest(name = "gate=\"{0}\" retryMode=\"{1}\" -> {2}") |
| 88 | + @CsvSource({ |
| 89 | + "true, legacy, LEGACY", |
| 90 | + "false, standard, STANDARD", |
| 91 | + "false, adaptive, ADAPTIVE_V2" |
| 92 | + }) |
| 93 | + void resolve_honorsExplicitRetryMode_regardlessOfGate(String gateValue, String retryModeValue, RetryMode expected) { |
| 94 | + System.setProperty(SdkSystemSetting.AWS_NEW_RETRIES_2026.property(), gateValue); |
| 95 | + System.setProperty(SdkSystemSetting.AWS_RETRY_MODE.property(), retryModeValue); |
| 96 | + assertThat(RetryMode.defaultRetryMode()).isEqualTo(expected); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + void resolve_throwsIllegalStateException_whenInvalidRetryModeConfigured() { |
| 101 | + System.setProperty(SdkSystemSetting.AWS_RETRY_MODE.property(), "invalid_mode"); |
| 102 | + assertThatThrownBy(RetryMode::defaultRetryMode).isInstanceOf(IllegalStateException.class); |
| 103 | + } |
| 104 | +} |
0 commit comments