From 1ee87fc4e95c02e6d09e2f5478bbb04e342bcd99 Mon Sep 17 00:00:00 2001 From: Niels Kootstra <545768+nkootstra@users.noreply.github.com> Date: Sun, 18 Oct 2026 15:10:25 +0200 Subject: [PATCH] fix(stepfunctions): end an Express execution at its maximum execution time instead of letting it run on (#5864) * fix(stepfunctions): end a synchronous execution at its maximum execution time instead of letting it run on * test(stepfunctions): build AslExecutor in tests through a shared fixture * fix(stepfunctions): keep the first outcome of a timed-out Express execution and limit asynchronous Express executions too * fix(stepfunctions): time out an execution a late runtime error reaches, and measure its deadlines on an injectable clock * test(stepfunctions): test the synchronous caller's timeout step directly instead of on the real clock --- .../services/stepfunctions/AslExecutor.java | 141 +++++++--- ...AslExecutorArrayAndMathIntrinsicsTest.java | 37 +-- .../AslExecutorArrayParamsTest.java | 7 +- .../AslExecutorBranchHistoryEventsTest.java | 31 +-- .../stepfunctions/AslExecutorCatchTest.java | 31 +-- .../AslExecutorChoiceRuntimeTest.java | 37 +-- ...AslExecutorCustomResourceLivenessTest.java | 31 +-- .../AslExecutorEcsRunTaskModeTest.java | 39 +-- .../AslExecutorErrorTerminationTest.java | 33 +-- .../AslExecutorFailStateErrorCauseTest.java | 31 +-- .../stepfunctions/AslExecutorFixture.java | 251 ++++++++++++++++++ .../AslExecutorHistoryEventLimitTest.java | 31 +-- .../AslExecutorHttpInvokeTest.java | 36 +-- .../AslExecutorIntrinsicContextTest.java | 7 +- .../AslExecutorIntrinsicFunctionsTest.java | 37 +-- ...lExecutorIntrinsicMissingArgumentTest.java | 33 +-- .../AslExecutorJsonMergeTest.java | 38 +-- .../AslExecutorLambdaArnTargetTest.java | 40 +-- .../AslExecutorLambdaInvokeResultTest.java | 32 +-- .../AslExecutorLambdaThrottleTest.java | 41 +-- .../AslExecutorMockedResponsesTest.java | 31 +-- .../AslExecutorNestedQueryLanguageTest.java | 32 +-- .../AslExecutorNestedStartExecutionTest.java | 36 +-- .../AslExecutorNestedSyncFailureTest.java | 45 +--- .../AslExecutorNestedSyncTimeoutTest.java | 45 +--- .../AslExecutorParallelCutTest.java | 46 +--- .../AslExecutorPathIntrinsicsTest.java | 33 +-- .../AslExecutorRedshiftDataDisabledTest.java | 10 +- .../AslExecutorResultPathTest.java | 28 +- .../AslExecutorResultWriterTest.java | 33 +-- .../stepfunctions/AslExecutorRetryTest.java | 31 +-- .../AslExecutorStatePathTest.java | 38 +-- .../AslExecutorSyncTimeoutTest.java | 247 +++++++++++++++++ .../AslExecutorTaskHistoryEventsTest.java | 31 +-- .../AslExecutorTerminalStateTest.java | 32 +-- .../AslExecutorUnresolvableJsonPathTest.java | 7 +- .../AslExecutorWaitStateTest.java | 48 +--- 37 files changed, 804 insertions(+), 933 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFixture.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorSyncTimeoutTest.java diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java index 8bb24567fd..a6e7247847 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java @@ -124,6 +124,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.function.LongSupplier; import java.util.stream.Collectors; @ApplicationScoped @@ -162,6 +163,9 @@ public class AslExecutor { // How long a Task waits for its token, or for a .sync job to end, when the state declares no // TimeoutSeconds. AWS lets it run for a year; the emulator would rather free the worker thread. private static final int DEFAULT_TASK_TIMEOUT_SECONDS = 300; + // AWS's hard quota on an Express execution, synchronous or not. + private static final Duration EXPRESS_MAX_EXECUTION_TIME = Duration.ofMinutes(5); + private static final Set TERMINAL_STATUSES = Set.of("SUCCEEDED", "FAILED", "TIMED_OUT", "ABORTED"); /** * AWS ends an execution once its history reaches this many events. The count is neither reset @@ -268,6 +272,9 @@ public class AslExecutor { private final Sleeper sleeper; // Null in production, where the ceiling comes from the Step Functions config. Tests pin it. private final Integer maxWaitSecondsOverride; + private final Duration expressMaxExecutionTime; + // The monotonic clock every execution and task deadline is measured on. Tests move it forward. + private final LongSupplier nanoTime; private final Map activeMocks = new ConcurrentHashMap<>(); private final ExecutorService executor = Executors.newCachedThreadPool(r -> { Thread t = new Thread(r, "sfn-executor"); @@ -294,7 +301,7 @@ public class AslExecutor { eventBridgeHandler, schedulerService, schedulerController, rdsDataService, objectMapper, jsonataEvaluator, sfnService, config, vertx, customResourceLiveness, Clock.systemUTC(), TimeUnit.NANOSECONDS::sleep, null, redshiftDataHandler, serviceRegistry, - lambdaTaskAuthorizer); + lambdaTaskAuthorizer, null, null); } AslExecutor(LambdaExecutorService lambdaExecutor, LambdaTargetResolver targetResolver, @@ -310,7 +317,8 @@ public class AslExecutor { CustomResourceLiveness customResourceLiveness, Clock clock, Sleeper sleeper, Integer maxWaitSecondsOverride, RedshiftDataJsonHandler redshiftDataHandler, ServiceRegistry serviceRegistry, - LambdaTaskAuthorizer lambdaTaskAuthorizer) { + LambdaTaskAuthorizer lambdaTaskAuthorizer, Duration expressMaxExecutionTimeOverride, + LongSupplier nanoTimeOverride) { this.serviceRegistry = serviceRegistry; this.lambdaTaskAuthorizer = lambdaTaskAuthorizer; this.customResourceLiveness = customResourceLiveness; @@ -343,6 +351,10 @@ public class AslExecutor { this.clock = clock; this.sleeper = sleeper; this.maxWaitSecondsOverride = maxWaitSecondsOverride; + this.nanoTime = nanoTimeOverride != null ? nanoTimeOverride : System::nanoTime; + this.expressMaxExecutionTime = expressMaxExecutionTimeOverride != null + ? expressMaxExecutionTimeOverride + : EXPRESS_MAX_EXECUTION_TIME; if (vertx != null) { // This can be optimized further // TODO Set WebclientOptions useragent to Amazon|StepFunctions|HttpInvoke|{{{{region}}}} @@ -369,7 +381,7 @@ public class AslExecutor { ec2Service, s3Service, ecsService, ecsJsonHandler, eventBridgeHandler, schedulerService, schedulerController, rdsDataService, objectMapper, jsonataEvaluator, sfnService, config, vertx, customResourceLiveness, - Clock.systemUTC(), TimeUnit.NANOSECONDS::sleep, null, null, null, null); + Clock.systemUTC(), TimeUnit.NANOSECONDS::sleep, null, null, null, null, null, null); } // Kept for tests that do not exercise the Redshift Data API integration. @@ -390,7 +402,7 @@ public class AslExecutor { ec2Service, s3Service, ecsService, ecsJsonHandler, eventBridgeHandler, schedulerService, schedulerController, rdsDataService, objectMapper, jsonataEvaluator, sfnService, config, vertx, customResourceLiveness, - clock, sleeper, maxWaitSecondsOverride, null, null, null); + clock, sleeper, maxWaitSecondsOverride, null, null, null, null, null); } AslExecutor(LambdaExecutorService lambdaExecutor, LambdaFunctionStore functionStore, @@ -458,9 +470,15 @@ public class AslExecutor { MockedTestCase mockedTestCase, BiConsumer> onUpdate) { registerMocks(exec, mockedTestCase); + // An Express execution has the same maximum execution time however it was started; a + // Standard one is allowed a year, which the emulator does not enforce. + long maxExecutionDeadlineNanos = "EXPRESS".equals(sm.getType()) + ? nanoTime.getAsLong() + expressMaxExecutionTime.toNanos() + : Long.MAX_VALUE; executor.submit(() -> { try { - runUnderExecutionAccount(sm, () -> doExecute(sm, exec, history, onUpdate)); + runUnderExecutionAccount(sm, + () -> doExecute(sm, exec, history, onUpdate, maxExecutionDeadlineNanos)); } catch (RuntimeException | Error e) { // submit() parks whatever the task throws in a Future nobody reads, so without this // the worker dies silently. doExecute has already published the terminal status by @@ -486,19 +504,37 @@ public class AslExecutor { MockedTestCase mockedTestCase, BiConsumer> onUpdate) { registerMocks(exec, mockedTestCase); + // The execution itself ends at this deadline, as it does at its TimeoutSeconds, so it runs + // no further state once the caller has been answered TIMED_OUT. + long maxExecutionDeadlineNanos = nanoTime.getAsLong() + expressMaxExecutionTime.toNanos(); try { - Future f = executor.submit(() -> - runUnderExecutionAccount(sm, () -> doExecute(sm, exec, history, onUpdate))); - f.get(300, TimeUnit.SECONDS); + Future f = executor.submit(() -> runUnderExecutionAccount(sm, + () -> doExecute(sm, exec, history, onUpdate, maxExecutionDeadlineNanos))); + f.get(maxExecutionDeadlineNanos - nanoTime.getAsLong(), TimeUnit.NANOSECONDS); } catch (java.util.concurrent.TimeoutException e) { - exec.setStopDate(System.currentTimeMillis() / 1000.0); - exec.setStatus("TIMED_OUT"); - onUpdate.accept(exec, history); + answerTimedOutUnlessEnded(exec, history, onUpdate); } catch (Exception e) { LOG.warnv("Sync execution wait failed for {0}: {1}", exec.getExecutionArn(), e.getMessage()); } } + /** + * Answers a synchronous caller whose wait ran out. The worker ends itself at the same deadline; + * this publishes TIMED_OUT when it has not yet, and never replaces an outcome the worker already + * published. + */ + void answerTimedOutUnlessEnded(Execution exec, List history, + BiConsumer> onUpdate) { + synchronized (exec) { + if (hasEnded(exec)) { + return; + } + exec.setStopDate(System.currentTimeMillis() / 1000.0); + exec.setStatus("TIMED_OUT"); + } + onUpdate.accept(exec, history); + } + /** * Runs {@code body} on this worker thread under a CDI request scope whose account is * the one encoded in the state machine ARN, so service integrations (Lambda, DynamoDB, @@ -541,8 +577,9 @@ public class AslExecutor { } private void doExecute(StateMachine sm, Execution exec, List history, - BiConsumer> onUpdate) { + BiConsumer> onUpdate, long maxExecutionDeadlineNanos) { HistoryChain chain = HistoryChain.of(history); + long executionDeadlineNanos = maxExecutionDeadlineNanos; try { JsonNode definition = objectMapper.readTree(sm.getDefinition()); JsonNode states = definition.path("States"); @@ -550,11 +587,13 @@ public class AslExecutor { String topLevelQueryLanguage = definition.path("QueryLanguage").asText("JSONPath"); JsonNode currentInput = parseInput(exec.getInput()); // The state machine's total budget, computed once so every state measures against the - // same instant. Long.MAX_VALUE stands for a definition with no TimeoutSeconds. + // same instant: the earlier of its TimeoutSeconds and the maximum execution time its + // workflow type allows. Long.MAX_VALUE stands for neither. int timeoutSeconds = definition.path("TimeoutSeconds").asInt(0); - long executionDeadlineNanos = timeoutSeconds > 0 - ? System.nanoTime() + TimeUnit.SECONDS.toNanos(timeoutSeconds) - : Long.MAX_VALUE; + if (timeoutSeconds > 0) { + executionDeadlineNanos = Math.min( + nanoTime.getAsLong() + TimeUnit.SECONDS.toNanos(timeoutSeconds), maxExecutionDeadlineNanos); + } JsonNode execContext = buildContext(exec, sm); // Execution-scoped JSONata variables (the Assign field). Mutated in place as states // assign, so later states observe earlier assignments. @@ -562,7 +601,7 @@ public class AslExecutor { String currentStateName = startAt; while (currentStateName != null && !abortedByCaller(exec)) { - if (System.nanoTime() >= executionDeadlineNanos) { + if (nanoTime.getAsLong() >= executionDeadlineNanos) { throw new ExecutionTimedOutException(); } JsonNode stateDef = states.path(currentStateName); @@ -575,6 +614,11 @@ public class AslExecutor { stateResult = runState(chain, currentStateName, stateDef, currentInput, sm, topLevelQueryLanguage, execContext, variables, executionDeadlineNanos); } catch (FailStateException e) { + // A failure that came back after the deadline, like a late success, ends the + // execution as timed out. + if (nanoTime.getAsLong() >= executionDeadlineNanos) { + throw new ExecutionTimedOutException(); + } failExecution(exec, chain, e); onUpdate.accept(exec, history); return; @@ -582,6 +626,11 @@ public class AslExecutor { currentInput = stateResult.output(); currentStateName = stateResult.nextState(); } + // A last state that outran the deadline, such as an integration call that does not + // watch it, ends the execution as timed out rather than succeeded. + if (nanoTime.getAsLong() >= executionDeadlineNanos) { + throw new ExecutionTimedOutException(); + } succeedExecution(exec, chain, currentInput); onUpdate.accept(exec, history); @@ -593,6 +642,12 @@ public class AslExecutor { // StopExecution already wrote ABORTED and sealed the history; the worker only stops. onUpdate.accept(exec, history); } catch (Exception e) { + if (nanoTime.getAsLong() >= executionDeadlineNanos) { + // Past the deadline the execution has timed out, whatever broke on the way there. + timeOutExecution(exec, chain); + onUpdate.accept(exec, history); + return; + } LOG.warnv("ASL execution failed for {0}: {1}", exec.getExecutionArn(), e.getMessage()); // This path previously set only the status, leaving error and cause null forever on an // execution DescribeExecution reports as FAILED. @@ -1004,22 +1059,22 @@ public class AslExecutor { long wakeAtNanos = Math.min(executionDeadlineNanos, Math.min(timeoutDeadlineNanos, heartbeatDeadlineNanos(taskToken, heartbeatSeconds))); try { - return future.get(wakeAtNanos - System.nanoTime(), TimeUnit.NANOSECONDS); + return future.get(wakeAtNanos - nanoTime.getAsLong(), TimeUnit.NANOSECONDS); } catch (java.util.concurrent.TimeoutException e) { // The execution's budget is read first: when it is the clock that ran out, the // execution ends as TIMED_OUT and the task's own timeout never applies. - if (System.nanoTime() >= executionDeadlineNanos) { + if (nanoTime.getAsLong() >= executionDeadlineNanos) { future.cancel(true); throw new ExecutionTimedOutException(); } - if (System.nanoTime() >= timeoutDeadlineNanos) { + if (nanoTime.getAsLong() >= timeoutDeadlineNanos) { future.cancel(true); throw new TaskTimedOutException("States.Timeout"); } // Read the gap again rather than trusting the one this thread parked on: a // heartbeat that landed meanwhile has already moved it past now, and the task // goes back to waiting on the later deadline. - if (System.nanoTime() >= heartbeatDeadlineNanos(taskToken, heartbeatSeconds)) { + if (nanoTime.getAsLong() >= heartbeatDeadlineNanos(taskToken, heartbeatSeconds)) { future.cancel(true); throw new TaskTimedOutException("States.HeartbeatTimeout"); } @@ -1047,7 +1102,7 @@ public class AslExecutor { if (timeoutSeconds <= 0) { timeoutSeconds = DEFAULT_TASK_TIMEOUT_SECONDS; } - return System.nanoTime() + TimeUnit.SECONDS.toNanos(timeoutSeconds); + return nanoTime.getAsLong() + TimeUnit.SECONDS.toNanos(timeoutSeconds); } /** @@ -2726,7 +2781,7 @@ public class AslExecutor { */ private void sleepOrTimeOutTask(long pauseNanos, long executionDeadlineNanos, long taskDeadlineNanos) throws InterruptedException { - long remainingNanos = Math.min(executionDeadlineNanos, taskDeadlineNanos) - System.nanoTime(); + long remainingNanos = Math.min(executionDeadlineNanos, taskDeadlineNanos) - nanoTime.getAsLong(); if (pauseNanos < remainingNanos) { sleeper.sleep(pauseNanos); return; @@ -2734,7 +2789,7 @@ public class AslExecutor { sleeper.sleep(Math.max(remainingNanos, 0)); // The execution's budget wins when it is the clock that was parked on, and also when a late // wake finds it spent: the execution ends TIMED_OUT and the Task's own timeout never applies. - if (executionDeadlineNanos <= taskDeadlineNanos || System.nanoTime() >= executionDeadlineNanos) { + if (executionDeadlineNanos <= taskDeadlineNanos || nanoTime.getAsLong() >= executionDeadlineNanos) { throw new ExecutionTimedOutException(); } throw new TaskTimedOutException("States.Timeout"); @@ -2833,7 +2888,7 @@ public class AslExecutor { int timeoutSeconds = stateDef.path("TimeoutSeconds").asInt(0); long stateDeadlineNanos = timeoutSeconds > 0 - ? System.nanoTime() + TimeUnit.SECONDS.toNanos(timeoutSeconds) + ? nanoTime.getAsLong() + TimeUnit.SECONDS.toNanos(timeoutSeconds) : Long.MAX_VALUE; // Two clocks can end this wait, and the join stops at whichever comes first: the state's // own TimeoutSeconds, and the state machine's budget for the whole execution. @@ -2845,7 +2900,7 @@ public class AslExecutor { int current = -1; try { for (int joined = 0; joined < futures.size(); joined++) { - long remainingNanos = joinDeadlineNanos - System.nanoTime(); + long remainingNanos = joinDeadlineNanos - nanoTime.getAsLong(); if (remainingNanos <= 0) { throw parallelJoinExpired(stateDeadlineNanos, timeoutSeconds); } @@ -2940,7 +2995,7 @@ public class AslExecutor { * execution and no Catch sees it. */ private RuntimeException parallelJoinExpired(long stateDeadlineNanos, int timeoutSeconds) { - if (System.nanoTime() < stateDeadlineNanos) { + if (nanoTime.getAsLong() < stateDeadlineNanos) { return new ExecutionTimedOutException(); } return new FailStateException("States.Timeout", @@ -5761,7 +5816,7 @@ public class AslExecutor { */ private void failExecution(Execution exec, HistoryChain chain, String error, String cause) { synchronized (exec) { - if (abortedByCaller(exec)) { + if (hasEnded(exec)) { return; } exec.setError(error); @@ -5800,11 +5855,15 @@ public class AslExecutor { */ private void timeOutExecution(Execution exec, HistoryChain chain) { synchronized (exec) { - if (abortedByCaller(exec)) { - return; + // A synchronous caller may have published the timeout already; the event still ends + // the history. Any other outcome already published stands. + if (!"TIMED_OUT".equals(exec.getStatus())) { + if (hasEnded(exec)) { + return; + } + exec.setStopDate(System.currentTimeMillis() / 1000.0); + exec.setStatus("TIMED_OUT"); } - exec.setStopDate(System.currentTimeMillis() / 1000.0); - exec.setStatus("TIMED_OUT"); } chain.end("ExecutionTimedOut", 0L, Map.of("error", "States.Timeout")); } @@ -5818,7 +5877,7 @@ public class AslExecutor { */ private void succeedExecution(Execution exec, HistoryChain chain, JsonNode output) { synchronized (exec) { - if (abortedByCaller(exec)) { + if (hasEnded(exec)) { return; } exec.setOutput(output.toString()); @@ -5831,9 +5890,7 @@ public class AslExecutor { /** * True once StopExecution published ABORTED on this execution. The state loop reads it between - * states and every terminal write here reads it before publishing, so the worker's own status - * loses the race against a stop that arrived while it was still stepping: what a caller has - * already read back from DescribeExecution is what stands. + * states, so the worker stops stepping once a caller has stopped it. */ private static boolean abortedByCaller(Execution exec) { synchronized (exec) { @@ -5841,6 +5898,18 @@ public class AslExecutor { } } + /** + * True once any outcome has been published on this execution: a stop from StopExecution, a + * synchronous caller answered with TIMED_OUT, or the worker's own. Every terminal write reads + * it before publishing, so the first outcome stands: what a caller has already read back from + * DescribeExecution or StartSyncExecution is never replaced. + */ + private static boolean hasEnded(Execution exec) { + synchronized (exec) { + return TERMINAL_STATUSES.contains(exec.getStatus()); + } + } + /** * The same read for a wait that has only the execution's ARN: a {@code .sync} poll loop. An * execution the store no longer holds is treated as stopped, since nothing is waiting for the diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayAndMathIntrinsicsTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayAndMathIntrinsicsTest.java index 327566336c..eab0e84cf7 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayAndMathIntrinsicsTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayAndMathIntrinsicsTest.java @@ -2,22 +2,9 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * Functionality + regression coverage for the last four JSONPath-mode intrinsic functions: @@ -50,25 +36,10 @@ class AslExecutorArrayAndMathIntrinsicsTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } private void assertIntrinsicFailure(JsonNode root, String expr) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayParamsTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayParamsTest.java index c6a8840c4b..394cd73174 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayParamsTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayParamsTest.java @@ -18,8 +18,11 @@ class AslExecutorArrayParamsTest { private final ObjectMapper mapper = new ObjectMapper(); private AslExecutor newExecutor() { - return new AslExecutor(null, null, null, null, null, null, null, null, null, - null, null, null, null, null, mapper, null, null, null, null, null); + return AslExecutorFixture.builder() + .objectMapper(mapper) + .config(null) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorBranchHistoryEventsTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorBranchHistoryEventsTest.java index 107f94e0f1..98b3d20798 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorBranchHistoryEventsTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorBranchHistoryEventsTest.java @@ -2,13 +2,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.MockedResponseStep; @@ -64,24 +57,12 @@ class AslExecutorBranchHistoryEventsTest { when(sfnService.get()).thenReturn(mock(StepFunctionsService.class)); EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); when(config.services().stepfunctions().maxWaitSeconds()).thenReturn(30); - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - sfnService, config, vertx, - mock(io.github.hectorvent.floci.core.common.CustomResourceLiveness.class)); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .sfnService(sfnService) + .config(config) + .vertx(vertx) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCatchTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCatchTest.java index e10b1256fe..f051ba1548 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCatchTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCatchTest.java @@ -2,23 +2,16 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -80,23 +73,13 @@ class AslExecutorCatchTest { return new InvokeResult(200, null, output, null, "cleanup-request"); }); - executor = new AslExecutor( - lambdaExecutor, - functionStore, - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, null); + executor = AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .functionStore(functionStore) + .objectMapper(objectMapper) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorChoiceRuntimeTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorChoiceRuntimeTest.java index eaa51554eb..a6bca8666f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorChoiceRuntimeTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorChoiceRuntimeTest.java @@ -1,22 +1,9 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,7 +11,6 @@ import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; /** * End-to-end Choice-state routing through the full {@code executeSync} loop, covering the @@ -43,25 +29,10 @@ class AslExecutorChoiceRuntimeTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } private static final String GTE_MACHINE = """ diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java index a69d0e6661..6cccf49ec9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorCustomResourceLivenessTest.java @@ -1,24 +1,17 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.CustomResourceLiveness; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -74,23 +67,13 @@ class AslExecutorCustomResourceLivenessTest { when(lambdaExecutor.invoke(eq(function), any(byte[].class), eq(InvocationType.RequestResponse))) .thenReturn(new InvokeResult(200, null, "{}".getBytes(), null, "poll-request")); - executor = new AslExecutor( - lambdaExecutor, - functionStore, - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, customResourceLiveness); + executor = AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .functionStore(functionStore) + .objectMapper(objectMapper) + .vertx(vertx) + .customResourceLiveness(customResourceLiveness) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java index caa1dc3c0c..8085bf3d3b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorEcsRunTaskModeTest.java @@ -3,18 +3,12 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; import io.github.hectorvent.floci.services.ecs.EcsService; import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy; import io.github.hectorvent.floci.services.ecs.model.Container; import io.github.hectorvent.floci.services.ecs.model.EcsTask; import io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -23,7 +17,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import java.time.Clock; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -86,29 +79,15 @@ class AslExecutorEcsRunTaskModeTest { Instance instance = mock(Instance.class); when(instance.get()).thenReturn(sfnService); - return new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(io.github.hectorvent.floci.services.s3.S3Service.class), - ecsService, - ecsJsonHandler, - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - instance, - mock(EmulatorConfig.class), - null, - null, - Clock.systemUTC(), - sleeper, - 30); + return AslExecutorFixture.builder() + .ecsService(ecsService) + .ecsJsonHandler(ecsJsonHandler) + .objectMapper(objectMapper) + .sfnService(instance) + .customResourceLiveness(null) + .sleeper(sleeper) + .maxWaitSeconds(30) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorErrorTerminationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorErrorTerminationTest.java index 73f955b822..a913eebd54 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorErrorTerminationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorErrorTerminationTest.java @@ -2,20 +2,11 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +20,6 @@ import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * Guards that an {@link Error} escaping a state ends the execution instead of leaving it RUNNING @@ -72,24 +62,11 @@ class AslExecutorErrorTerminationTest { @BeforeEach void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new CrashingJsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, - mock(io.github.hectorvent.floci.core.common.CustomResourceLiveness.class)); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .jsonataEvaluator(new CrashingJsonataEvaluator(objectMapper)) + .vertx(vertx) + .build(); } private static final String PASS_WITH_JSONATA_OUTPUT = """ diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java index cea21b4107..656c777fa8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFailStateErrorCauseTest.java @@ -1,19 +1,11 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,24 +42,11 @@ class AslExecutorFailStateErrorCauseTest { @BeforeEach void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), - mock(io.github.hectorvent.floci.services.sns.SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, null); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } /** The exact reproduction from issue #3255: both ErrorPath and CausePath resolve from input. */ diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFixture.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFixture.java new file mode 100644 index 0000000000..1d16bda46b --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorFixture.java @@ -0,0 +1,251 @@ +package io.github.hectorvent.floci.services.stepfunctions; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.config.EmulatorConfig; +import io.github.hectorvent.floci.core.common.CustomResourceLiveness; +import io.github.hectorvent.floci.core.common.ServiceRegistry; +import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; +import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; +import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; +import io.github.hectorvent.floci.services.ec2.Ec2Service; +import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; +import io.github.hectorvent.floci.services.ecs.EcsService; +import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; +import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; +import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; +import io.github.hectorvent.floci.services.lambda.LambdaTargetResolver; +import io.github.hectorvent.floci.services.rdsdata.RdsDataService; +import io.github.hectorvent.floci.services.redshiftdata.RedshiftDataJsonHandler; +import io.github.hectorvent.floci.services.s3.S3Service; +import io.github.hectorvent.floci.services.scheduler.SchedulerController; +import io.github.hectorvent.floci.services.scheduler.SchedulerService; +import io.github.hectorvent.floci.services.sns.SnsJsonHandler; +import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; +import io.vertx.mutiny.core.Vertx; +import jakarta.enterprise.inject.Instance; + +import java.time.Clock; +import java.time.Duration; +import java.util.concurrent.TimeUnit; +import java.util.function.LongSupplier; + +import static org.mockito.Mockito.mock; + +/** + * Builds {@link AslExecutor} for tests, naming only the collaborators a test uses. + * + *

Every other collaborator defaults to what the convenience constructors pass: a Mockito mock + * for each integration, the system clock, a real sleeper, {@code System.nanoTime()} for deadlines, + * no Wait cap override, AWS's 5-minute Express limit, and no RDS Data, Redshift Data, service + * registry or Lambda task authorizer. A Lambda target resolver is built over the function store + * unless a test supplies its own. + */ +final class AslExecutorFixture { + + private AslExecutorFixture() { + } + + static Builder builder() { + return new Builder(); + } + + static final class Builder { + + private LambdaExecutorService lambdaExecutor = mock(LambdaExecutorService.class); + private LambdaFunctionStore functionStore = mock(LambdaFunctionStore.class); + private LambdaTargetResolver targetResolver; + private DynamoDbFacade dynamoDb = mock(DynamoDbFacade.class); + private DynamoDbJsonHandler dynamoDbJsonHandler = mock(DynamoDbJsonHandler.class); + private SqsJsonHandler sqsJsonHandler = mock(SqsJsonHandler.class); + private SnsJsonHandler snsJsonHandler = mock(SnsJsonHandler.class); + private CloudFormationQueryHandler cloudFormationHandler = mock(CloudFormationQueryHandler.class); + private Ec2Service ec2Service = mock(Ec2Service.class); + private S3Service s3Service = mock(S3Service.class); + private EcsService ecsService = mock(EcsService.class); + private EcsJsonHandler ecsJsonHandler = mock(EcsJsonHandler.class); + private EventBridgeHandler eventBridgeHandler = mock(EventBridgeHandler.class); + private SchedulerService schedulerService = mock(SchedulerService.class); + private SchedulerController schedulerController = mock(SchedulerController.class); + private RdsDataService rdsDataService; + private ObjectMapper objectMapper = new ObjectMapper(); + private JsonataEvaluator jsonataEvaluator; + @SuppressWarnings("unchecked") + private Instance sfnService = mock(Instance.class); + private EmulatorConfig config = mock(EmulatorConfig.class); + private Vertx vertx; + private CustomResourceLiveness customResourceLiveness = mock(CustomResourceLiveness.class); + private Clock clock = Clock.systemUTC(); + private AslExecutor.Sleeper sleeper = TimeUnit.NANOSECONDS::sleep; + private Integer maxWaitSeconds; + private RedshiftDataJsonHandler redshiftDataHandler; + private ServiceRegistry serviceRegistry; + private LambdaTaskAuthorizer lambdaTaskAuthorizer; + private Duration expressMaxExecutionTime; + private LongSupplier nanoTime; + + private Builder() { + } + + Builder lambdaExecutor(LambdaExecutorService lambdaExecutor) { + this.lambdaExecutor = lambdaExecutor; + return this; + } + + Builder functionStore(LambdaFunctionStore functionStore) { + this.functionStore = functionStore; + return this; + } + + Builder targetResolver(LambdaTargetResolver targetResolver) { + this.targetResolver = targetResolver; + return this; + } + + Builder dynamoDb(DynamoDbFacade dynamoDb) { + this.dynamoDb = dynamoDb; + return this; + } + + Builder dynamoDbJsonHandler(DynamoDbJsonHandler dynamoDbJsonHandler) { + this.dynamoDbJsonHandler = dynamoDbJsonHandler; + return this; + } + + Builder sqsJsonHandler(SqsJsonHandler sqsJsonHandler) { + this.sqsJsonHandler = sqsJsonHandler; + return this; + } + + Builder snsJsonHandler(SnsJsonHandler snsJsonHandler) { + this.snsJsonHandler = snsJsonHandler; + return this; + } + + Builder cloudFormationHandler(CloudFormationQueryHandler cloudFormationHandler) { + this.cloudFormationHandler = cloudFormationHandler; + return this; + } + + Builder ec2Service(Ec2Service ec2Service) { + this.ec2Service = ec2Service; + return this; + } + + Builder s3Service(S3Service s3Service) { + this.s3Service = s3Service; + return this; + } + + Builder ecsService(EcsService ecsService) { + this.ecsService = ecsService; + return this; + } + + Builder ecsJsonHandler(EcsJsonHandler ecsJsonHandler) { + this.ecsJsonHandler = ecsJsonHandler; + return this; + } + + Builder eventBridgeHandler(EventBridgeHandler eventBridgeHandler) { + this.eventBridgeHandler = eventBridgeHandler; + return this; + } + + Builder schedulerService(SchedulerService schedulerService) { + this.schedulerService = schedulerService; + return this; + } + + Builder schedulerController(SchedulerController schedulerController) { + this.schedulerController = schedulerController; + return this; + } + + Builder rdsDataService(RdsDataService rdsDataService) { + this.rdsDataService = rdsDataService; + return this; + } + + Builder objectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + return this; + } + + Builder jsonataEvaluator(JsonataEvaluator jsonataEvaluator) { + this.jsonataEvaluator = jsonataEvaluator; + return this; + } + + Builder sfnService(Instance sfnService) { + this.sfnService = sfnService; + return this; + } + + Builder config(EmulatorConfig config) { + this.config = config; + return this; + } + + Builder vertx(Vertx vertx) { + this.vertx = vertx; + return this; + } + + Builder customResourceLiveness(CustomResourceLiveness customResourceLiveness) { + this.customResourceLiveness = customResourceLiveness; + return this; + } + + Builder clock(Clock clock) { + this.clock = clock; + return this; + } + + Builder sleeper(AslExecutor.Sleeper sleeper) { + this.sleeper = sleeper; + return this; + } + + Builder maxWaitSeconds(Integer maxWaitSeconds) { + this.maxWaitSeconds = maxWaitSeconds; + return this; + } + + Builder redshiftDataHandler(RedshiftDataJsonHandler redshiftDataHandler) { + this.redshiftDataHandler = redshiftDataHandler; + return this; + } + + Builder serviceRegistry(ServiceRegistry serviceRegistry) { + this.serviceRegistry = serviceRegistry; + return this; + } + + Builder lambdaTaskAuthorizer(LambdaTaskAuthorizer lambdaTaskAuthorizer) { + this.lambdaTaskAuthorizer = lambdaTaskAuthorizer; + return this; + } + + Builder expressMaxExecutionTime(Duration expressMaxExecutionTime) { + this.expressMaxExecutionTime = expressMaxExecutionTime; + return this; + } + + Builder nanoTime(LongSupplier nanoTime) { + this.nanoTime = nanoTime; + return this; + } + + AslExecutor build() { + return new AslExecutor(lambdaExecutor, + targetResolver != null ? targetResolver : new LambdaTargetResolver(functionStore, null), + dynamoDb, dynamoDbJsonHandler, sqsJsonHandler, snsJsonHandler, cloudFormationHandler, + ec2Service, s3Service, ecsService, ecsJsonHandler, eventBridgeHandler, + schedulerService, schedulerController, rdsDataService, objectMapper, + jsonataEvaluator != null ? jsonataEvaluator : new JsonataEvaluator(objectMapper), + sfnService, config, vertx, customResourceLiveness, clock, sleeper, maxWaitSeconds, + redshiftDataHandler, serviceRegistry, lambdaTaskAuthorizer, expressMaxExecutionTime, + nanoTime); + } + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHistoryEventLimitTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHistoryEventLimitTest.java index 349e5d2bb6..581fea106e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHistoryEventLimitTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHistoryEventLimitTest.java @@ -1,14 +1,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -187,23 +179,12 @@ class AslExecutorHistoryEventLimitTest { void setUp() { Instance sfnService = mock(Instance.class); when(sfnService.get()).thenReturn(mock(StepFunctionsService.class)); - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - sfnService, mock(EmulatorConfig.class), vertx, null); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .sfnService(sfnService) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHttpInvokeTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHttpInvokeTest.java index ac791b2de8..dfcb4ccd0f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHttpInvokeTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorHttpInvokeTest.java @@ -3,14 +3,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -25,7 +17,6 @@ import io.vertx.mutiny.core.http.HttpServer; import io.vertx.mutiny.core.http.HttpServerRequest; import io.vertx.mutiny.ext.web.Router; import io.vertx.mutiny.ext.web.RoutingContext; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -43,7 +34,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; @QuarkusTest class AslExecutorHttpInvokeTest { @@ -159,26 +149,12 @@ class AslExecutorHttpInvokeTest { .listenAndAwait(0); baseUrl = "http://127.0.0.1:" + server.actualPort(); - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(io.github.hectorvent.floci.services.s3.S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), - emulatorConfig, - vertx, - null); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .config(emulatorConfig) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } private void recordRequest(final RoutingContext ctx, String body) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicContextTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicContextTest.java index f047e33d37..2dab855458 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicContextTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicContextTest.java @@ -22,8 +22,11 @@ class AslExecutorIntrinsicContextTest { /** Only ObjectMapper is exercised by the path/intrinsic resolution methods under test. */ private AslExecutor newExecutor() { - return new AslExecutor(null, null, null, null, null, null, null, null, null, - null, null, null, null, null, mapper, null, null, null, null, null); + return AslExecutorFixture.builder() + .objectMapper(mapper) + .config(null) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicFunctionsTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicFunctionsTest.java index 366768793d..0f23f34e27 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicFunctionsTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicFunctionsTest.java @@ -3,22 +3,9 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * Functionality + regression coverage for the five JSONPath-mode intrinsic functions added @@ -53,25 +39,10 @@ class AslExecutorIntrinsicFunctionsTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } private void assertIntrinsicFailure(JsonNode root, String expr) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java index 6e315278ce..0446d712c4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java @@ -2,21 +2,12 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * A {@code $.} argument of a {@code States.*} intrinsic that matches nothing fails with @@ -33,26 +24,10 @@ class AslExecutorIntrinsicMissingArgumentTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(io.github.hectorvent.floci.services.s3.S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, - null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorJsonMergeTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorJsonMergeTest.java index 6f87c6b083..6364b28b14 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorJsonMergeTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorJsonMergeTest.java @@ -2,26 +2,12 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * Regression + functionality coverage for the {@code States.JsonMerge} intrinsic. AWS Step Functions @@ -38,26 +24,10 @@ class AslExecutorJsonMergeTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, - null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaArnTargetTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaArnTargetTest.java index 85283e2021..cdfdbc12ac 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaArnTargetTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaArnTargetTest.java @@ -3,13 +3,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; import io.github.hectorvent.floci.services.lambda.LambdaAliasStore; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; @@ -17,17 +10,11 @@ import io.github.hectorvent.floci.services.lambda.LambdaTargetResolver; import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.scheduler.SchedulerController; -import io.github.hectorvent.floci.services.scheduler.SchedulerService; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -96,24 +83,15 @@ class AslExecutorLambdaArnTargetTest { } private AslExecutor newExecutor(EmulatorConfig config, LambdaTaskAuthorizer authorizer) { - return new AslExecutor( - lambdaExecutor, - new LambdaTargetResolver(functionStore, mock(LambdaAliasStore.class)), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(EventBridgeHandler.class), - mock(SchedulerService.class), - mock(SchedulerController.class), - null, - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), config, vertx, null, null, null, authorizer); + return AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .targetResolver(new LambdaTargetResolver(functionStore, mock(LambdaAliasStore.class))) + .objectMapper(objectMapper) + .config(config) + .vertx(vertx) + .customResourceLiveness(null) + .lambdaTaskAuthorizer(authorizer) + .build(); } private static LambdaFunction function(String account, String region) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java index 17b3cbfd84..09edd13a25 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaInvokeResultTest.java @@ -2,9 +2,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.lambda.LambdaAliasStore; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; @@ -13,15 +10,11 @@ import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaAlias; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -83,24 +76,13 @@ class AslExecutorLambdaInvokeResultTest { return new InvokeResult(200, null, output, null, "echo-request"); }); - executor = new AslExecutor( - lambdaExecutor, - new LambdaTargetResolver(functionStore, aliasStore), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - null, - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, null); + executor = AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .targetResolver(new LambdaTargetResolver(functionStore, aliasStore)) + .objectMapper(objectMapper) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaThrottleTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaThrottleTest.java index e3cc15f924..7009b0801f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaThrottleTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorLambdaThrottleTest.java @@ -4,35 +4,21 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.AwsException; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; import io.github.hectorvent.floci.services.lambda.LambdaConcurrencyLimiter; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.scheduler.SchedulerController; -import io.github.hectorvent.floci.services.scheduler.SchedulerService; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import java.nio.charset.StandardCharsets; -import java.time.Clock; import java.util.ArrayList; import java.util.Optional; @@ -195,24 +181,15 @@ class AslExecutorLambdaThrottleTest { } private AslExecutor executor(AslExecutor.Sleeper sleeper) { - return new AslExecutor( - lambdaExecutor, - functionStore, - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(EventBridgeHandler.class), - mock(SchedulerService.class), - mock(SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), config, null, null, - Clock.systemUTC(), sleeper, 30); + return AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .functionStore(functionStore) + .objectMapper(objectMapper) + .config(config) + .customResourceLiveness(null) + .sleeper(sleeper) + .maxWaitSeconds(30) + .build(); } private Execution run(AslExecutor executor, String definition) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorMockedResponsesTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorMockedResponsesTest.java index 8fbfbd0caf..832adc3a38 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorMockedResponsesTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorMockedResponsesTest.java @@ -3,13 +3,7 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.MockedResponseStep; @@ -17,7 +11,6 @@ import io.github.hectorvent.floci.services.stepfunctions.model.MockedTestCase; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,23 +46,13 @@ class AslExecutorMockedResponsesTest { EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); when(config.services().stepfunctions().maxWaitSeconds()).thenReturn(30); - executor = new AslExecutor( - lambdaExecutor, - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), config, vertx, null); + executor = AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .objectMapper(objectMapper) + .config(config) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedQueryLanguageTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedQueryLanguageTest.java index 58afdb2f4f..9a080916c7 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedQueryLanguageTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedQueryLanguageTest.java @@ -2,20 +2,11 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,7 +16,6 @@ import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; /** * Pins the query language a state inside a Map's {@code ItemProcessor} runs under. @@ -57,23 +47,11 @@ class AslExecutorNestedQueryLanguageTest { @BeforeEach void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, null); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } /** diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedStartExecutionTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedStartExecutionTest.java index f8aefc36ab..2a3faa4559 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedStartExecutionTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedStartExecutionTest.java @@ -3,17 +3,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.AwsException; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -75,25 +64,12 @@ class AslExecutorNestedStartExecutionTest { EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); when(config.services().stepfunctions().maxWaitSeconds()).thenReturn(30); - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - sfnInstance, - config, - null, null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .sfnService(sfnInstance) + .config(config) + .customResourceLiveness(null) + .build(); } private Execution runParent(String parentDefinition, String input) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncFailureTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncFailureTest.java index 3b5b3b3e40..bd1b0ae37b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncFailureTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncFailureTest.java @@ -1,21 +1,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.scheduler.SchedulerController; -import io.github.hectorvent.floci.services.scheduler.SchedulerService; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -26,7 +11,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.time.Clock; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -231,29 +215,12 @@ class AslExecutorNestedSyncFailureTest { private AslExecutor newExecutor() { Instance instance = mock(Instance.class); when(instance.get()).thenReturn(sfnService); - return new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(EventBridgeHandler.class), - mock(SchedulerService.class), - mock(SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - instance, - mock(EmulatorConfig.class), - null, - null, - Clock.systemUTC(), - nanos -> { }, - null); + return AslExecutorFixture.builder() + .objectMapper(objectMapper) + .sfnService(instance) + .customResourceLiveness(null) + .sleeper(nanos -> { }) + .build(); } private Execution run(String mode, String catcher) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncTimeoutTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncTimeoutTest.java index 595c3452ac..3c17e349b7 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncTimeoutTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorNestedSyncTimeoutTest.java @@ -2,21 +2,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.scheduler.SchedulerController; -import io.github.hectorvent.floci.services.scheduler.SchedulerService; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -24,7 +9,6 @@ import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.time.Clock; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -176,29 +160,12 @@ class AslExecutorNestedSyncTimeoutTest { private AslExecutor newExecutor(AslExecutor.Sleeper sleeper) { Instance instance = mock(Instance.class); when(instance.get()).thenReturn(sfnService); - return new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(EventBridgeHandler.class), - mock(SchedulerService.class), - mock(SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - instance, - mock(EmulatorConfig.class), - null, - null, - Clock.systemUTC(), - sleeper, - null); + return AslExecutorFixture.builder() + .objectMapper(objectMapper) + .sfnService(instance) + .customResourceLiveness(null) + .sleeper(sleeper) + .build(); } private Execution run(AslExecutor executor, String mode, int timeoutSeconds, boolean catchTimeout) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java index 7da6bd24b0..6980caa809 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java @@ -1,21 +1,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.scheduler.SchedulerController; -import io.github.hectorvent.floci.services.scheduler.SchedulerService; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -24,7 +9,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -import java.time.Clock; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -414,29 +398,13 @@ class AslExecutorParallelCutTest { private AslExecutor newExecutor(AslExecutor.Sleeper sleeper) { Instance instance = mock(Instance.class); when(instance.get()).thenReturn(sfnService); - return new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(EventBridgeHandler.class), - mock(SchedulerService.class), - mock(SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - instance, - mock(EmulatorConfig.class), - null, - null, - Clock.systemUTC(), - sleeper, - 30); + return AslExecutorFixture.builder() + .objectMapper(objectMapper) + .sfnService(instance) + .customResourceLiveness(null) + .sleeper(sleeper) + .maxWaitSeconds(30) + .build(); } private Execution run(String parallelState, int waitingBranches, int executionTimeoutSeconds) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorPathIntrinsicsTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorPathIntrinsicsTest.java index 4ad4413d84..172e04e09d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorPathIntrinsicsTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorPathIntrinsicsTest.java @@ -2,14 +2,6 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -17,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * Unit coverage for the JSONPath/intrinsic features DPS's provisioning state machine relies on: @@ -32,26 +23,10 @@ class AslExecutorPathIntrinsicsTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(io.github.hectorvent.floci.services.s3.S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, - null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRedshiftDataDisabledTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRedshiftDataDisabledTest.java index 2ec5141473..c909ff764b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRedshiftDataDisabledTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRedshiftDataDisabledTest.java @@ -53,9 +53,13 @@ class AslExecutorRedshiftDataDisabledTest { RedshiftDataService service = mock(RedshiftDataService.class); when(service.listStatements(any())).thenReturn(objectMapper.createObjectNode()); RedshiftDataJsonHandler handler = spy(new RedshiftDataJsonHandler(service)); - AslExecutor executor = new AslExecutor(null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, objectMapper, - new JsonataEvaluator(objectMapper), null, config, null, null, handler, serviceRegistry, null); + AslExecutor executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .config(config) + .customResourceLiveness(null) + .redshiftDataHandler(handler) + .serviceRegistry(serviceRegistry) + .build(); StateMachine stateMachine = new StateMachine(); stateMachine.setStateMachineArn("arn:aws:states:us-east-1:000000000000:stateMachine:disabled-data"); diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultPathTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultPathTest.java index 53a67259d0..a0ee349012 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultPathTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultPathTest.java @@ -1,29 +1,15 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; /** * End-to-end coverage for the ResultPath fix: a non-applicable ResultPath fails the execution with @@ -43,16 +29,10 @@ class AslExecutorResultPathTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), mock(DynamoDbJsonHandler.class), mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), mock(Ec2Service.class), mock(S3Service.class), - mock(EcsService.class), mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, new JsonataEvaluator(mapper), - mock(Instance.class), mock(EmulatorConfig.class), null, null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } private Execution run(String definition, String input) { diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java index 78cd0f70eb..3dde53413f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorResultWriterTest.java @@ -6,13 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.AwsException; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; @@ -61,26 +55,13 @@ class AslExecutorResultWriterTest { when(sfnService.get()).thenReturn(mock(StepFunctionsService.class)); EmulatorConfig config = mock(EmulatorConfig.class); when(config.defaultRegion()).thenReturn("us-east-1"); - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - s3Service, - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - sfnService, - config, - null, - null); + executor = AslExecutorFixture.builder() + .s3Service(s3Service) + .objectMapper(mapper) + .sfnService(sfnService) + .config(config) + .customResourceLiveness(null) + .build(); sm = new StateMachine(); sm.setStateMachineArn("arn:aws:states:us-east-1:000000000000:stateMachine:orderProcessing"); diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRetryTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRetryTest.java index f939bbf2dd..7c9217f7be 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRetryTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorRetryTest.java @@ -2,22 +2,16 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -74,23 +68,14 @@ class AslExecutorRetryTest { when(servicesConfig.stepfunctions()).thenReturn(stepFunctionsConfig); when(stepFunctionsConfig.maxWaitSeconds()).thenReturn(30); - executor = new AslExecutor( - lambdaExecutor, - functionStore, - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), config, vertx, null); + executor = AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .functionStore(functionStore) + .objectMapper(objectMapper) + .config(config) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorStatePathTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorStatePathTest.java index 4a2d1342ce..bc9ca4f482 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorStatePathTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorStatePathTest.java @@ -1,23 +1,9 @@ package io.github.hectorvent.floci.services.stepfunctions; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,7 +12,6 @@ import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; class AslExecutorStatePathTest { @@ -36,25 +21,10 @@ class AslExecutorStatePathTest { @BeforeEach @SuppressWarnings("unchecked") void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - mapper, - new JsonataEvaluator(mapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, null); + executor = AslExecutorFixture.builder() + .objectMapper(mapper) + .customResourceLiveness(null) + .build(); } @AfterEach diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorSyncTimeoutTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorSyncTimeoutTest.java new file mode 100644 index 0000000000..b0a5b94155 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorSyncTimeoutTest.java @@ -0,0 +1,247 @@ +package io.github.hectorvent.floci.services.stepfunctions; + +import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; +import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; +import io.github.hectorvent.floci.services.lambda.model.InvocationType; +import io.github.hectorvent.floci.services.lambda.model.InvokeResult; +import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; +import io.github.hectorvent.floci.services.stepfunctions.model.Execution; +import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; +import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; +import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; + +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * An Express execution, synchronous or not, is one AWS ends with States.Timeout once it has run for + * its maximum execution time. Once it has timed out it runs no further state, and the first + * outcome published, the timeout or one the execution reached in time, is the one that stands. + * + *

Every case runs on a test clock that Wait states and slow integrations move forward, so none + * takes real time. What the synchronous caller does once its own wait runs out is exercised by + * calling that step directly. + */ +class AslExecutorSyncTimeoutTest { + + private static final Duration MAX_EXECUTION_TIME = Duration.ofSeconds(1); + private static final String FUNCTION_ARN = "arn:aws:lambda:us-east-1:000000000000:function:slow"; + private static final Set TERMINAL_EVENTS = + Set.of("ExecutionSucceeded", "ExecutionFailed", "ExecutionTimedOut", "ExecutionAborted"); + private static final String WAIT_THEN_PASS = """ + {"StartAt":"Pause","States":{ + "Pause":{"Type":"Wait","Seconds":2,"Next":"After"}, + "After":{"Type":"Pass","End":true}}} + """; + + private final LambdaExecutorService lambdaExecutor = mock(LambdaExecutorService.class); + private final LambdaFunctionStore functionStore = mock(LambdaFunctionStore.class); + private final AtomicLong testNanos = new AtomicLong(); + private final AslExecutor executor = AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .functionStore(functionStore) + .maxWaitSeconds(30) + .expressMaxExecutionTime(MAX_EXECUTION_TIME) + .nanoTime(testNanos::get) + .sleeper(testNanos::addAndGet) + .build(); + private final List history = new CopyOnWriteArrayList<>(); + + @Test + void executionPastItsMaximumTimeRunsNoFurtherStateAndStaysTimedOut() { + StateMachine stateMachine = stateMachine(WAIT_THEN_PASS); + Execution execution = execution(stateMachine); + + executor.executeSync(stateMachine, execution, history, (updated, events) -> { + }); + + assertEndedTimedOut(execution); + assertFalse(history.stream().anyMatch(event -> "PassStateEntered".equals(event.getType())), + "the state after the timeout ran"); + } + + @Test + void lastStateFinishingPastTheMaximumTimeStillEndsTimedOut() { + lambdaAnswers(invocation -> { + advance(Duration.ofSeconds(2)); + return new InvokeResult(200, null, bytes("{}"), null, "late-success"); + }); + StateMachine stateMachine = stateMachine(lambdaTask()); + Execution execution = execution(stateMachine); + + executor.executeSync(stateMachine, execution, history, (updated, events) -> { + }); + + assertEndedTimedOut(execution); + } + + @Test + void lastStateFailingPastTheMaximumTimeStillEndsTimedOut() { + lambdaAnswers(invocation -> { + advance(Duration.ofSeconds(2)); + return new InvokeResult(200, "Unhandled", + bytes("{\"errorType\":\"Boom\",\"errorMessage\":\"late\"}"), null, "late-failure"); + }); + StateMachine stateMachine = stateMachine(lambdaTask()); + Execution execution = execution(stateMachine); + + executor.executeSync(stateMachine, execution, history, (updated, events) -> { + }); + + assertEndedTimedOut(execution); + } + + @Test + void lastStateThrowingPastTheMaximumTimeStillEndsTimedOut() { + lambdaAnswers(invocation -> { + advance(Duration.ofSeconds(2)); + throw new IllegalStateException("runtime broke after the deadline"); + }); + StateMachine stateMachine = stateMachine(lambdaTask()); + Execution execution = execution(stateMachine); + + executor.executeSync(stateMachine, execution, history, (updated, events) -> { + }); + + assertEndedTimedOut(execution); + } + + @Test + void expressExecutionStartedAsynchronouslyEndsAtItsMaximumTime() { + StateMachine stateMachine = stateMachine(WAIT_THEN_PASS); + stateMachine.setType("EXPRESS"); + Execution execution = execution(stateMachine); + + executor.executeAsync(stateMachine, execution, history, (updated, events) -> { + }); + + awaitTerminalEvent(); + assertEndedTimedOut(execution); + assertFalse(history.stream().anyMatch(event -> "PassStateEntered".equals(event.getType())), + "the state after the timeout ran"); + } + + @Test + void standardExecutionStartedAsynchronouslyHasNoSuchLimit() { + StateMachine stateMachine = stateMachine(WAIT_THEN_PASS); + stateMachine.setType("STANDARD"); + Execution execution = execution(stateMachine); + + executor.executeAsync(stateMachine, execution, history, (updated, events) -> { + }); + + awaitTerminalEvent(); + assertEquals("SUCCEEDED", execution.getStatus()); + } + + @Test + void callerTimeoutLeavesAnExecutionThatAlreadyEndedAsItWas() { + Execution execution = execution(stateMachine(WAIT_THEN_PASS)); + execution.setStatus("SUCCEEDED"); + AtomicInteger updates = new AtomicInteger(); + + executor.answerTimedOutUnlessEnded(execution, history, (updated, events) -> updates.incrementAndGet()); + + assertEquals("SUCCEEDED", execution.getStatus()); + assertEquals(0, updates.get()); + } + + @Test + void callerTimeoutEndsAStillRunningExecutionTimedOut() { + Execution execution = execution(stateMachine(WAIT_THEN_PASS)); + AtomicInteger updates = new AtomicInteger(); + + executor.answerTimedOutUnlessEnded(execution, history, (updated, events) -> updates.incrementAndGet()); + + assertEquals("TIMED_OUT", execution.getStatus()); + assertNotNull(execution.getStopDate()); + assertEquals(1, updates.get()); + } + + @Test + void lateOutcomeAfterTheCallerWasAnsweredKeepsTheTimeout() { + lambdaAnswers(invocation -> { + advance(Duration.ofSeconds(2)); + return new InvokeResult(200, null, bytes("{}"), null, "late-success"); + }); + StateMachine stateMachine = stateMachine(lambdaTask()); + Execution execution = execution(stateMachine); + + // The caller's wait ran out first; the worker's late outcome arrives after it. + executor.answerTimedOutUnlessEnded(execution, history, (updated, events) -> { + }); + executor.executeSync(stateMachine, execution, history, (updated, events) -> { + }); + + assertEndedTimedOut(execution); + } + + private void advance(Duration duration) { + testNanos.addAndGet(duration.toNanos()); + } + + private void lambdaAnswers(Answer answer) { + LambdaFunction function = new LambdaFunction(); + function.setFunctionName("slow"); + function.setFunctionArn(FUNCTION_ARN); + when(functionStore.get("us-east-1", "slow")).thenReturn(Optional.of(function)); + when(lambdaExecutor.invoke(eq(function), any(byte[].class), eq(InvocationType.RequestResponse))) + .thenAnswer(answer); + } + + private void awaitTerminalEvent() { + await().atMost(Duration.ofSeconds(10)) + .until(() -> history.stream().anyMatch(event -> TERMINAL_EVENTS.contains(event.getType()))); + } + + private void assertEndedTimedOut(Execution execution) { + assertEquals("TIMED_OUT", execution.getStatus()); + assertEquals("ExecutionTimedOut", history.getLast().getType()); + } + + private static String lambdaTask() { + return """ + {"StartAt":"Slow","States":{"Slow":{"Type":"Task","Resource":"%s","End":true}}} + """.formatted(FUNCTION_ARN); + } + + private static byte[] bytes(String text) { + return text.getBytes(StandardCharsets.UTF_8); + } + + private static StateMachine stateMachine(String definition) { + StateMachine stateMachine = new StateMachine(); + stateMachine.setName("sync-timeout-test"); + stateMachine.setStateMachineArn( + "arn:aws:states:us-east-1:000000000000:stateMachine:sync-timeout-test"); + stateMachine.setDefinition(definition); + return stateMachine; + } + + private static Execution execution(StateMachine stateMachine) { + Execution execution = new Execution(); + execution.setName("sync-timeout-exec"); + execution.setExecutionArn( + "arn:aws:states:us-east-1:000000000000:execution:sync-timeout-test:sync-timeout-exec"); + execution.setStateMachineArn(stateMachine.getStateMachineArn()); + execution.setInput("{}"); + execution.setStatus("RUNNING"); + return execution; + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTaskHistoryEventsTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTaskHistoryEventsTest.java index d6cef26f26..311f3840ae 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTaskHistoryEventsTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTaskHistoryEventsTest.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend; import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend.Invocation; import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; @@ -13,9 +12,6 @@ import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; import io.github.hectorvent.floci.services.lambda.model.InvocationType; import io.github.hectorvent.floci.services.lambda.model.InvokeResult; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.MockedResponseStep; @@ -23,7 +19,6 @@ import io.github.hectorvent.floci.services.stepfunctions.model.MockedTestCase; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -77,24 +72,14 @@ class AslExecutorTaskHistoryEventsTest { EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); when(config.services().stepfunctions().maxWaitSeconds()).thenReturn(30); - return new AslExecutor( - lambdaExecutor, - functionStore, - dynamoDb, - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), config, vertx, - mock(io.github.hectorvent.floci.core.common.CustomResourceLiveness.class)); + return AslExecutorFixture.builder() + .lambdaExecutor(lambdaExecutor) + .functionStore(functionStore) + .dynamoDb(dynamoDb) + .objectMapper(objectMapper) + .config(config) + .vertx(vertx) + .build(); } /** diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTerminalStateTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTerminalStateTest.java index 77d8d7c8c9..1ce0575c15 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTerminalStateTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorTerminalStateTest.java @@ -1,20 +1,11 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; import io.quarkus.test.junit.QuarkusTest; import io.vertx.mutiny.core.Vertx; -import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,7 +15,6 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.mock; /** * Guards the terminal metadata written on the outer catch in {@code doExecute}, the path that @@ -50,23 +40,11 @@ class AslExecutorTerminalStateTest { @BeforeEach void setUp() { - executor = new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), mock(SnsJsonHandler.class), - mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class), - mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class), - mock(S3Service.class), - mock(io.github.hectorvent.floci.services.ecs.EcsService.class), - mock(io.github.hectorvent.floci.services.ecs.EcsJsonHandler.class), - mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerService.class), - mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), mock(EmulatorConfig.class), vertx, null); + executor = AslExecutorFixture.builder() + .objectMapper(objectMapper) + .vertx(vertx) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorUnresolvableJsonPathTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorUnresolvableJsonPathTest.java index 186d237178..13e80e41a9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorUnresolvableJsonPathTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorUnresolvableJsonPathTest.java @@ -22,8 +22,11 @@ class AslExecutorUnresolvableJsonPathTest { private final ObjectMapper mapper = new ObjectMapper(); private AslExecutor newExecutor() { - return new AslExecutor(null, null, null, null, null, null, null, null, null, - null, null, null, null, null, mapper, null, null, null, null, null); + return AslExecutorFixture.builder() + .objectMapper(mapper) + .config(null) + .customResourceLiveness(null) + .build(); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorWaitStateTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorWaitStateTest.java index ade2131e37..60f733a90c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorWaitStateTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorWaitStateTest.java @@ -1,26 +1,9 @@ package io.github.hectorvent.floci.services.stepfunctions; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.hectorvent.floci.config.EmulatorConfig; -import io.github.hectorvent.floci.core.common.CustomResourceLiveness; -import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade; -import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; -import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.services.ecs.EcsJsonHandler; -import io.github.hectorvent.floci.services.ecs.EcsService; -import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler; -import io.github.hectorvent.floci.services.lambda.LambdaExecutorService; -import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore; -import io.github.hectorvent.floci.services.s3.S3Service; -import io.github.hectorvent.floci.services.scheduler.SchedulerController; -import io.github.hectorvent.floci.services.scheduler.SchedulerService; -import io.github.hectorvent.floci.services.sns.SnsJsonHandler; -import io.github.hectorvent.floci.services.sqs.SqsJsonHandler; import io.github.hectorvent.floci.services.stepfunctions.model.Execution; import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent; import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine; -import jakarta.enterprise.inject.Instance; import org.junit.jupiter.api.Test; import java.time.Clock; @@ -32,7 +15,6 @@ import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; /** * Wait states must honor {@code Seconds}, {@code SecondsPath}, {@code Timestamp}, and @@ -197,30 +179,12 @@ class AslExecutorWaitStateTest { private static AslExecutor newExecutor(RecordingSleeper sleeper, int maxWaitSeconds) { ObjectMapper objectMapper = new ObjectMapper(); - return new AslExecutor( - mock(LambdaExecutorService.class), - mock(LambdaFunctionStore.class), - mock(DynamoDbFacade.class), - mock(DynamoDbJsonHandler.class), - mock(SqsJsonHandler.class), - mock(SnsJsonHandler.class), - mock(CloudFormationQueryHandler.class), - mock(Ec2Service.class), - mock(S3Service.class), - mock(EcsService.class), - mock(EcsJsonHandler.class), - mock(EventBridgeHandler.class), - mock(SchedulerService.class), - mock(SchedulerController.class), - objectMapper, - new JsonataEvaluator(objectMapper), - mock(Instance.class), - mock(EmulatorConfig.class), - null, - mock(CustomResourceLiveness.class), - Clock.fixed(NOW, ZoneOffset.UTC), - sleeper, - maxWaitSeconds); + return AslExecutorFixture.builder() + .objectMapper(objectMapper) + .clock(Clock.fixed(NOW, ZoneOffset.UTC)) + .sleeper(sleeper) + .maxWaitSeconds(maxWaitSeconds) + .build(); } private static Execution run(AslExecutor executor, String definition, String input) {