Skip to content

Commit 344f828

Browse files
committed
chore: set default retry strategy when missing config
1 parent ca928ab commit 344f828

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

sdk/src/main/java/software/amazon/lambda/durable/config/WithRetryConfig.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package software.amazon.lambda.durable.config;
44

5+
import software.amazon.lambda.durable.retry.RetryStrategies;
56
import software.amazon.lambda.durable.retry.RetryStrategy;
67

78
/**
89
* Configuration for {@link software.amazon.lambda.durable.util.WithRetryHelper#withRetry}.
910
*
1011
* <p>Uses the same {@link RetryStrategy} shape that developers already know from {@link StepConfig}, so there are zero
11-
* new retry concepts to learn.
12+
* new retry concepts to learn. If no retry strategy is specified, {@link RetryStrategies.Presets#DEFAULT} is used.
1213
*/
1314
public class WithRetryConfig {
1415
private final RetryStrategy retryStrategy;
@@ -20,12 +21,13 @@ private WithRetryConfig(Builder builder) {
2021
}
2122

2223
/**
23-
* Returns the retry strategy. Same type as {@link StepConfig#retryStrategy()}.
24+
* Returns the retry strategy, or the default strategy if not specified. Same type as
25+
* {@link StepConfig#retryStrategy()}.
2426
*
2527
* @return the retry strategy, never null
2628
*/
2729
public RetryStrategy retryStrategy() {
28-
return retryStrategy;
30+
return retryStrategy != null ? retryStrategy : RetryStrategies.Presets.DEFAULT;
2931
}
3032

3133
/**
@@ -56,7 +58,7 @@ public static class Builder {
5658
private Builder() {}
5759

5860
/**
59-
* Sets the retry strategy. Required.
61+
* Sets the retry strategy. Optional — defaults to {@link RetryStrategies.Presets#DEFAULT} if not set.
6062
*
6163
* <p>Reuses the exact same {@link RetryStrategy} interface from {@link StepConfig}. All existing factory
6264
* methods ({@link software.amazon.lambda.durable.retry.RetryStrategies#exponentialBackoff},
@@ -91,12 +93,8 @@ public Builder wrapInChildContext(boolean wrapInChildContext) {
9193
* Builds the {@link WithRetryConfig} instance.
9294
*
9395
* @return a new config with the configured options
94-
* @throws IllegalArgumentException if retryStrategy is not set
9596
*/
9697
public WithRetryConfig build() {
97-
if (retryStrategy == null) {
98-
throw new IllegalArgumentException("retryStrategy is required");
99-
}
10098
return new WithRetryConfig(this);
10199
}
102100
}

sdk/src/test/java/software/amazon/lambda/durable/config/WithRetryConfigTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ void builderWithRetryStrategy() {
2020
}
2121

2222
@Test
23-
void builderWithoutRetryStrategy_shouldThrow() {
24-
var exception = assertThrows(
25-
IllegalArgumentException.class, () -> WithRetryConfig.builder().build());
23+
void builderWithoutRetryStrategy_usesDefault() {
24+
var config = WithRetryConfig.builder().build();
2625

27-
assertEquals("retryStrategy is required", exception.getMessage());
26+
assertEquals(RetryStrategies.Presets.DEFAULT, config.retryStrategy());
2827
}
2928

3029
@Test

0 commit comments

Comments
 (0)