Skip to content

Commit c851c22

Browse files
committed
Add input validation for duration parameters with 1-second minimum requirement
1 parent 1050e5a commit c851c22

3 files changed

Lines changed: 17 additions & 22 deletions

File tree

sdk/src/main/java/com/amazonaws/lambda/durable/validation/ParameterValidator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ public static void validateDuration(Duration duration, String parameterName) {
2929
throw new IllegalArgumentException(parameterName + " cannot be null");
3030
}
3131
if (duration.toSeconds() < MIN_DURATION_SECONDS) {
32-
throw new IllegalArgumentException(
33-
parameterName + " must be at least " + MIN_DURATION_SECONDS + " second, got: "
34-
+ duration.toSeconds() + " seconds");
32+
throw new IllegalArgumentException(parameterName + " must be at least " + MIN_DURATION_SECONDS
33+
+ " second, got: " + duration.toSeconds() + " seconds");
3534
}
3635
}
3736

@@ -44,9 +43,8 @@ public static void validateDuration(Duration duration, String parameterName) {
4443
*/
4544
public static void validateOptionalDuration(Duration duration, String parameterName) {
4645
if (duration != null && duration.toSeconds() < MIN_DURATION_SECONDS) {
47-
throw new IllegalArgumentException(
48-
parameterName + " must be at least " + MIN_DURATION_SECONDS + " second, got: "
49-
+ duration.toSeconds() + " seconds");
46+
throw new IllegalArgumentException(parameterName + " must be at least " + MIN_DURATION_SECONDS
47+
+ " second, got: " + duration.toSeconds() + " seconds");
5048
}
5149
}
5250

sdk/src/test/java/com/amazonaws/lambda/durable/DurationValidationIntegrationTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ void callbackConfig_withInvalidTimeout_shouldThrow() {
2121

2222
@Test
2323
void callbackConfig_withInvalidHeartbeatTimeout_shouldThrow() {
24-
var exception = assertThrows(
25-
IllegalArgumentException.class,
26-
() -> CallbackConfig.builder().heartbeatTimeout(Duration.ofMillis(999)).build());
24+
var exception = assertThrows(IllegalArgumentException.class, () -> CallbackConfig.builder()
25+
.heartbeatTimeout(Duration.ofMillis(999))
26+
.build());
2727

2828
assertTrue(exception.getMessage().contains("Heartbeat timeout"));
2929
assertTrue(exception.getMessage().contains("at least 1 second"));
@@ -39,10 +39,8 @@ void callbackConfig_withValidTimeouts_shouldPass() {
3939

4040
@Test
4141
void callbackConfig_withNullTimeouts_shouldPass() {
42-
assertDoesNotThrow(() -> CallbackConfig.builder()
43-
.timeout(null)
44-
.heartbeatTimeout(null)
45-
.build());
42+
assertDoesNotThrow(() ->
43+
CallbackConfig.builder().timeout(null).heartbeatTimeout(null).build());
4644
}
4745

4846
@Test
@@ -57,7 +55,8 @@ void invokeConfig_withInvalidTimeout_shouldThrow() {
5755

5856
@Test
5957
void invokeConfig_withValidTimeout_shouldPass() {
60-
assertDoesNotThrow(() -> InvokeConfig.builder().timeout(Duration.ofSeconds(30)).build());
58+
assertDoesNotThrow(
59+
() -> InvokeConfig.builder().timeout(Duration.ofSeconds(30)).build());
6160
}
6261

6362
@Test
@@ -67,9 +66,9 @@ void invokeConfig_withNullTimeout_shouldPass() {
6766

6867
@Test
6968
void durableConfig_withInvalidPollingInterval_shouldThrow() {
70-
var exception = assertThrows(
71-
IllegalArgumentException.class,
72-
() -> DurableConfig.builder().withPollingInterval(Duration.ofMillis(500)).build());
69+
var exception = assertThrows(IllegalArgumentException.class, () -> DurableConfig.builder()
70+
.withPollingInterval(Duration.ofMillis(500))
71+
.build());
7372

7473
assertTrue(exception.getMessage().contains("Polling interval"));
7574
assertTrue(exception.getMessage().contains("at least 1 second"));
@@ -84,8 +83,7 @@ void durableConfig_withValidPollingInterval_shouldPass() {
8483

8584
@Test
8685
void durableConfig_withNullPollingInterval_shouldPass() {
87-
assertDoesNotThrow(() -> DurableConfig.builder()
88-
.withPollingInterval(null)
89-
.build());
86+
assertDoesNotThrow(
87+
() -> DurableConfig.builder().withPollingInterval(null).build());
9088
}
9189
}

sdk/src/test/java/com/amazonaws/lambda/durable/retry/RetryStrategiesTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ void fixedDelay_withSubSecondDelay_shouldThrow() {
218218

219219
@Test
220220
void fixedDelay_withNullDelay_shouldThrow() {
221-
var exception =
222-
assertThrows(IllegalArgumentException.class, () -> RetryStrategies.fixedDelay(3, null));
221+
var exception = assertThrows(IllegalArgumentException.class, () -> RetryStrategies.fixedDelay(3, null));
223222

224223
assertTrue(exception.getMessage().contains("fixedDelay"));
225224
assertTrue(exception.getMessage().contains("cannot be null"));

0 commit comments

Comments
 (0)