Class LocalDurableTestRunner<I,O>
java.lang.Object
software.amazon.lambda.durable.testing.LocalDurableTestRunner<I,O>
-
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcompleteCallback(String callbackId, String result) Complete a callback with success result.voidcompleteChainedInvoke(String name, String 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) getCallbackId(String operationName) Get callback ID for a named callback operation.getOperation(String name) voidresetCheckpointToStarted(String stepName) 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) voidstopChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error) voidtimeoutCallback(String callbackId) Timeout a callback.voidtimeoutChainedInvoke(String name)
-
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. -
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. -
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. -
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
-
simulateFireAndForgetCheckpointLoss
-
getOperation
-
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() -
completeChainedInvoke
-
timeoutChainedInvoke
-
failChainedInvoke
public void failChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error) -
stopChainedInvoke
public void stopChainedInvoke(String name, software.amazon.awssdk.services.lambda.model.ErrorObject error)
-