Skip to content

Commit a552e61

Browse files
committed
Retry interrupted at-most-once steps
1 parent 5cce0d1 commit a552e61

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

sdk-integration-tests/src/test/java/software/amazon/lambda/durable/StepSemanticsIntegrationTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import static org.junit.jupiter.api.Assertions.*;
66

7+
import java.time.Duration;
78
import java.util.concurrent.atomic.AtomicInteger;
89
import org.junit.jupiter.api.Test;
910
import software.amazon.lambda.durable.config.StepConfig;
@@ -157,7 +158,7 @@ void testAtLeastOnceReExecutesAfterCheckpointFailure() {
157158
}
158159

159160
@Test
160-
void testAtMostOnceThrowsExceptionAfterCheckpointFailure() {
161+
void testAtMostOnceNoRetryFailsAfterCheckpointFailure() {
161162
var executionCount = new AtomicInteger(0);
162163

163164
var runner = LocalDurableTestRunner.create(String.class, (input, context) -> {
@@ -170,6 +171,7 @@ void testAtMostOnceThrowsExceptionAfterCheckpointFailure() {
170171
},
171172
StepConfig.builder()
172173
.semantics(StepSemantics.AT_MOST_ONCE_PER_RETRY)
174+
.retryStrategy(RetryStrategies.Presets.NO_RETRY)
173175
.build());
174176
});
175177

@@ -183,4 +185,33 @@ void testAtMostOnceThrowsExceptionAfterCheckpointFailure() {
183185
assertEquals(ExecutionStatus.FAILED, result.getStatus());
184186
assertEquals(1, executionCount.get());
185187
}
188+
189+
@Test
190+
void testAtMostOnceRetriesAfterCheckpointFailure() {
191+
var executionCount = new AtomicInteger(0);
192+
193+
var runner = LocalDurableTestRunner.create(String.class, (input, context) -> {
194+
return context.step(
195+
"step",
196+
String.class,
197+
stepCtx -> {
198+
var count = executionCount.incrementAndGet();
199+
return "Executed " + count + " times";
200+
},
201+
StepConfig.builder()
202+
.semantics(StepSemantics.AT_MOST_ONCE_PER_RETRY)
203+
.retryStrategy(RetryStrategies.fixedDelay(3, Duration.ofSeconds(1)))
204+
.build());
205+
});
206+
207+
runner.run("test");
208+
assertEquals(1, executionCount.get());
209+
210+
runner.resetCheckpointToStarted("step");
211+
var result = runner.runUntilComplete("test");
212+
213+
assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());
214+
assertEquals(2, executionCount.get());
215+
assertEquals("Executed 2 times", result.getResult(String.class));
216+
}
186217
}

sdk/src/main/java/software/amazon/lambda/durable/operation/StepOperation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ private void handleStepFailure(Throwable exception, int attempt) {
165165
errorObject = serializeException(exception);
166166
}
167167

168-
var isRetryable = !(exception instanceof StepInterruptedException);
169168
var retryDecision = config.retryStrategy().makeRetryDecision(exception, attempt);
170169

171-
if (isRetryable && retryDecision.shouldRetry()) {
170+
if (retryDecision.shouldRetry()) {
172171
// Send RETRY
173172
var retryDelayInSeconds = Math.toIntExact(retryDecision.delay().toSeconds());
174173
var retryUpdate = OperationUpdate.builder()

0 commit comments

Comments
 (0)