Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

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

import java.time.Duration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -103,4 +106,34 @@ public String handleRequest(String input, DurableContext context) {
assertEquals("success: test-input", result.getResult(String.class));
assertEquals(1, callCount.get());
}

@Test
void testStepContextAttemptNumbers_ShouldBeOneBased() {
var attempts = new CopyOnWriteArrayList<Integer>();
var handler = new DurableHandler<String, String>() {
@Override
public String handleRequest(String input, DurableContext context) {
return context.step(
"retry-step",
String.class,
stepContext -> {
attempts.add(stepContext.getAttempt());
if (stepContext.getAttempt() == 1) {
throw new RuntimeException("Retry once");
}
return "success";
},
StepConfig.builder()
.retryStrategy(RetryStrategies.fixedDelay(2, Duration.ofSeconds(1)))
.build());
}
};

var runner = LocalDurableTestRunner.create(String.class, handler);
var result = runner.runUntilComplete("test-input");

assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());
assertEquals("success", result.getResult(String.class));
assertEquals(List.of(1, 2), attempts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public ErrorObject getError() {
return details != null ? details.error() : null;
}

/** Returns the current retry attempt number (0-based), defaulting to 0 if not available. */
/** Returns the current retry attempt number (1-based), defaulting to 1 if not available. */
public int getAttempt() {
var details = operation.stepDetails();
return details != null && details.attempt() != null ? details.attempt() : 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import software.amazon.lambda.durable.context.BaseContext;

public interface StepContext extends BaseContext {
/** Returns the current retry attempt number (0-based). */
/** Returns the current retry attempt number (1-based). */
int getAttempt();

static StepContext getCurrentContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public DurableContextImpl createChildContext(String childContextId, String child
*
* @param stepOperationId the ID of the step operation (used for thread registration)
* @param stepOperationName the name of the step operation
* @param attempt the current retry attempt number (0-based)
* @param attempt the current retry attempt number (1-based)
* @return a new StepContext instance
*/
public StepContextImpl createStepContext(String stepOperationId, String stepOperationName, int attempt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class StepContextImpl extends BaseContextImpl implements StepContext {
* @param lambdaContext AWS Lambda runtime context
* @param stepOperationId Unique identifier for this context instance that equals to step operation id
* @param stepOperationName the name of the step operation
* @param attempt the current retry attempt number (0-based)
* @param attempt the current retry attempt number (1-based)
*/
protected StepContextImpl(
ExecutionManager executionManager,
Expand All @@ -38,7 +38,7 @@ protected StepContextImpl(
this.attempt = attempt;
}

/** Returns the current retry attempt number (0-based). */
/** Returns the current retry attempt number (1-based). */
@Override
public int getAttempt() {
return attempt;
Expand Down
Loading