Class LocalDurableTestRunner<I,O>
java.lang.Object
software.amazon.lambda.durable.testing.LocalDurableTestRunner<I,O>
- Type Parameters:
I- the handler input typeO- the handler output type
In-memory test runner for durable Lambda functions. Simulates the Lambda re-invocation loop locally without requiring
AWS infrastructure, enabling fast unit and integration tests.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdvances all pending operations, simulating time passing for retries and waits.voidcompleteCallback(String callbackId, String result) Complete a callback with success result.voidcompleteChainedInvoke(String name, String result) Completes a chained invoke operation with a successful result.static <I,O> LocalDurableTestRunner<I, O> create(Class<I> inputType, BiFunction<I, DurableContext, O> handlerFn) Creates a LocalDurableTestRunner with default configuration.static <I,O> LocalDurableTestRunner<I, O> create(Class<I> inputType, BiFunction<I, DurableContext, O> handlerFn, DurableConfig config) Creates a LocalDurableTestRunner that uses a custom configuration.static <I,O> LocalDurableTestRunner<I, O> create(Class<I> inputType, DurableHandler<I, O> handler) Creates a LocalDurableTestRunner from a DurableHandler instance, automatically extracting the configuration.static <I,O> LocalDurableTestRunner<I, O> create(TypeToken<I> inputType, BiFunction<I, DurableContext, O> handlerFn) Creates a LocalDurableTestRunner with default configuration.static <I,O> LocalDurableTestRunner<I, O> create(TypeToken<I> inputType, BiFunction<I, DurableContext, O> handlerFn, DurableConfig config) Creates a LocalDurableTestRunner that uses a custom configuration.static <I,O> LocalDurableTestRunner<I, O> create(TypeToken<I> inputType, DurableHandler<I, O> handler) Creates a LocalDurableTestRunner from a DurableHandler instance, automatically extracting the configuration.voidfailCallback(String callbackId, software.amazon.awssdk.services.lambda.model.ErrorObject error) Fail a callback with error.voidfailChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error) Fails a chained invoke operation with the given error.getCallbackId(String operationName) Get callback ID for a named callback operation.getOperation(String name) Returns theTestOperationfor the given operation name, or null if not found.voidresetCheckpointToStarted(String stepName) Resets a named step operation to STARTED status, simulating a checkpoint failure.Run a single invocation (may return PENDING if waiting/retrying).runUntilComplete(I input) Run until completion (SUCCEEDED or FAILED) or pending manual intervention, simulating Lambda re-invocations.voidsimulateFireAndForgetCheckpointLoss(String stepName) Removes a named step operation entirely, simulating loss of a fire-and-forget checkpoint.voidstopChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error) Stops a chained invoke operation with the given error.voidtimeoutCallback(String callbackId) Timeout a callback.voidtimeoutChainedInvoke(String name) Marks a chained invoke operation as timed out.
-
Method Details
-
create
public static <I,O> LocalDurableTestRunner<I,O> create(Class<I> inputType, BiFunction<I, DurableContext, O> handlerFn) Creates a LocalDurableTestRunner with default configuration. Use this method when your handler uses the default DurableConfig.- Type Parameters:
I- Input typeO- Output type- Parameters:
inputType- The input type classhandlerFn- The handler function- Returns:
- LocalDurableTestRunner with default configuration
-
create
public static <I,O> LocalDurableTestRunner<I,O> create(TypeToken<I> inputType, BiFunction<I, DurableContext, O> handlerFn) Creates a LocalDurableTestRunner with default configuration. Use this method when your handler uses the default DurableConfig.If your handler has custom configuration (custom SerDes, ExecutorService, etc.), use
create(TypeToken, DurableHandler)instead to ensure the test runner uses the same configuration as your handler.Optionally, you can also use
create(TypeToken, BiFunction, DurableConfig)to pass in any DurableConfig directly.- Type Parameters:
I- Input typeO- Output type- Parameters:
inputType- The input type classhandlerFn- The handler function- Returns:
- LocalDurableTestRunner with default configuration
-
create
public static <I,O> LocalDurableTestRunner<I,O> create(Class<I> inputType, BiFunction<I, DurableContext, O> handlerFn, DurableConfig config) Creates a LocalDurableTestRunner that uses a custom configuration. This allows the test runner to use custom SerDes and other configuration, while overriding the DurableExecutionClient with the in-memory implementation.- Type Parameters:
I- Input typeO- Output type- Parameters:
inputType- The input type classhandlerFn- The handler functionconfig- The DurableConfig to use (DurableExecutionClient will be overridden with in-memory implementation)- Returns:
- LocalDurableTestRunner configured with the provided settings
-
create
public static <I,O> LocalDurableTestRunner<I,O> create(TypeToken<I> inputType, BiFunction<I, DurableContext, O> handlerFn, DurableConfig config) Creates a LocalDurableTestRunner that uses a custom configuration. This allows the test runner to use custom SerDes and other configuration, while overriding the DurableExecutionClient with the in-memory implementation.Use this method when you need to pass a custom DurableConfig directly, for example when testing with a custom SerDes without using a DurableHandler.
Example usage:
// Create a custom DurableConfig with custom SerDes var config = DurableConfig.builder() .withSerDes(new MyCustomSerDes()) .build(); // Create test runner with custom configuration var runner = LocalDurableTestRunner.create( String.class, (input, context) -> context.step("process", String.class, stepCtx -> "result"), config ); // Run test with custom configuration var result = runner.run("test-input"); assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());- Type Parameters:
I- Input typeO- Output type- Parameters:
inputType- The input type classhandlerFn- The handler functionconfig- The DurableConfig to use (DurableExecutionClient will be overridden with in-memory implementation)- Returns:
- LocalDurableTestRunner configured with the provided settings
-
create
public static <I,O> LocalDurableTestRunner<I,O> create(Class<I> inputType, DurableHandler<I, O> handler) Creates a LocalDurableTestRunner from a DurableHandler instance, automatically extracting the configuration. This is a convenient method when you have a handler instance and want to test it with the same configuration it uses in production.- Type Parameters:
I- Input typeO- Output type- Parameters:
inputType- The input type classhandler- The DurableHandler instance to test- Returns:
- LocalDurableTestRunner configured with the handler's settings
-
create
public static <I,O> LocalDurableTestRunner<I,O> create(TypeToken<I> inputType, DurableHandler<I, O> handler) Creates a LocalDurableTestRunner from a DurableHandler instance, automatically extracting the configuration. This is a convenient method when you have a handler instance and want to test it with the same configuration it uses in production.This method automatically:
- Uses the handler's configuration (SerDes, ExecutorService, etc.)
- Overrides the DurableExecutionClient with the in-memory implementation for testing
Example usage:
// Create handler instance var handler = new MyCustomHandler(); // Create test runner from handler (automatically extracts config) var runner = LocalDurableTestRunner.create(String.class, handler); // Run test with the handler's configuration var result = runner.run("test-input"); assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());- Type Parameters:
I- Input typeO- Output type- Parameters:
inputType- The input type classhandler- The DurableHandler instance to test- Returns:
- LocalDurableTestRunner configured with the handler's settings
-
run
Run a single invocation (may return PENDING if waiting/retrying). -
runUntilComplete
Run until completion (SUCCEEDED or FAILED) or pending manual intervention, simulating Lambda re-invocations. Operations that don't require manual intervention (like WAIT in STARTED or STEP in PENDING) will be automatically advanced.- Parameters:
input- The input to process- Returns:
- Final test result (SUCCEEDED or FAILED) or PENDING if operations pending manual intervention
-
resetCheckpointToStarted
Resets a named step operation to STARTED status, simulating a checkpoint failure. -
simulateFireAndForgetCheckpointLoss
Removes a named step operation entirely, simulating loss of a fire-and-forget checkpoint. -
getOperation
Returns theTestOperationfor the given operation name, or null if not found. -
getCallbackId
Get callback ID for a named callback operation. -
completeCallback
Complete a callback with success result. -
failCallback
public void failCallback(String callbackId, software.amazon.awssdk.services.lambda.model.ErrorObject error) Fail a callback with error. -
timeoutCallback
Timeout a callback. -
advanceTime
public void advanceTime()Advances all pending operations, simulating time passing for retries and waits. -
completeChainedInvoke
Completes a chained invoke operation with a successful result. -
timeoutChainedInvoke
Marks a chained invoke operation as timed out. -
failChainedInvoke
public void failChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error) Fails a chained invoke operation with the given error. -
stopChainedInvoke
public void stopChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error) Stops a chained invoke operation with the given error.
-