mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(sfn): publish history events for Parallel branches and Map iterations (#3167)
* feat(sfn): publish Parallel branch and Map iteration history events The states inside a Parallel branch or an inline Map iteration now publish their events into the execution history. The cause of a failure the interpreter raises now carries the AWS prefix "An error occurred while executing the state '<name>' (entered at the event id #<n>). ". It is written once, at the innermost state. Every shape was verified against real Step Functions in us-east-1. * feat(sfn): record EvaluationFailed for JSONata failures A JSONata expression that fails now leaves the EvaluationFailed event AWS records, with error, the attributed cause, location and state. The location names the field the way the cause does. The event is recorded once per attempt when the state retries, and before the Failed event and the Catch. A Catch clause whose own expression fails records it from where the state stood before its first Failed event, then fails the state again. Verified against real Step Functions in us-east-1 * fix(sfn): record every Distributed Map run so DescribeMapRun resolves its ARN * fix(sfn): stop counting history events once the execution has ended
This commit is contained in:
1 parent
5eacd01636
commit
fd21ac9a6d
19 files changed
+1726
-333
No files matched your search
+143
@@ -126,6 +126,149 @@ class StepFunctionsExecutionHistoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #2868: the states inside a Parallel branch and an inline Map iteration publish into the
|
||||
* execution's history, chained through previousEventId to the Started event that opened them.
|
||||
* The SDK reads each event's details under the field named for its type, which is what this
|
||||
* test pins. Shapes verified against real AWS in us-east-1.
|
||||
*/
|
||||
@Test
|
||||
void parallelBranchesAndMapIterationsPublishTheirEvents() throws Exception {
|
||||
var smDef = """
|
||||
{
|
||||
"StartAt": "P",
|
||||
"States": {
|
||||
"P": {
|
||||
"Type": "Parallel",
|
||||
"Branches": [
|
||||
{"StartAt": "A1", "States": {"A1": {"Type": "Pass", "End": true}}}
|
||||
],
|
||||
"Next": "M"
|
||||
},
|
||||
"M": {
|
||||
"Type": "Map",
|
||||
"ItemsPath": "$[0].items",
|
||||
"MaxConcurrency": 1,
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {"Mode": "INLINE"},
|
||||
"StartAt": "I1",
|
||||
"States": {"I1": {"Type": "Pass", "End": true}}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
var smArn = sfn.createStateMachine(b -> b
|
||||
.name(TestFixtures.uniqueName("sfn-history-branches-sm"))
|
||||
.definition(smDef)
|
||||
.roleArn(ROLE_ARN)).stateMachineArn();
|
||||
|
||||
try {
|
||||
var execArn = sfn.startExecution(b -> b
|
||||
.stateMachineArn(smArn)
|
||||
.input("{\"items\": [1, 2]}")).executionArn();
|
||||
|
||||
var execution = pollUntilDone(execArn);
|
||||
assertThat(execution.status()).isEqualTo(ExecutionStatus.SUCCEEDED);
|
||||
|
||||
var events = sfn.getExecutionHistory(b -> b
|
||||
.executionArn(execArn)
|
||||
.includeExecutionData(true)).events();
|
||||
|
||||
var types = events.stream().map(HistoryEvent::type).toList();
|
||||
assertThat(types).containsExactly(
|
||||
HistoryEventType.EXECUTION_STARTED,
|
||||
HistoryEventType.PARALLEL_STATE_ENTERED,
|
||||
HistoryEventType.PARALLEL_STATE_STARTED,
|
||||
HistoryEventType.PASS_STATE_ENTERED,
|
||||
HistoryEventType.PASS_STATE_EXITED,
|
||||
HistoryEventType.PARALLEL_STATE_SUCCEEDED,
|
||||
HistoryEventType.PARALLEL_STATE_EXITED,
|
||||
HistoryEventType.MAP_STATE_ENTERED,
|
||||
HistoryEventType.MAP_STATE_STARTED,
|
||||
HistoryEventType.MAP_ITERATION_STARTED,
|
||||
HistoryEventType.PASS_STATE_ENTERED,
|
||||
HistoryEventType.PASS_STATE_EXITED,
|
||||
HistoryEventType.MAP_ITERATION_SUCCEEDED,
|
||||
HistoryEventType.MAP_ITERATION_STARTED,
|
||||
HistoryEventType.PASS_STATE_ENTERED,
|
||||
HistoryEventType.PASS_STATE_EXITED,
|
||||
HistoryEventType.MAP_ITERATION_SUCCEEDED,
|
||||
HistoryEventType.MAP_STATE_SUCCEEDED,
|
||||
HistoryEventType.MAP_STATE_EXITED,
|
||||
HistoryEventType.EXECUTION_SUCCEEDED);
|
||||
|
||||
var expectedPreviousEventIds = List.of(0L, 0L, 2L, 3L, 4L, 5L, 5L, 7L, 8L, 9L, 10L, 11L, 12L,
|
||||
9L, 14L, 15L, 16L, 17L, 17L, 19L);
|
||||
for (var i = 0; i < events.size(); i++) {
|
||||
var event = events.get(i);
|
||||
assertThat(event.id()).isEqualTo(i + 1L);
|
||||
assertThat(event.previousEventId()).as("previousEventId of event %d", i + 1)
|
||||
.isEqualTo(expectedPreviousEventIds.get(i));
|
||||
}
|
||||
|
||||
assertThat(events.get(8).mapStateStartedEventDetails().length()).isEqualTo(2);
|
||||
assertThat(events.get(9).mapIterationStartedEventDetails().name()).isEqualTo("M");
|
||||
assertThat(events.get(9).mapIterationStartedEventDetails().index()).isEqualTo(0);
|
||||
assertThat(events.get(16).mapIterationSucceededEventDetails().name()).isEqualTo("M");
|
||||
assertThat(events.get(16).mapIterationSucceededEventDetails().index()).isEqualTo(1);
|
||||
assertThat(events.get(18).stateExitedEventDetails().output()).isEqualTo("[1,2]");
|
||||
} finally {
|
||||
try { sfn.deleteStateMachine(b -> b.stateMachineArn(smArn)); } catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
/** Issue #2868: the cause of a failure inside a branch names the branch state, as on AWS. */
|
||||
@Test
|
||||
void failureInsideABranchNamesTheBranchStateInItsCause() throws Exception {
|
||||
var smDef = """
|
||||
{
|
||||
"StartAt": "P",
|
||||
"States": {
|
||||
"P": {
|
||||
"Type": "Parallel",
|
||||
"Branches": [
|
||||
{"StartAt": "Fast", "States": {"Fast": {"Type": "Pass", "Parameters": {"m.$": "$.nope"}, "End": true}}}
|
||||
],
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
var smArn = sfn.createStateMachine(b -> b
|
||||
.name(TestFixtures.uniqueName("sfn-history-branch-failure-sm"))
|
||||
.definition(smDef)
|
||||
.roleArn(ROLE_ARN)).stateMachineArn();
|
||||
|
||||
try {
|
||||
var execArn = sfn.startExecution(b -> b
|
||||
.stateMachineArn(smArn)
|
||||
.input("{\"x\":\"a\"}")).executionArn();
|
||||
|
||||
var execution = pollUntilDone(execArn);
|
||||
assertThat(execution.status()).isEqualTo(ExecutionStatus.FAILED);
|
||||
assertThat(execution.error()).isEqualTo("States.Runtime");
|
||||
assertThat(execution.cause()).isEqualTo(
|
||||
"An error occurred while executing the state 'Fast' (entered at the event id #4). "
|
||||
+ "The JSONPath '$.nope' specified for the field 'm.$' could not be found in the input '{\"x\":\"a\"}'");
|
||||
|
||||
var events = sfn.getExecutionHistory(b -> b.executionArn(execArn)).events();
|
||||
assertThat(events.stream().map(HistoryEvent::type).toList()).containsExactly(
|
||||
HistoryEventType.EXECUTION_STARTED,
|
||||
HistoryEventType.PARALLEL_STATE_ENTERED,
|
||||
HistoryEventType.PARALLEL_STATE_STARTED,
|
||||
HistoryEventType.PASS_STATE_ENTERED,
|
||||
HistoryEventType.EXECUTION_FAILED);
|
||||
assertThat(events.get(3).stateEnteredEventDetails().name()).isEqualTo("Fast");
|
||||
assertThat(events.get(4).executionFailedEventDetails().cause()).isEqualTo(execution.cause());
|
||||
} finally {
|
||||
try { sfn.deleteStateMachine(b -> b.stateMachineArn(smArn)); } catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
private DescribeExecutionResponse pollUntilDone(String execArn) throws InterruptedException {
|
||||
for (var i = 0; i < 120; i++) {
|
||||
var resp = sfn.describeExecution(b -> b.executionArn(execArn));
|
||||
|
||||
@@ -62,9 +62,34 @@ A `Retry` re-entry emits its own Scheduled, Started, and Failed triple for each
|
||||
mocked Task (`SFN_MOCK_CONFIG`) emits the same events as a real one, because Step Functions
|
||||
Local does the same.
|
||||
|
||||
Every event's `previousEventId` points to the id of the event right before it. The one
|
||||
exception is the first state's `*StateEntered` event. Its `previousEventId` is `0`. That
|
||||
matches `ExecutionStarted`, which is always `id: 1, previousEventId: 0`.
|
||||
Every event's `previousEventId` points to the id of the event right before it on the same
|
||||
chain of states. The one exception is the first state's `*StateEntered` event. Its
|
||||
`previousEventId` is `0`. That matches `ExecutionStarted`, which is always
|
||||
`id: 1, previousEventId: 0`.
|
||||
|
||||
### Parallel branches and Map iterations
|
||||
|
||||
The states inside a `Parallel` branch or an inline `Map` iteration publish their events into
|
||||
the parent execution's history, as on AWS. A `Parallel` records `ParallelStateStarted`,
|
||||
`ParallelStateSucceeded` and `ParallelStateFailed`. An inline `Map` records `MapStateStarted`,
|
||||
`MapIterationStarted`, `MapIterationSucceeded`, `MapIterationFailed`, `MapStateSucceeded` and
|
||||
`MapStateFailed`. A Distributed `Map` records `MapRunStarted`, `MapRunSucceeded` and
|
||||
`MapRunFailed` instead. Its items are child executions and publish nothing into the parent
|
||||
history. A `Task` whose failure ends its branch also records `TaskStateAborted`.
|
||||
|
||||
Branches and iterations run concurrently, so the order in which their events interleave differs
|
||||
from run to run. Each branch chains its own events through `previousEventId`, and that chain is
|
||||
the same every time.
|
||||
|
||||
### The cause of a failure
|
||||
|
||||
The `cause` of a failure the interpreter raises starts with
|
||||
`An error occurred while executing the state '<name>' (entered at the event id #<n>). `, as on
|
||||
AWS. The prefix is added once, at the innermost state. A `Fail` state's `Cause` and a cause a
|
||||
task's resource answered with pass through unchanged. A `Choice` that matches no rule and has
|
||||
no `Default`, and a payload template path that matches nothing, fail with `States.Runtime`.
|
||||
A JSONata expression that fails also records an `EvaluationFailed` event with `error`, `cause`,
|
||||
`location` and `state`, once per attempt.
|
||||
|
||||
`inputDetails` appears on `ExecutionStarted`, on `stateEnteredEventDetails`, and on
|
||||
`LambdaFunctionScheduled`/`ActivityScheduled`. `outputDetails` appears on
|
||||
@@ -76,9 +101,12 @@ When the request sets `includeExecutionData` to false, the details objects stay
|
||||
`taskScheduledEventDetails.parameters`. This matches AWS.
|
||||
|
||||
A few gaps remain. `TaskStarted`, `LambdaFunctionStarted`, and `ActivityStarted` fire at
|
||||
scheduling time, not when a worker actually picks up the task. Events inside a `Parallel` or
|
||||
`Map` branch are not recorded in the parent execution's history. `TaskSubmitted`, which real
|
||||
AWS emits for `.sync` and `.waitForTaskToken` integrations, is not emitted yet.
|
||||
scheduling time, not when a worker actually picks up the task. `TaskSubmitted`, which real
|
||||
AWS emits for `.sync` and `.waitForTaskToken` integrations, is not emitted yet. When a
|
||||
branch fails, AWS records `*StateAborted` and `MapIterationAborted` events for the states its
|
||||
sibling branches were in; Floci cancels the siblings without recording them. A Distributed
|
||||
`Map` whose item fails reports the item's own error rather than AWS's
|
||||
`States.ExceedToleratedFailureThreshold`, and emits `MapRunFailed` with that error.
|
||||
|
||||
## Map concurrency
|
||||
|
||||
@@ -187,9 +215,8 @@ index: `Output`, `Output/a/b[0]`, `Assign/x`, `Arguments/MessageGroupId`, `Choic
|
||||
`Choices[1]/Output/v`, `Choices[0]/Assign/x`, `Catch[1]/Output/v`. A `Choice` stops at the first rule
|
||||
that matches, so an undefined condition in a later rule is never evaluated.
|
||||
|
||||
One deviation. AWS prefixes the cause of a real execution with
|
||||
`An error occurred while executing the state '<name>' (entered at the event id #<n>).`; Floci
|
||||
returns the cause without it, which is the form AWS's own `TestState` returns.
|
||||
The cause of a real execution carries the state prefix described under
|
||||
[The cause of a failure](#the-cause-of-a-failure).
|
||||
|
||||
## JSONata functions
|
||||
|
||||
|
||||
+354
-262
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,169 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* One {@code previousEventId} chain of an execution's history: the top-level state loop, a Parallel
|
||||
* branch, or a Map iteration. All chains share the execution's history and event limit.
|
||||
*/
|
||||
final class HistoryChain {
|
||||
|
||||
private final List<HistoryEvent> history;
|
||||
private final AtomicLong producedEventCount;
|
||||
private final AtomicBoolean ended;
|
||||
private final HistoryChain parent;
|
||||
private volatile boolean abandoned;
|
||||
private long lastEventId;
|
||||
private long tailEventId;
|
||||
|
||||
private HistoryChain(List<HistoryEvent> history, AtomicLong producedEventCount, AtomicBoolean ended,
|
||||
HistoryChain parent, long lastEventId) {
|
||||
this.history = history;
|
||||
this.producedEventCount = producedEventCount;
|
||||
this.ended = ended;
|
||||
this.parent = parent;
|
||||
this.lastEventId = lastEventId;
|
||||
this.tailEventId = lastEventId;
|
||||
}
|
||||
|
||||
/** Starts at 0, not at ExecutionStarted. AWS leaves the first state's Entered event unchained. */
|
||||
static HistoryChain of(List<HistoryEvent> history) {
|
||||
return new HistoryChain(history, new AtomicLong(history.size()), new AtomicBoolean(), null, 0L);
|
||||
}
|
||||
|
||||
/** A Distributed Map item is a child execution. Its events are counted, not kept. */
|
||||
static HistoryChain ofChildExecution() {
|
||||
return new HistoryChain(new CountOnlyHistory(), new AtomicLong(), new AtomicBoolean(), null, 0L);
|
||||
}
|
||||
|
||||
HistoryChain fork() {
|
||||
return new HistoryChain(history, producedEventCount, ended, this, lastEventId);
|
||||
}
|
||||
|
||||
boolean isBranch() {
|
||||
return parent != null;
|
||||
}
|
||||
|
||||
long lastEventId() {
|
||||
return lastEventId;
|
||||
}
|
||||
|
||||
void continueFrom(long eventId) {
|
||||
lastEventId = eventId;
|
||||
tailEventId = eventId;
|
||||
}
|
||||
|
||||
void continueAfter(Collection<HistoryChain> chains) {
|
||||
var last = lastEventId;
|
||||
for (HistoryChain chain : chains) {
|
||||
last = Math.max(last, chain.lastEventId);
|
||||
}
|
||||
continueFrom(last);
|
||||
}
|
||||
|
||||
/** AWS records nothing of a branch it cut. */
|
||||
void abandon() {
|
||||
abandoned = true;
|
||||
}
|
||||
|
||||
private boolean isAbandoned() {
|
||||
for (var chain = this; chain != null; chain = chain.parent) {
|
||||
if (chain.abandoned) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns the event id, or 0 once the execution has ended. */
|
||||
long publish(String type, Map<String, Object> details) {
|
||||
if (isAbandoned()) {
|
||||
return 0L;
|
||||
}
|
||||
long id = append(type, lastEventId, details, true);
|
||||
if (id > 0) {
|
||||
lastEventId = id;
|
||||
tailEventId = id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event does not become the chain's tail. AWS records {@code *StateSucceeded},
|
||||
* {@code MapRunSucceeded}, {@code MapIterationFailed} and {@code TaskStateAborted} this way.
|
||||
*/
|
||||
void publishAside(String type, Map<String, Object> details) {
|
||||
if (isAbandoned()) {
|
||||
return;
|
||||
}
|
||||
long id = append(type, tailEventId, details, true);
|
||||
if (id > 0) {
|
||||
tailEventId = id;
|
||||
}
|
||||
}
|
||||
|
||||
/** The terminal event does not count towards the limit, and nothing is recorded after it. */
|
||||
void end(String type, Map<String, Object> details) {
|
||||
end(type, tailEventId, details);
|
||||
}
|
||||
|
||||
/** ExecutionTimedOut points at 0. */
|
||||
void end(String type, long previousEventId, Map<String, Object> details) {
|
||||
synchronized (history) {
|
||||
append(type, previousEventId, details, false);
|
||||
ended.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized on the history because StopExecution appends the terminal event from another
|
||||
* thread. An event counts towards the limit only once the history is known to take it.
|
||||
*/
|
||||
private long append(String type, long previousEventId, Map<String, Object> details, boolean counted) {
|
||||
synchronized (history) {
|
||||
if (ended.get()) {
|
||||
return 0L;
|
||||
}
|
||||
if (counted) {
|
||||
AslExecutor.countTowardsHistoryEventLimit(producedEventCount);
|
||||
}
|
||||
var event = new HistoryEvent();
|
||||
event.setId(history.size() + 1L);
|
||||
event.setPreviousEventId(previousEventId);
|
||||
event.setType(type);
|
||||
event.setDetails(details);
|
||||
if (!history.add(event)) {
|
||||
ended.set(true);
|
||||
return 0L;
|
||||
}
|
||||
return event.getId();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CountOnlyHistory extends AbstractList<HistoryEvent> {
|
||||
private int size;
|
||||
|
||||
@Override
|
||||
public boolean add(HistoryEvent event) {
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryEvent get(int index) {
|
||||
throw new IndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -477,12 +477,13 @@ public class JsonataEvaluator {
|
||||
} catch (QueryEvaluationFailure failure) {
|
||||
throw new FailStateException(failure.error,
|
||||
"The JSONata expression '" + expr + "' specified for the field '" + field
|
||||
+ "' threw an error during evaluation" + failure.sentenceSeparator + failure.cause);
|
||||
+ "' threw an error during evaluation" + failure.sentenceSeparator + failure.cause,
|
||||
field);
|
||||
}
|
||||
if (value.isMissingNode()) {
|
||||
throw new FailStateException("States.QueryEvaluationError",
|
||||
"The JSONata expression '" + expr + "' specified for the field '" + field
|
||||
+ "' returned nothing (undefined).");
|
||||
+ "' returned nothing (undefined).", field);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
+21
-14
@@ -16,6 +16,7 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -301,37 +302,38 @@ public class StepFunctionsJsonHandler {
|
||||
* {@code arn:aws:states:::aws-sdk:sfn:describeMapRun} Task integration renders the same node in
|
||||
* PascalCase, so this is the one place the response is described.
|
||||
*
|
||||
* <p>A retained run is one whose every item succeeded, because a Map fails on the first item
|
||||
* that fails. That fixes {@code status}, both zero tolerances and {@code redriveCount}:
|
||||
* {@code redriveDate} is absent until a run is redriven, and no run here ever is.
|
||||
* <p>Both tolerances and {@code redriveCount} are zero because Floci implements neither, and
|
||||
* {@code redriveDate} is absent until a run is redriven, which no run here ever is.
|
||||
*/
|
||||
static ObjectNode describeMapRunResponse(ObjectMapper objectMapper, MapRun mapRun) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("mapRunArn", mapRun.getMapRunArn());
|
||||
response.put("executionArn", mapRun.getExecutionArn());
|
||||
response.put("status", "SUCCEEDED");
|
||||
response.put("status", mapRun.getStatus());
|
||||
response.put("startDate", mapRun.getStartDate());
|
||||
response.put("stopDate", mapRun.getStopDate());
|
||||
response.put("maxConcurrency", mapRun.getMaxConcurrency());
|
||||
response.put("toleratedFailurePercentage", 0.0);
|
||||
response.put("toleratedFailureCount", 0);
|
||||
putMapRunCounts(response.putObject("itemCounts"), mapRun.getItemCount());
|
||||
putMapRunCounts(response.putObject("itemCounts"), mapRun);
|
||||
// One child execution per item: ItemBatcher is not applied, so no execution covers a batch.
|
||||
putMapRunCounts(response.putObject("executionCounts"), mapRun.getItemCount());
|
||||
putMapRunCounts(response.putObject("executionCounts"), mapRun);
|
||||
response.put("redriveCount", 0);
|
||||
return response;
|
||||
}
|
||||
|
||||
/** The ten counters of a run whose every item succeeded and was written to the result set. */
|
||||
private static void putMapRunCounts(ObjectNode counts, int items) {
|
||||
/** A failed item's result counts as written, as on AWS. */
|
||||
private static void putMapRunCounts(ObjectNode counts, MapRun mapRun) {
|
||||
var succeeded = mapRun.getSucceededCount();
|
||||
var failed = mapRun.getFailedCount();
|
||||
counts.put("pending", 0);
|
||||
counts.put("running", 0);
|
||||
counts.put("succeeded", items);
|
||||
counts.put("failed", 0);
|
||||
counts.put("succeeded", succeeded);
|
||||
counts.put("failed", failed);
|
||||
counts.put("timedOut", 0);
|
||||
counts.put("aborted", 0);
|
||||
counts.put("total", items);
|
||||
counts.put("resultsWritten", items);
|
||||
counts.put("aborted", mapRun.getItemCount() - succeeded - failed);
|
||||
counts.put("total", mapRun.getItemCount());
|
||||
counts.put("resultsWritten", succeeded + failed);
|
||||
counts.put("failuresNotRedrivable", 0);
|
||||
counts.put("pendingRedrive", 0);
|
||||
}
|
||||
@@ -367,7 +369,12 @@ public class StepFunctionsJsonHandler {
|
||||
var arn = request.path("executionArn").asText();
|
||||
var includeExecutionData = request.path("includeExecutionData").asBoolean(true);
|
||||
|
||||
List<HistoryEvent> events = service.getExecutionHistory(arn);
|
||||
var live = service.getExecutionHistory(arn);
|
||||
List<HistoryEvent> events;
|
||||
// Branch and iteration threads append under the history's own monitor while a client reads.
|
||||
synchronized (live) {
|
||||
events = new ArrayList<>(live);
|
||||
}
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = response.putArray("events");
|
||||
for (HistoryEvent e : events) {
|
||||
|
||||
@@ -4,23 +4,24 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* A distributed Map run that has finished, keyed by its Map run ARN.
|
||||
*
|
||||
* <p>A Map fails on the first item that fails, so a run only reaches the {@code ResultWriter} that
|
||||
* mints its ARN once every item has succeeded. That is why a run carries a single {@code itemCount}
|
||||
* rather than the ten counters {@code DescribeMapRun} reports: the other nine are zero, and
|
||||
* {@code succeeded}, {@code total} and {@code resultsWritten} are all this count.
|
||||
* A distributed Map run that has finished, keyed by its Map run ARN. It is kept on success and on
|
||||
* failure, so the {@code mapRunArn} of a {@code MapRunStarted} event resolves through
|
||||
* {@code DescribeMapRun}. A Map cancels the remaining items on the first failure, so a failed run
|
||||
* reports those as aborted.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MapRun {
|
||||
private String mapRunArn;
|
||||
private String status;
|
||||
/** The execution of the state machine whose Map state opened this run. */
|
||||
private String executionArn;
|
||||
private double startDate;
|
||||
private double stopDate;
|
||||
/** Items processed by the run, which is also the number of child executions it ran. */
|
||||
/** Items of the run, which is also the number of child executions it ran. */
|
||||
private int itemCount;
|
||||
private int succeededCount;
|
||||
private int failedCount;
|
||||
/** The Map's declared MaxConcurrency, with an unbounded Map held as Integer.MAX_VALUE. */
|
||||
private int maxConcurrency;
|
||||
|
||||
@@ -38,6 +39,13 @@ public class MapRun {
|
||||
|
||||
public int getItemCount() { return itemCount; }
|
||||
public void setItemCount(int itemCount) { this.itemCount = itemCount; }
|
||||
/** A run recorded before the status was kept is one whose every item succeeded. */
|
||||
public String getStatus() { return status == null ? "SUCCEEDED" : status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public int getSucceededCount() { return status == null ? itemCount : succeededCount; }
|
||||
public void setSucceededCount(int succeededCount) { this.succeededCount = succeededCount; }
|
||||
public int getFailedCount() { return failedCount; }
|
||||
public void setFailedCount(int failedCount) { this.failedCount = failedCount; }
|
||||
|
||||
public int getMaxConcurrency() { return maxConcurrency; }
|
||||
public void setMaxConcurrency(int maxConcurrency) { this.maxConcurrency = maxConcurrency; }
|
||||
|
||||
+614
@@ -0,0 +1,614 @@
|
||||
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.DynamoDbJsonHandler;
|
||||
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
|
||||
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.MockedResponseStep;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* The history events of the states inside a Parallel branch or a Map iteration, and the cause a
|
||||
* failure inside one reports. Every shape here was read off real Step Functions in us-east-1 for
|
||||
* issue #2868: the event families a Parallel and a Map publish around their branches, how
|
||||
* {@code previousEventId} chains a branch's events to each other and to the state that started
|
||||
* them, which failures leave a {@code *StateFailed} event, and the
|
||||
* {@code An error occurred while executing the state ...} prefix a cause carries.
|
||||
*
|
||||
* <p>Branches run concurrently, so the order in which their events interleave is not asserted.
|
||||
* What is asserted is what a reader needs to follow each branch: the chain.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class AslExecutorBranchHistoryEventsTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private AslExecutor executor;
|
||||
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Instance<StepFunctionsService> sfnService = mock(Instance.class);
|
||||
when(sfnService.get()).thenReturn(mock(StepFunctionsService.class));
|
||||
executor = new AslExecutor(
|
||||
mock(LambdaExecutorService.class),
|
||||
mock(LambdaFunctionStore.class),
|
||||
mock(DynamoDbService.class),
|
||||
mock(DynamoDbJsonHandler.class),
|
||||
mock(SqsJsonHandler.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,
|
||||
mock(io.github.hectorvent.floci.core.common.CustomResourceLiveness.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parallelBranchesPublishTheirStatesOnChainsOfTheirOwn() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"A1","States":{"A1":{"Type":"Pass","Next":"A2"},"A2":{"Type":"Pass","End":true}}},
|
||||
{"StartAt":"B1","States":{"B1":{"Type":"Pass","Next":"B2"},"B2":{"Type":"Pass","End":true}}}
|
||||
],"Next":"After"},
|
||||
"After":{"Type":"Pass","End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals("SUCCEEDED", status(history), typesOf(history).toString());
|
||||
assertEquals(16, history.size(), typesOf(history).toString());
|
||||
assertIdsAreConsecutive(history);
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted"),
|
||||
typesOf(history.subList(0, 3)));
|
||||
assertEquals(List.of("ParallelStateSucceeded", "ParallelStateExited", "PassStateEntered",
|
||||
"PassStateExited", "ExecutionSucceeded"),
|
||||
typesOf(history.subList(11, 16)));
|
||||
|
||||
var started = eventOfType(history, "ParallelStateStarted");
|
||||
assertEquals(2L, started.getPreviousEventId());
|
||||
assertNull(started.getDetails());
|
||||
// Each branch's first state starts from ParallelStateStarted, and the branch chains on from
|
||||
// there: A1 exited points at A1 entered, A2 entered at A1 exited.
|
||||
for (String branch : List.of("A", "B")) {
|
||||
var firstEntered = stateEvent(history, "PassStateEntered", branch + "1");
|
||||
var firstExited = stateEvent(history, "PassStateExited", branch + "1");
|
||||
var secondEntered = stateEvent(history, "PassStateEntered", branch + "2");
|
||||
var secondExited = stateEvent(history, "PassStateExited", branch + "2");
|
||||
assertEquals(started.getId(), firstEntered.getPreviousEventId());
|
||||
assertEquals(firstEntered.getId(), firstExited.getPreviousEventId());
|
||||
assertEquals(firstExited.getId(), secondEntered.getPreviousEventId());
|
||||
assertEquals(secondEntered.getId(), secondExited.getPreviousEventId());
|
||||
}
|
||||
// The Parallel continues from the last event a branch published. ParallelStateSucceeded
|
||||
// points at it and is passed by: ParallelStateExited points at it too.
|
||||
long lastBranchEvent = history.get(10).getId();
|
||||
var succeeded = eventOfType(history, "ParallelStateSucceeded");
|
||||
var exited = eventOfType(history, "ParallelStateExited");
|
||||
assertEquals(lastBranchEvent, succeeded.getPreviousEventId());
|
||||
assertNull(succeeded.getDetails());
|
||||
assertEquals(lastBranchEvent, exited.getPreviousEventId());
|
||||
assertEquals("[{\"x\":\"a\"},{\"x\":\"a\"}]", exited.getDetails().get("output"));
|
||||
assertEquals(exited.getId(), stateEvent(history, "PassStateEntered", "After").getPreviousEventId());
|
||||
}
|
||||
|
||||
/** The shape reported in issue #2868, with the branch that never fails left out. */
|
||||
@Test
|
||||
void runtimeErrorInABranchNamesTheBranchStateAndItsEnteredEvent() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Fast","States":{"Fast":{"Type":"Pass","Parameters":{"m.$":"$.nope"},"End":true}}}
|
||||
],"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"PassStateEntered", "ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L), previousEventIdsOf(history));
|
||||
var failed = history.get(4);
|
||||
assertEquals("States.Runtime", failed.getDetails().get("error"));
|
||||
assertEquals("An error occurred while executing the state 'Fast' (entered at the event id #4). "
|
||||
+ "The JSONPath '$.nope' specified for the field 'm.$' could not be found in the input '{\"x\":\"a\"}'",
|
||||
failed.getDetails().get("cause"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void failStateInABranchPassesItsCauseThroughAndLeavesAParallelStateFailedEvent() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Boom","States":{"Boom":{"Type":"Fail","Error":"MyError","Cause":"my cause"}}}
|
||||
],"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"FailStateEntered", "ParallelStateFailed", "ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L), previousEventIdsOf(history));
|
||||
assertNull(history.get(4).getDetails());
|
||||
assertEquals(Map.of("error", "MyError", "cause", "my cause"), history.get(5).getDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void caughtBranchFailureExitsTheParallelWithTheErrorOutput() {
|
||||
var history = run("""
|
||||
{"QueryLanguage":"JSONata","StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Undef","States":{"Undef":{"Type":"Pass","Output":{"v":"{% $states.input.missing %}"},"End":true}}}
|
||||
],"Catch":[{"ErrorEquals":["States.ALL"],"Next":"Handled"}],"End":true},
|
||||
"Handled":{"Type":"Pass","End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"PassStateEntered", "EvaluationFailed", "ParallelStateFailed", "ParallelStateExited",
|
||||
"PassStateEntered", "PassStateExited", "ExecutionSucceeded"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), previousEventIdsOf(history));
|
||||
var cause = "An error occurred while executing the state 'Undef' (entered at the event id #4). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Output/v' "
|
||||
+ "returned nothing (undefined).";
|
||||
assertEquals(Map.of("error", "States.QueryEvaluationError", "cause", cause, "location", "Output/v",
|
||||
"state", "Undef"), history.get(4).getDetails());
|
||||
var errorOutput = "{\"Error\":\"States.QueryEvaluationError\",\"Cause\":\"" + cause.replace("\"", "\\\"") + "\"}";
|
||||
assertEquals(errorOutput, history.get(6).getDetails().get("output"));
|
||||
assertEquals(errorOutput, history.get(9).getDetails().get("output"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void retriedParallelStartsAgainAndFailsOnceItsRetryIsUsedUp() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Boom","States":{"Boom":{"Type":"Fail","Error":"MyError","Cause":"my cause"}}}
|
||||
],"Retry":[{"ErrorEquals":["States.ALL"],"MaxAttempts":1,"IntervalSeconds":0}],"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"FailStateEntered", "ParallelStateStarted", "FailStateEntered", "ParallelStateFailed",
|
||||
"ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L, 6L, 7L), previousEventIdsOf(history));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parallelOwnFailureIsAttributedToTheParallelAfterItsBranchesSucceeded() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Ok","States":{"Ok":{"Type":"Pass","End":true}}}
|
||||
],"ResultSelector":{"m.$":"$.nope"},"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"PassStateEntered", "PassStateExited", "ParallelStateSucceeded", "ExecutionFailed"),
|
||||
typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L, 6L), previousEventIdsOf(history));
|
||||
assertEquals("An error occurred while executing the state 'P' (entered at the event id #2). "
|
||||
+ "The JSONPath '$.nope' specified for the field 'm.$' could not be found in the input '[{\"x\":\"a\"}]'",
|
||||
history.get(6).getDetails().get("cause"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskFailureEndingABranchIsRecordedAsAbortedAndPassesItsCauseThrough() {
|
||||
var mocks = new MockedTestCase("branch-history-test", "Case", Map.of("Send", List.of(
|
||||
new MockedResponseStep(0, 0, null, "SQS.QueueDoesNotExistException", "The specified queue does not exist."))));
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Send","States":{"Send":{"Type":"Task","Resource":"arn:aws:states:::sqs:sendMessage",
|
||||
"Parameters":{"QueueUrl":"https://sqs.us-east-1.amazonaws.com/000000000000/missing","MessageBody":"hi"},"End":true}}}
|
||||
],"Catch":[{"ErrorEquals":["States.ALL"],"Next":"Handled"}],"End":true},
|
||||
"Handled":{"Type":"Pass","End":true}}}
|
||||
""", "{\"x\":\"a\"}", mocks);
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"TaskStateEntered", "TaskScheduled", "TaskStarted", "TaskFailed", "TaskStateAborted",
|
||||
"ParallelStateFailed", "ParallelStateExited", "PassStateEntered", "PassStateExited",
|
||||
"ExecutionSucceeded"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L, 6L, 7L, 7L, 9L, 10L, 11L, 12L), previousEventIdsOf(history));
|
||||
assertNull(history.get(7).getDetails());
|
||||
assertEquals("{\"Error\":\"SQS.QueueDoesNotExistException\",\"Cause\":\"The specified queue does not exist.\"}",
|
||||
history.get(9).getDetails().get("output"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapIterationsPublishTheirStatesUnderIterationEvents() {
|
||||
var history = run("""
|
||||
{"StartAt":"M","States":{
|
||||
"M":{"Type":"Map","ItemsPath":"$.items","ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},
|
||||
"StartAt":"I1","States":{"I1":{"Type":"Pass","Next":"I2"},"I2":{"Type":"Pass","End":true}}},
|
||||
"Next":"After"},
|
||||
"After":{"Type":"Pass","End":true}}}
|
||||
""", "{\"items\":[1,2]}");
|
||||
|
||||
assertEquals("SUCCEEDED", status(history), typesOf(history).toString());
|
||||
assertEquals(20, history.size(), typesOf(history).toString());
|
||||
assertIdsAreConsecutive(history);
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted"), typesOf(history.subList(0, 3)));
|
||||
var started = history.get(2);
|
||||
assertEquals(2L, started.getPreviousEventId());
|
||||
assertEquals(Map.of("length", 2), started.getDetails());
|
||||
|
||||
for (int index = 0; index < 2; index++) {
|
||||
var iterationStarted = iterationEvent(history, "MapIterationStarted", index);
|
||||
var iterationSucceeded = iterationEvent(history, "MapIterationSucceeded", index);
|
||||
var input = String.valueOf(index + 1);
|
||||
var firstEntered = stateEventWithInput(history, "PassStateEntered", "I1", input);
|
||||
var firstExited = stateEventWithOutput(history, "PassStateExited", "I1", input);
|
||||
var secondEntered = stateEventWithInput(history, "PassStateEntered", "I2", input);
|
||||
var secondExited = stateEventWithOutput(history, "PassStateExited", "I2", input);
|
||||
assertEquals(Map.of("name", "M", "index", index), iterationStarted.getDetails());
|
||||
assertEquals(started.getId(), iterationStarted.getPreviousEventId());
|
||||
assertEquals(iterationStarted.getId(), firstEntered.getPreviousEventId());
|
||||
assertEquals(firstEntered.getId(), firstExited.getPreviousEventId());
|
||||
assertEquals(firstExited.getId(), secondEntered.getPreviousEventId());
|
||||
assertEquals(secondEntered.getId(), secondExited.getPreviousEventId());
|
||||
assertEquals(secondExited.getId(), iterationSucceeded.getPreviousEventId());
|
||||
assertEquals(Map.of("name", "M", "index", index), iterationSucceeded.getDetails());
|
||||
}
|
||||
assertEquals(List.of("MapStateSucceeded", "MapStateExited", "PassStateEntered", "PassStateExited",
|
||||
"ExecutionSucceeded"), typesOf(history.subList(15, 20)));
|
||||
long lastIterationEvent = history.get(14).getId();
|
||||
assertEquals("MapIterationSucceeded", history.get(14).getType());
|
||||
assertEquals(lastIterationEvent, history.get(15).getPreviousEventId());
|
||||
assertNull(history.get(15).getDetails());
|
||||
assertEquals(lastIterationEvent, history.get(16).getPreviousEventId());
|
||||
assertEquals("[1,2]", history.get(16).getDetails().get("output"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapOverNoItemsExitsFromItsStartedEvent() {
|
||||
var history = run("""
|
||||
{"StartAt":"M","States":{
|
||||
"M":{"Type":"Map","ItemsPath":"$.items",
|
||||
"ItemProcessor":{"StartAt":"I","States":{"I":{"Type":"Pass","End":true}}},"End":true}}}
|
||||
""", "{\"items\":[]}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted", "MapStateSucceeded",
|
||||
"MapStateExited", "ExecutionSucceeded"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 3L, 5L), previousEventIdsOf(history));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeErrorInABranchTaskLeavesNoAbortedEvent() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Send","States":{"Send":{"Type":"Task","Resource":"arn:aws:states:::sqs:sendMessage",
|
||||
"Parameters":{"QueueUrl.$":"$.nope","MessageBody":"hi"},"End":true}}}
|
||||
],"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"TaskStateEntered", "ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L), previousEventIdsOf(history));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapIterationFailureLeavesIterationAndStateFailedEventsBehind() {
|
||||
var history = run("""
|
||||
{"QueryLanguage":"JSONata","StartAt":"M","States":{
|
||||
"M":{"Type":"Map","Items":"{% $states.input.items %}","MaxConcurrency":1,
|
||||
"ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},"StartAt":"Undef",
|
||||
"States":{"Undef":{"Type":"Pass","Output":{"v":"{% $states.input.missing %}"},"End":true}}},
|
||||
"End":true}}}
|
||||
""", "{\"items\":[1,2]}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted", "MapIterationStarted",
|
||||
"PassStateEntered", "EvaluationFailed", "MapIterationFailed", "MapStateFailed", "ExecutionFailed"),
|
||||
typesOf(history));
|
||||
// MapIterationFailed points at the iteration's last event and is passed by: MapStateFailed
|
||||
// points at that same event.
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L, 6L, 6L, 8L), previousEventIdsOf(history));
|
||||
var cause = "An error occurred while executing the state 'Undef' (entered at the event id #5). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Output/v' "
|
||||
+ "returned nothing (undefined).";
|
||||
assertEquals("Undef", history.get(5).getDetails().get("state"));
|
||||
assertEquals(Map.of("name", "M", "index", 0), history.get(6).getDetails());
|
||||
assertNull(history.get(7).getDetails());
|
||||
assertEquals(cause, history.get(8).getDetails().get("cause"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeErrorInAMapIterationLeavesNoFailedEvents() {
|
||||
var history = run("""
|
||||
{"StartAt":"M","States":{
|
||||
"M":{"Type":"Map","ItemsPath":"$.items","MaxConcurrency":1,
|
||||
"ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},"StartAt":"Fast",
|
||||
"States":{"Fast":{"Type":"Pass","Parameters":{"m.$":"$.nope"},"End":true}}},
|
||||
"End":true}}}
|
||||
""", "{\"items\":[1,2]}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted", "MapIterationStarted",
|
||||
"PassStateEntered", "ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L), previousEventIdsOf(history));
|
||||
assertEquals("An error occurred while executing the state 'Fast' (entered at the event id #5). "
|
||||
+ "The JSONPath '$.nope' specified for the field 'm.$' could not be found in the input '1'",
|
||||
history.get(5).getDetails().get("cause"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapNamesItsRunAndPublishesNoItemEvents() {
|
||||
var history = run("""
|
||||
{"StartAt":"D","States":{
|
||||
"D":{"Type":"Map","ItemsPath":"$.items","ItemProcessor":{
|
||||
"ProcessorConfig":{"Mode":"DISTRIBUTED","ExecutionType":"STANDARD"},
|
||||
"StartAt":"I1","States":{"I1":{"Type":"Pass","End":true}}},
|
||||
"End":true}}}
|
||||
""", "{\"items\":[1,2]}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted", "MapRunStarted",
|
||||
"MapRunSucceeded", "MapStateSucceeded", "MapStateExited", "ExecutionSucceeded"), typesOf(history));
|
||||
// The parent chain stays at MapRunStarted: MapStateExited points at it, past both Succeeded events.
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 5L, 4L, 7L), previousEventIdsOf(history));
|
||||
var mapRunArn = (String) history.get(3).getDetails().get("mapRunArn");
|
||||
assertTrue(mapRunArn.startsWith("arn:aws:states:us-east-1:000000000000:mapRun:branch-history-test/"), mapRunArn);
|
||||
assertEquals("[1,2]", history.get(6).getDetails().get("output"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nestedMapInsideAParallelBranchChainsToTheBranch() {
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"M","States":{"M":{"Type":"Map","ItemsPath":"$.items","ItemProcessor":{
|
||||
"ProcessorConfig":{"Mode":"INLINE"},"StartAt":"I1","States":{"I1":{"Type":"Pass","End":true}}},
|
||||
"End":true}}},
|
||||
{"StartAt":"B1","States":{"B1":{"Type":"Pass","End":true}}}
|
||||
],"End":true}}}
|
||||
""", "{\"items\":[1,2]}");
|
||||
|
||||
assertEquals("SUCCEEDED", status(history), typesOf(history).toString());
|
||||
assertEquals(20, history.size(), typesOf(history).toString());
|
||||
assertIdsAreConsecutive(history);
|
||||
var parallelStarted = eventOfType(history, "ParallelStateStarted");
|
||||
var mapEntered = eventOfType(history, "MapStateEntered");
|
||||
var mapStarted = eventOfType(history, "MapStateStarted");
|
||||
var mapSucceeded = eventOfType(history, "MapStateSucceeded");
|
||||
var mapExited = eventOfType(history, "MapStateExited");
|
||||
assertEquals(parallelStarted.getId(), mapEntered.getPreviousEventId());
|
||||
assertEquals(parallelStarted.getId(), stateEvent(history, "PassStateEntered", "B1").getPreviousEventId());
|
||||
assertEquals(mapEntered.getId(), mapStarted.getPreviousEventId());
|
||||
for (int index = 0; index < 2; index++) {
|
||||
assertEquals(mapStarted.getId(), iterationEvent(history, "MapIterationStarted", index).getPreviousEventId());
|
||||
}
|
||||
long lastIterationEvent = Math.max(iterationEvent(history, "MapIterationSucceeded", 0).getId(),
|
||||
iterationEvent(history, "MapIterationSucceeded", 1).getId());
|
||||
assertEquals(lastIterationEvent, mapSucceeded.getPreviousEventId());
|
||||
assertEquals(lastIterationEvent, mapExited.getPreviousEventId());
|
||||
var parallelExited = eventOfType(history, "ParallelStateExited");
|
||||
long lastBranchEvent = Math.max(mapExited.getId(), stateEvent(history, "PassStateExited", "B1").getId());
|
||||
assertEquals(lastBranchEvent, eventOfType(history, "ParallelStateSucceeded").getPreviousEventId());
|
||||
assertEquals(lastBranchEvent, parallelExited.getPreviousEventId());
|
||||
assertEquals("ExecutionSucceeded", history.get(19).getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonataFailureRecordsAnEvaluationFailedEventPerAttempt() {
|
||||
var history = run("""
|
||||
{"QueryLanguage":"JSONata","StartAt":"Send","States":{
|
||||
"Send":{"Type":"Task","Resource":"arn:aws:states:::sqs:sendMessage",
|
||||
"Arguments":{"QueueUrl":"https://sqs.us-east-1.amazonaws.com/000000000000/q","MessageBody":"{% $states.input.missing %}"},
|
||||
"Retry":[{"ErrorEquals":["States.ALL"],"MaxAttempts":1,"IntervalSeconds":0}],"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "TaskStateEntered", "EvaluationFailed", "EvaluationFailed",
|
||||
"ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L), previousEventIdsOf(history));
|
||||
var cause = "An error occurred while executing the state 'Send' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Arguments/MessageBody' "
|
||||
+ "returned nothing (undefined).";
|
||||
var expected = Map.of("error", "States.QueryEvaluationError", "cause", cause,
|
||||
"location", "Arguments/MessageBody", "state", "Send");
|
||||
assertEquals(expected, history.get(2).getDetails());
|
||||
assertEquals(expected, history.get(3).getDetails());
|
||||
assertEquals(Map.of("error", "States.QueryEvaluationError", "cause", cause), history.get(4).getDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapItemsExpressionFailureIsRecordedBeforeTheMapStarts() {
|
||||
var history = run("""
|
||||
{"QueryLanguage":"JSONata","StartAt":"Fan","States":{
|
||||
"Fan":{"Type":"Map","Items":"{% $states.input.missing %}",
|
||||
"ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},"StartAt":"I","States":{"I":{"Type":"Pass","End":true}}},
|
||||
"End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "EvaluationFailed", "MapStateFailed",
|
||||
"ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L), previousEventIdsOf(history));
|
||||
assertEquals("Items", history.get(2).getDetails().get("location"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Catch clause whose own Output fails. AWS records the clause's EvaluationFailed from where the
|
||||
* state stood before its first Failed event, then fails the state a second time.
|
||||
*/
|
||||
@Test
|
||||
void catchClauseOutputFailureIsRecordedFromBeforeTheStateFailedEvent() {
|
||||
var history = run("""
|
||||
{"QueryLanguage":"JSONata","StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Boom","States":{"Boom":{"Type":"Fail","Error":"MyError","Cause":"my cause"}}}
|
||||
],"Catch":[{"ErrorEquals":["Other"],"Next":"Done"},
|
||||
{"ErrorEquals":["States.ALL"],"Output":{"v":"{% $states.input.missing %}"},"Next":"Done"}],
|
||||
"End":true},
|
||||
"Done":{"Type":"Pass","End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted", "FailStateEntered",
|
||||
"ParallelStateFailed", "EvaluationFailed", "ParallelStateFailed", "ExecutionFailed"), typesOf(history));
|
||||
assertEquals(List.of(0L, 0L, 2L, 3L, 4L, 4L, 6L, 7L), previousEventIdsOf(history));
|
||||
var cause = "An error occurred while executing the state 'P' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Catch[1]/Output/v' "
|
||||
+ "returned nothing (undefined).";
|
||||
assertEquals(Map.of("error", "States.QueryEvaluationError", "cause", cause,
|
||||
"location", "Catch[1]/Output/v", "state", "P"), history.get(5).getDetails());
|
||||
assertEquals(Map.of("error", "States.QueryEvaluationError", "cause", cause), history.get(7).getDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void choiceWithNoMatchingRuleAndNoDefaultFailsAsAwsDoes() {
|
||||
var history = run("""
|
||||
{"StartAt":"C","States":{
|
||||
"C":{"Type":"Choice","Choices":[{"Variable":"$.x","StringEquals":"never","Next":"Done"}]},
|
||||
"Done":{"Type":"Pass","End":true}}}
|
||||
""", "{\"x\":\"a\"}");
|
||||
|
||||
assertEquals(List.of("ExecutionStarted", "ChoiceStateEntered", "ExecutionFailed"), typesOf(history));
|
||||
assertEquals(Map.of("error", "States.Runtime",
|
||||
"cause", "An error occurred while executing the state 'C' (entered at the event id #2). "
|
||||
+ "Failed to transition out of the state. The state does not point to a next state."),
|
||||
history.get(2).getDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void catchInsideABranchTakesItsNextEvenOnAnEndState() {
|
||||
var mocks = new MockedTestCase("branch-history-test", "Case", Map.of("Send", List.of(
|
||||
new MockedResponseStep(0, 0, null, "MyError", "boom"))));
|
||||
var history = run("""
|
||||
{"StartAt":"P","States":{
|
||||
"P":{"Type":"Parallel","Branches":[
|
||||
{"StartAt":"Send","States":{
|
||||
"Send":{"Type":"Task","Resource":"arn:aws:states:::sqs:sendMessage",
|
||||
"Parameters":{"QueueUrl":"https://sqs.us-east-1.amazonaws.com/000000000000/q","MessageBody":"hi"},
|
||||
"Catch":[{"ErrorEquals":["States.ALL"],"Next":"Recover"}],"End":true},
|
||||
"Recover":{"Type":"Pass","Result":{"recovered":true},"End":true}}}
|
||||
],"End":true}}}
|
||||
""", "{}", mocks);
|
||||
|
||||
assertEquals("SUCCEEDED", status(history), typesOf(history).toString());
|
||||
assertEquals("[{\"recovered\":true}]", eventOfType(history, "ExecutionSucceeded").getDetails().get("output"));
|
||||
assertFalse(typesOf(history).contains("TaskStateAborted"));
|
||||
}
|
||||
|
||||
private static String status(List<HistoryEvent> history) {
|
||||
var last = history.get(history.size() - 1).getType();
|
||||
return switch (last) {
|
||||
case "ExecutionSucceeded" -> "SUCCEEDED";
|
||||
case "ExecutionFailed" -> "FAILED";
|
||||
default -> last;
|
||||
};
|
||||
}
|
||||
|
||||
private static List<String> typesOf(List<HistoryEvent> history) {
|
||||
return history.stream().map(HistoryEvent::getType).toList();
|
||||
}
|
||||
|
||||
private static List<Long> previousEventIdsOf(List<HistoryEvent> history) {
|
||||
return history.stream().map(HistoryEvent::getPreviousEventId).toList();
|
||||
}
|
||||
|
||||
private static void assertIdsAreConsecutive(List<HistoryEvent> history) {
|
||||
for (var i = 0; i < history.size(); i++) {
|
||||
assertEquals(i + 1L, history.get(i).getId(), "unexpected id at index " + i);
|
||||
}
|
||||
var referenced = history.stream().map(HistoryEvent::getPreviousEventId).collect(Collectors.toSet());
|
||||
referenced.remove(0L);
|
||||
assertTrue(referenced.stream().allMatch(id -> id < history.size()),
|
||||
"previousEventId points past the history: " + Set.copyOf(referenced));
|
||||
}
|
||||
|
||||
private static HistoryEvent eventOfType(List<HistoryEvent> history, String type) {
|
||||
return history.stream()
|
||||
.filter(event -> type.equals(event.getType()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("history has no " + type + " event: " + typesOf(history)));
|
||||
}
|
||||
|
||||
private static HistoryEvent stateEvent(List<HistoryEvent> history, String type, String name) {
|
||||
return history.stream()
|
||||
.filter(event -> type.equals(event.getType()) && name.equals(event.getDetails().get("name")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("history has no " + type + " for " + name + ": " + typesOf(history)));
|
||||
}
|
||||
|
||||
private static HistoryEvent stateEventWithInput(List<HistoryEvent> history, String type, String name, String input) {
|
||||
return history.stream()
|
||||
.filter(event -> type.equals(event.getType()) && name.equals(event.getDetails().get("name"))
|
||||
&& input.equals(event.getDetails().get("input")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("history has no " + type + " for " + name + " with input "
|
||||
+ input + ": " + typesOf(history)));
|
||||
}
|
||||
|
||||
private static HistoryEvent stateEventWithOutput(List<HistoryEvent> history, String type, String name, String output) {
|
||||
return history.stream()
|
||||
.filter(event -> type.equals(event.getType()) && name.equals(event.getDetails().get("name"))
|
||||
&& output.equals(event.getDetails().get("output")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("history has no " + type + " for " + name + " with output "
|
||||
+ output + ": " + typesOf(history)));
|
||||
}
|
||||
|
||||
private static HistoryEvent iterationEvent(List<HistoryEvent> history, String type, int index) {
|
||||
return history.stream()
|
||||
.filter(event -> type.equals(event.getType()) && Integer.valueOf(index).equals(event.getDetails().get("index")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("history has no " + type + " for index " + index + ": " + typesOf(history)));
|
||||
}
|
||||
|
||||
private List<HistoryEvent> run(String definition, String input) {
|
||||
return run(definition, input, null);
|
||||
}
|
||||
|
||||
/** Runs the definition the way StartExecution does: the history already holds ExecutionStarted as event 1. */
|
||||
private List<HistoryEvent> run(String definition, String input, MockedTestCase mocks) {
|
||||
var stateMachine = new StateMachine();
|
||||
stateMachine.setName("branch-history-test");
|
||||
stateMachine.setStateMachineArn("arn:aws:states:%s:%s:stateMachine:branch-history-test".formatted(REGION, ACCOUNT));
|
||||
stateMachine.setRoleArn("arn:aws:iam::%s:role/test-role".formatted(ACCOUNT));
|
||||
stateMachine.setDefinition(definition);
|
||||
|
||||
var execution = new Execution();
|
||||
execution.setName("branch-history-execution");
|
||||
execution.setExecutionArn(
|
||||
"arn:aws:states:%s:%s:execution:branch-history-test:branch-history-execution".formatted(REGION, ACCOUNT));
|
||||
execution.setStateMachineArn(stateMachine.getStateMachineArn());
|
||||
execution.setInput(input);
|
||||
|
||||
var history = new ArrayList<HistoryEvent>();
|
||||
var started = new HistoryEvent();
|
||||
started.setId(1L);
|
||||
started.setPreviousEventId(0L);
|
||||
started.setType("ExecutionStarted");
|
||||
started.setDetails(Map.of("input", input, "inputDetails", Map.of("truncated", false)));
|
||||
history.add(started);
|
||||
|
||||
executor.executeSync(stateMachine, execution, history, mocks, (updated, events) -> {
|
||||
});
|
||||
return history;
|
||||
}
|
||||
}
|
||||
+12
-6
@@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Guards the bound AWS puts on a running execution: a state machine that never reaches a terminal
|
||||
@@ -183,6 +184,8 @@ class AslExecutorHistoryEventLimitTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Instance<StepFunctionsService> sfnService = mock(Instance.class);
|
||||
when(sfnService.get()).thenReturn(mock(StepFunctionsService.class));
|
||||
executor = new AslExecutor(
|
||||
mock(LambdaExecutorService.class),
|
||||
mock(LambdaFunctionStore.class),
|
||||
@@ -199,7 +202,7 @@ class AslExecutorHistoryEventLimitTest {
|
||||
mock(io.github.hectorvent.floci.services.scheduler.SchedulerController.class),
|
||||
objectMapper,
|
||||
new JsonataEvaluator(objectMapper),
|
||||
mock(Instance.class), mock(EmulatorConfig.class), vertx, null);
|
||||
sfnService, mock(EmulatorConfig.class), vertx, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,17 +241,20 @@ class AslExecutorHistoryEventLimitTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* The branch produced the events that ran the execution out of them, and floci publishes none
|
||||
* of them. What the caller reads back is the four events the top-level flow did produce, ending
|
||||
* in the failure: an unbroken chain, not four events numbered as if 25,000 had happened.
|
||||
* The branch produced the events that ran the execution out of them, and they are published
|
||||
* into the execution's history like any other: what the caller reads back is one history,
|
||||
* numbered without a gap and ending in the failure.
|
||||
*/
|
||||
@Test
|
||||
void aParallelBranchLeavesThePublishedHistoryUnbroken() {
|
||||
run(RUNAWAY_PARALLEL_BRANCH);
|
||||
|
||||
assertEquals(List.of("PassStateEntered", "PassStateExited", "ParallelStateEntered",
|
||||
"ExecutionFailed"),
|
||||
history.stream().map(HistoryEvent::getType).toList());
|
||||
"ParallelStateStarted", "ChoiceStateEntered"),
|
||||
history.subList(0, 5).stream().map(HistoryEvent::getType).toList());
|
||||
HistoryEvent last = history.get(history.size() - 1);
|
||||
assertEquals("ExecutionFailed", last.getType());
|
||||
assertEquals(25_000, history.size());
|
||||
for (int index = 0; index < history.size(); index++) {
|
||||
assertEquals(index + 1L, history.get(index).getId(), "unexpected id at index " + index);
|
||||
assertEquals((long) index, history.get(index).getPreviousEventId(),
|
||||
|
||||
+9
@@ -14,6 +14,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -164,6 +165,14 @@ class AslExecutorIntrinsicMissingArgumentTest {
|
||||
+ "input '{\"items\":[1,2]}'", failure.cause);
|
||||
}
|
||||
|
||||
/** The plain form of the same path is not a miss. AWS resolves it to null and the execution succeeds. */
|
||||
@Test
|
||||
void plainReferencePastTheEndOfAnArrayResolvesToNull() throws Exception {
|
||||
var resolved = resolve("{\"v.$\":\"$.items[5]\"}", "{\"items\":[1,2]}");
|
||||
|
||||
assertTrue(resolved.path("v").isNull());
|
||||
}
|
||||
|
||||
/** Reading a field off the absent element fails alike. */
|
||||
@Test
|
||||
void navigatingPastAnOutOfRangeIndexFails() throws Exception {
|
||||
|
||||
+17
-3
@@ -281,6 +281,7 @@ class AslExecutorTaskHistoryEventsTest {
|
||||
"Iterate": {
|
||||
"Type": "Map",
|
||||
"ItemsPath": "$[0].items",
|
||||
"MaxConcurrency": 1,
|
||||
"ItemProcessor": {
|
||||
"StartAt": "ItemStep",
|
||||
"States": {"ItemStep": {"Type": "Pass", "End": true}}
|
||||
@@ -293,10 +294,23 @@ class AslExecutorTaskHistoryEventsTest {
|
||||
|
||||
assertEquals("SUCCEEDED", execution.getStatus(), "history: " + typesOf(history));
|
||||
assertEquals(
|
||||
List.of("ParallelStateEntered", "ParallelStateExited",
|
||||
"MapStateEntered", "MapStateExited", "ExecutionSucceeded"),
|
||||
List.of("ParallelStateEntered", "ParallelStateStarted",
|
||||
"PassStateEntered", "PassStateExited", "PassStateEntered", "PassStateExited",
|
||||
"ParallelStateSucceeded", "ParallelStateExited",
|
||||
"MapStateEntered", "MapStateStarted",
|
||||
"MapIterationStarted", "PassStateEntered", "PassStateExited", "MapIterationSucceeded",
|
||||
"MapIterationStarted", "PassStateEntered", "PassStateExited", "MapIterationSucceeded",
|
||||
"MapStateSucceeded", "MapStateExited", "ExecutionSucceeded"),
|
||||
typesOf(history));
|
||||
assertChain(history);
|
||||
// The branch and the iterations chain to the Started event that opened them, and a
|
||||
// Succeeded event is passed by: the Exited event after it points where it pointed.
|
||||
assertEquals(
|
||||
List.of(0L, 1L, 2L, 3L, 4L, 5L, 6L, 6L,
|
||||
8L, 9L, 10L, 11L, 12L, 13L, 10L, 15L, 16L, 17L, 18L, 18L, 20L),
|
||||
history.stream().map(HistoryEvent::getPreviousEventId).toList());
|
||||
for (var i = 0; i < history.size(); i++) {
|
||||
assertEquals(i + 1L, history.get(i).getId(), "unexpected id at index " + i);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> typesOf(List<HistoryEvent> history) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class HistoryChainTest {
|
||||
|
||||
/** The history-event limit of AslExecutor. A counted event past it fails the execution. */
|
||||
private static final int MAX_HISTORY_EVENTS = 25_000;
|
||||
|
||||
@Test
|
||||
void publishingAfterTheExecutionEndedRecordsNothingAndDoesNotCountTowardsTheLimit() {
|
||||
List<HistoryEvent> history = new ArrayList<>();
|
||||
var chain = HistoryChain.of(history);
|
||||
chain.end("ExecutionSucceeded", Map.of());
|
||||
|
||||
assertDoesNotThrow(() -> {
|
||||
for (var i = 0; i < MAX_HISTORY_EVENTS; i++) {
|
||||
assertEquals(0L, chain.publish("PassStateEntered", null));
|
||||
chain.publishAside("PassStateSucceeded", null);
|
||||
}
|
||||
});
|
||||
assertEquals(1, history.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishingIntoAHistorySealedByStopExecutionStopsCountingAsWell() {
|
||||
var history = new StepFunctionsService.ExecutionHistory();
|
||||
var chain = HistoryChain.of(history);
|
||||
var branch = chain.fork();
|
||||
history.sealWith("ExecutionAborted", Map.of());
|
||||
|
||||
assertDoesNotThrow(() -> {
|
||||
for (var i = 0; i < MAX_HISTORY_EVENTS; i++) {
|
||||
assertEquals(0L, chain.publish("PassStateEntered", null));
|
||||
assertEquals(0L, branch.publish("PassStateEntered", null));
|
||||
}
|
||||
});
|
||||
assertEquals(1, history.size());
|
||||
}
|
||||
}
|
||||
+78
-2
@@ -22,8 +22,8 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* the {@code arn:aws:states:::aws-sdk:sfn:describeMapRun} Task integration.
|
||||
*
|
||||
* <p>Every asserted value was measured against us-east-1 with a distributed Map run of the same
|
||||
* shape. A Map run only becomes describable once its {@code ResultWriter} has minted the Map run
|
||||
* ARN and returned it in the Map result, which is also the only way an ASL author obtains it.
|
||||
* shape. Every run is describable through the {@code mapRunArn} of its {@code MapRunStarted}
|
||||
* event. A run with a {@code ResultWriter} also returns that ARN in the Map result.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@@ -240,6 +240,44 @@ class StepFunctionsDescribeMapRunIntegrationTest {
|
||||
assertEquals(0, response.jsonPath().getInt(set + ".pendingRedrive"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void describeMapRunResolvesTheArnOfAMapWithoutResultWriter() throws Exception {
|
||||
var smArn = createStateMachine("describe-map-run-no-writer", distributedMapWithoutWriter(
|
||||
"[1, 2]", "Keep", "{\"Keep\": {\"Type\": \"Pass\", \"End\": true}}"));
|
||||
var execArn = startExecution(smArn, "{}");
|
||||
var describe = waitForTerminalState(execArn);
|
||||
assertEquals("SUCCEEDED", describe.jsonPath().getString("status"),
|
||||
"cause: " + describe.jsonPath().getString("cause"));
|
||||
|
||||
var mapRunArn = mapRunArnFromHistory(execArn);
|
||||
var response = describeMapRun(mapRunArn);
|
||||
response.then().statusCode(200);
|
||||
assertEquals(mapRunArn, response.jsonPath().getString("mapRunArn"));
|
||||
assertEquals(execArn, response.jsonPath().getString("executionArn"));
|
||||
assertEquals("SUCCEEDED", response.jsonPath().getString("status"));
|
||||
assertCounters(response, "itemCounts", 2);
|
||||
assertCounters(response, "executionCounts", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void describeMapRunReportsARunWhoseItemFailed() throws Exception {
|
||||
var smArn = createStateMachine("describe-map-run-failed", distributedMapWithoutWriter(
|
||||
"[1]", "Boom", "{\"Boom\": {\"Type\": \"Fail\", \"Error\": \"Boom\", \"Cause\": \"item failed\"}}"));
|
||||
var execArn = startExecution(smArn, "{}");
|
||||
assertEquals("FAILED", waitForTerminalState(execArn).jsonPath().getString("status"));
|
||||
|
||||
var response = describeMapRun(mapRunArnFromHistory(execArn));
|
||||
response.then().statusCode(200);
|
||||
assertEquals("FAILED", response.jsonPath().getString("status"));
|
||||
assertEquals(0, response.jsonPath().getInt("itemCounts.succeeded"));
|
||||
assertEquals(1, response.jsonPath().getInt("itemCounts.failed"));
|
||||
assertEquals(0, response.jsonPath().getInt("itemCounts.aborted"));
|
||||
assertEquals(1, response.jsonPath().getInt("itemCounts.total"));
|
||||
assertEquals(1, response.jsonPath().getInt("itemCounts.resultsWritten"));
|
||||
}
|
||||
|
||||
private static void assertTaskCounters(JsonNode counts, int items) {
|
||||
assertEquals(0, counts.path("Pending").asInt());
|
||||
assertEquals(0, counts.path("Running").asInt());
|
||||
@@ -284,6 +322,44 @@ class StepFunctionsDescribeMapRunIntegrationTest {
|
||||
.replace("BUCKET", bucket);
|
||||
}
|
||||
|
||||
private static String distributedMapWithoutWriter(String items, String startAt, String states) {
|
||||
return """
|
||||
{
|
||||
"QueryLanguage": "JSONata",
|
||||
"StartAt": "Fan",
|
||||
"States": {
|
||||
"Fan": {
|
||||
"Type": "Map",
|
||||
"End": true,
|
||||
"Items": ITEMS,
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {"Mode": "DISTRIBUTED", "ExecutionType": "STANDARD"},
|
||||
"StartAt": "START_AT",
|
||||
"States": STATES
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".replace("ITEMS", items).replace("START_AT", startAt).replace("STATES", states);
|
||||
}
|
||||
|
||||
private static String mapRunArnFromHistory(String execArn) throws Exception {
|
||||
var history = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.GetExecutionHistory")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"executionArn": "%s"}
|
||||
""".formatted(execArn))
|
||||
.when().post("/");
|
||||
history.then().statusCode(200);
|
||||
for (JsonNode event : mapper.readTree(history.asString()).path("events")) {
|
||||
if ("MapRunStarted".equals(event.path("type").asText())) {
|
||||
return event.path("mapRunStartedEventDetails").path("mapRunArn").asText();
|
||||
}
|
||||
}
|
||||
return fail("no MapRunStarted event in the history of " + execArn);
|
||||
}
|
||||
|
||||
private static Response describeMapRun(String mapRunArn) {
|
||||
return given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.DescribeMapRun")
|
||||
|
||||
+146
@@ -220,6 +220,136 @@ class StepFunctionsExecutionHistoryIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The events of the states inside a Parallel branch and a Map iteration reach the caller through
|
||||
* GetExecutionHistory under the details field the SDK names for each event type. Shapes read
|
||||
* off real Step Functions in us-east-1 for issue #2868.
|
||||
*/
|
||||
@Test
|
||||
void getExecutionHistory_publishesParallelBranchAndMapIterationEvents() throws Exception {
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "P",
|
||||
"States": {
|
||||
"P": {
|
||||
"Type": "Parallel",
|
||||
"Branches": [
|
||||
{"StartAt": "A1", "States": {"A1": {"Type": "Pass", "End": true}}}
|
||||
],
|
||||
"Next": "M"
|
||||
},
|
||||
"M": {
|
||||
"Type": "Map",
|
||||
"ItemsPath": "$[0].items",
|
||||
"MaxConcurrency": 1,
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {"Mode": "INLINE"},
|
||||
"StartAt": "I1",
|
||||
"States": {"I1": {"Type": "Pass", "End": true}}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String stateMachineArn = createStateMachine("execution-history-branches-test", definition);
|
||||
String executionArn = startExecution(stateMachineArn, "{\"items\": [1, 2]}");
|
||||
waitForExecution(executionArn);
|
||||
|
||||
var events = MAPPER.readTree(getExecutionHistory(executionArn).body().asString()).path("events");
|
||||
var types = new ArrayList<String>();
|
||||
events.forEach(event -> types.add(event.path("type").asText()));
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"PassStateEntered", "PassStateExited", "ParallelStateSucceeded", "ParallelStateExited",
|
||||
"MapStateEntered", "MapStateStarted",
|
||||
"MapIterationStarted", "PassStateEntered", "PassStateExited", "MapIterationSucceeded",
|
||||
"MapIterationStarted", "PassStateEntered", "PassStateExited", "MapIterationSucceeded",
|
||||
"MapStateSucceeded", "MapStateExited", "ExecutionSucceeded"), types);
|
||||
var expectedPreviousEventIds = List.of(0L, 0L, 2L, 3L, 4L, 5L, 5L, 7L, 8L, 9L, 10L, 11L, 12L,
|
||||
9L, 14L, 15L, 16L, 17L, 17L, 19L);
|
||||
for (var i = 0; i < events.size(); i++) {
|
||||
assertEquals(i + 1L, events.get(i).path("id").asLong());
|
||||
assertEquals(expectedPreviousEventIds.get(i), events.get(i).path("previousEventId").asLong(),
|
||||
"previousEventId of event " + (i + 1) + " in " + events);
|
||||
}
|
||||
assertFalse(events.get(2).has("parallelStateStartedEventDetails"));
|
||||
assertEquals(2, events.get(8).path("mapStateStartedEventDetails").path("length").asInt());
|
||||
assertEquals("M", events.get(9).path("mapIterationStartedEventDetails").path("name").asText());
|
||||
assertEquals(0, events.get(9).path("mapIterationStartedEventDetails").path("index").asInt());
|
||||
assertEquals("M", events.get(16).path("mapIterationSucceededEventDetails").path("name").asText());
|
||||
assertEquals(1, events.get(16).path("mapIterationSucceededEventDetails").path("index").asInt());
|
||||
assertEquals("[1,2]", events.get(18).path("stateExitedEventDetails").path("output").asText());
|
||||
}
|
||||
|
||||
/** The shape reported in issue #2868, verified against us-east-1. */
|
||||
@Test
|
||||
void getExecutionHistory_namesTheBranchStateAFailureBelongsTo() throws Exception {
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "P",
|
||||
"States": {
|
||||
"P": {
|
||||
"Type": "Parallel",
|
||||
"Branches": [
|
||||
{"StartAt": "Fast", "States": {"Fast": {"Type": "Pass", "Parameters": {"m.$": "$.nope"}, "End": true}}}
|
||||
],
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String stateMachineArn = createStateMachine("execution-history-branch-failure-test", definition);
|
||||
String executionArn = startExecution(stateMachineArn, "{\"x\": \"a\"}");
|
||||
var cause = "An error occurred while executing the state 'Fast' (entered at the event id #4). "
|
||||
+ "The JSONPath '$.nope' specified for the field 'm.$' could not be found in the input '{\"x\":\"a\"}'";
|
||||
await().atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> {
|
||||
var described = describeExecution(executionArn);
|
||||
assertEquals("FAILED", described.jsonPath().getString("status"), described.body().asString());
|
||||
assertEquals("States.Runtime", described.jsonPath().getString("error"));
|
||||
assertEquals(cause, described.jsonPath().getString("cause"));
|
||||
});
|
||||
|
||||
var events = MAPPER.readTree(getExecutionHistory(executionArn).body().asString()).path("events");
|
||||
var types = new ArrayList<String>();
|
||||
events.forEach(event -> types.add(event.path("type").asText()));
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"PassStateEntered", "ExecutionFailed"), types);
|
||||
assertEquals("Fast", events.get(3).path("stateEnteredEventDetails").path("name").asText());
|
||||
assertEquals(cause, events.get(4).path("executionFailedEventDetails").path("cause").asText());
|
||||
assertEquals(4L, events.get(4).path("previousEventId").asLong());
|
||||
}
|
||||
|
||||
private Response getExecutionHistory(String executionArn) {
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.GetExecutionHistory")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body(String.format("""
|
||||
{
|
||||
"executionArn": "%s",
|
||||
"includeExecutionData": true
|
||||
}
|
||||
""", executionArn))
|
||||
.when()
|
||||
.post("/");
|
||||
response.then().statusCode(200);
|
||||
return response;
|
||||
}
|
||||
|
||||
private Response describeExecution(String executionArn) {
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.DescribeExecution")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body(String.format("""
|
||||
{ "executionArn": "%s" }
|
||||
""", executionArn))
|
||||
.when()
|
||||
.post("/");
|
||||
response.then().statusCode(200);
|
||||
return response;
|
||||
}
|
||||
|
||||
private static String createQueue(String queueName) {
|
||||
var response = given()
|
||||
.header("X-Amz-Target", "AmazonSQS.CreateQueue")
|
||||
@@ -278,6 +408,22 @@ class StepFunctionsExecutionHistoryIntegrationTest {
|
||||
return response.jsonPath().getString("executionArn");
|
||||
}
|
||||
|
||||
private String startExecution(String stateMachineArn, String input) {
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.StartExecution")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body(String.format("""
|
||||
{
|
||||
"stateMachineArn": "%s",
|
||||
"input": %s
|
||||
}
|
||||
""", stateMachineArn, quote(input)))
|
||||
.when()
|
||||
.post("/");
|
||||
response.then().statusCode(200);
|
||||
return response.jsonPath().getString("executionArn");
|
||||
}
|
||||
|
||||
private void waitForExecution(String executionArn) {
|
||||
await()
|
||||
.atMost(Duration.ofSeconds(5))
|
||||
|
||||
+8
-4
@@ -39,7 +39,8 @@ class StepFunctionsIntrinsicMissingArgumentIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", describe.jsonPath().getString("status"), describe.body().asString());
|
||||
assertEquals("States.Runtime", describe.jsonPath().getString("error"));
|
||||
assertEquals("The function 'States.Format('{}', $.nope)' had the following error: "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The function 'States.Format('{}', $.nope)' had the following error: "
|
||||
+ "The JsonPath argument for the field '$.nope' could not be found in the input "
|
||||
+ "'{\"other\":1}'",
|
||||
describe.jsonPath().getString("cause"));
|
||||
@@ -58,7 +59,8 @@ class StepFunctionsIntrinsicMissingArgumentIntegrationTest {
|
||||
var describe = run("nested-intrinsic", definition, "{\"other\":1}");
|
||||
|
||||
assertEquals("FAILED", describe.jsonPath().getString("status"), describe.body().asString());
|
||||
assertEquals("The function 'States.Format('{}', States.Format('{}', $.nope))' had the "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The function 'States.Format('{}', States.Format('{}', $.nope))' had the "
|
||||
+ "following error: The JsonPath argument for the field '$.nope' could not be "
|
||||
+ "found in the input '{\"other\":1}'",
|
||||
describe.jsonPath().getString("cause"));
|
||||
@@ -79,7 +81,8 @@ class StepFunctionsIntrinsicMissingArgumentIntegrationTest {
|
||||
var describe = run("intrinsic-index-out-of-range", definition, "{\"items\":[1,2]}");
|
||||
|
||||
assertEquals("FAILED", describe.jsonPath().getString("status"), describe.body().asString());
|
||||
assertEquals("The function 'States.Format('{}', $.items[5])' had the following error: "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The function 'States.Format('{}', $.items[5])' had the following error: "
|
||||
+ "The JsonPath argument for the field '$.items[5]' could not be found in the "
|
||||
+ "input '{\"items\":[1,2]}'",
|
||||
describe.jsonPath().getString("cause"));
|
||||
@@ -101,7 +104,8 @@ class StepFunctionsIntrinsicMissingArgumentIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", describe.jsonPath().getString("status"), describe.body().asString());
|
||||
assertEquals("States.Runtime", describe.jsonPath().getString("error"));
|
||||
assertEquals("The function 'States.Format('{}', $.nope)' had the following error: "
|
||||
assertEquals("An error occurred while executing the state 'M' (entered at the event id #2). "
|
||||
+ "The function 'States.Format('{}', $.nope)' had the following error: "
|
||||
+ "The JsonPath argument for the field '$.nope' could not be found in the input "
|
||||
+ "'{\"items\":[1,2]}'",
|
||||
describe.jsonPath().getString("cause"));
|
||||
|
||||
+4
-2
@@ -247,7 +247,8 @@ class StepFunctionsJsonataFunctionsIntegrationTest {
|
||||
Response resp = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", resp.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$sum(['a'])' specified for the field 'Output/v' threw an error "
|
||||
assertEquals("An error occurred while executing the state 'Sum' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$sum(['a'])' specified for the field 'Output/v' threw an error "
|
||||
+ "during evaluation. T0412: Argument [\"a\"] must be an array of \"numbers\"",
|
||||
resp.jsonPath().getString("cause"));
|
||||
}
|
||||
@@ -277,7 +278,8 @@ class StepFunctionsJsonataFunctionsIntegrationTest {
|
||||
Response resp = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", resp.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$abs(\"x\")' specified for the field 'Output/v' threw an error "
|
||||
assertEquals("An error occurred while executing the state 'Abs' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$abs(\"x\")' specified for the field 'Output/v' threw an error "
|
||||
+ "during evaluation. T0410: Argument 1 of function \"abs\" does not match function signature",
|
||||
resp.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
+32
-16
@@ -619,7 +619,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", failure.jsonPath().getString("status"));
|
||||
assertEquals("States.ItemReaderFailed", failure.jsonPath().getString("error"));
|
||||
assertEquals("The provided ReaderConfig.ItemsPointer does not match any valid path in the JSON structure.",
|
||||
assertEquals("An error occurred while executing the state 'ProcessWorkers' (entered at the event id #2). "
|
||||
+ "The provided ReaderConfig.ItemsPointer does not match any valid path in the JSON structure.",
|
||||
failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -672,7 +673,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", failure.jsonPath().getString("status"));
|
||||
assertEquals("States.ItemReaderFailed", failure.jsonPath().getString("error"));
|
||||
assertEquals("Attempting to map over non-iterable node.", failure.jsonPath().getString("cause"));
|
||||
assertEquals("An error occurred while executing the state 'ProcessWorkers' (entered at the event id #2). "
|
||||
+ "Attempting to map over non-iterable node.", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -770,7 +772,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", failure.jsonPath().getString("status"));
|
||||
assertEquals("States.Runtime", failure.jsonPath().getString("error"));
|
||||
assertEquals("The ItemReader, ItemBatcher and ResultWriter fields are not supported for INLINE maps",
|
||||
assertEquals("An error occurred while executing the state 'ProcessWorkers' (entered at the event id #2). "
|
||||
+ "The ItemReader, ItemBatcher and ResultWriter fields are not supported for INLINE maps",
|
||||
failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1295,7 +1298,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Output/v' "
|
||||
assertEquals("An error occurred while executing the state 'Transform' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Output/v' "
|
||||
+ "returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
|
||||
String catching = definition.replace("\"End\": true",
|
||||
@@ -1390,7 +1394,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Assign/x' "
|
||||
assertEquals("An error occurred while executing the state 'Bind' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Assign/x' "
|
||||
+ "returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1421,7 +1426,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field "
|
||||
assertEquals("An error occurred while executing the state 'Send' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field "
|
||||
+ "'Arguments/MessageGroupId' returned nothing (undefined).",
|
||||
failure.jsonPath().getString("cause"));
|
||||
}
|
||||
@@ -1454,7 +1460,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field "
|
||||
+ "'Choices[1]/Condition' returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1516,7 +1523,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field "
|
||||
+ "'Choices[1]/Output/v' returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1546,7 +1554,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field "
|
||||
+ "'Choices[0]/Assign/x' returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1586,7 +1595,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field "
|
||||
assertEquals("An error occurred while executing the state 'Boom' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field "
|
||||
+ "'Catch[1]/Output/v' returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1608,7 +1618,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Seconds' "
|
||||
assertEquals("An error occurred while executing the state 'Pause' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Seconds' "
|
||||
+ "returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1631,14 +1642,16 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
createStateMachine("jsonata-fail-error-returned-nothing-test",
|
||||
definition.formatted("{% $states.input.missing %}", "boom")), "{}"));
|
||||
assertEquals("States.QueryEvaluationError", errorFailure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Error' "
|
||||
assertEquals("An error occurred while executing the state 'Stop' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Error' "
|
||||
+ "returned nothing (undefined).", errorFailure.jsonPath().getString("cause"));
|
||||
|
||||
Response causeFailure = waitForExecutionFailure(startExecution(
|
||||
createStateMachine("jsonata-fail-cause-returned-nothing-test",
|
||||
definition.formatted("Boom", "{% $states.input.missing %}")), "{}"));
|
||||
assertEquals("States.QueryEvaluationError", causeFailure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Cause' "
|
||||
assertEquals("An error occurred while executing the state 'Stop' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Cause' "
|
||||
+ "returned nothing (undefined).", causeFailure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1667,7 +1680,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Items' "
|
||||
assertEquals("An error occurred while executing the state 'Fan' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Items' "
|
||||
+ "returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1698,7 +1712,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field "
|
||||
assertEquals("An error occurred while executing the state 'Fan' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field "
|
||||
+ "'MaxConcurrency' returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
@@ -1758,7 +1773,8 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
Response failure = waitForExecutionFailure(startExecution(smArn, "{}"));
|
||||
|
||||
assertEquals("States.QueryEvaluationError", failure.jsonPath().getString("error"));
|
||||
assertEquals("The JSONata expression '$states.input.missing' specified for the field 'Output' "
|
||||
assertEquals("An error occurred while executing the state 'Transform' (entered at the event id #2). "
|
||||
+ "The JSONata expression '$states.input.missing' specified for the field 'Output' "
|
||||
+ "returned nothing (undefined).", failure.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
|
||||
+13
-4
@@ -117,7 +117,9 @@ class StepFunctionsTimeoutSecondsIntegrationTest {
|
||||
assertTrue(elapsedMillis < 3_000,
|
||||
"the branch's 3-second Wait outlasted the 1-second budget: " + elapsedMillis + " ms");
|
||||
JsonNode events = mapper.readTree(getExecutionHistory(execArn).body().asString()).path("events");
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ExecutionTimedOut"),
|
||||
// The branch's Wait was entered and never exited: the budget cut it.
|
||||
assertEquals(List.of("ExecutionStarted", "ParallelStateEntered", "ParallelStateStarted",
|
||||
"WaitStateEntered", "ExecutionTimedOut"),
|
||||
eventTypes(events), "history was " + events);
|
||||
}
|
||||
|
||||
@@ -224,8 +226,14 @@ class StepFunctionsTimeoutSecondsIntegrationTest {
|
||||
assertTrue(elapsedMillis < 5_000,
|
||||
"the iterations' 10-second Wait outlasted the 1-second budget: " + elapsedMillis + " ms");
|
||||
JsonNode events = mapper.readTree(getExecutionHistory(execArn).body().asString()).path("events");
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "ExecutionTimedOut"),
|
||||
eventTypes(events), "history was " + events);
|
||||
// Both iterations entered their Wait and neither exited it. They run concurrently, so
|
||||
// the order their events interleave in is theirs to choose.
|
||||
List<String> types = eventTypes(events);
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted"), types.subList(0, 3),
|
||||
"history was " + events);
|
||||
assertEquals(List.of("MapIterationStarted", "MapIterationStarted", "WaitStateEntered", "WaitStateEntered"),
|
||||
types.subList(3, 7).stream().sorted().toList(), "history was " + events);
|
||||
assertEquals(List.of("ExecutionTimedOut"), types.subList(7, types.size()), "history was " + events);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,7 +267,8 @@ class StepFunctionsTimeoutSecondsIntegrationTest {
|
||||
assertTrue(elapsedMillis < 5_000,
|
||||
"the single iteration's 10-second Wait outlasted the 1-second budget: " + elapsedMillis + " ms");
|
||||
JsonNode events = mapper.readTree(getExecutionHistory(execArn).body().asString()).path("events");
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "ExecutionTimedOut"),
|
||||
assertEquals(List.of("ExecutionStarted", "MapStateEntered", "MapStateStarted", "MapIterationStarted",
|
||||
"WaitStateEntered", "ExecutionTimedOut"),
|
||||
eventTypes(events), "history was " + events);
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -38,7 +38,8 @@ class StepFunctionsUnresolvableJsonPathIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", describe.jsonPath().getString("status"), describe.body().asString());
|
||||
assertEquals("States.Runtime", describe.jsonPath().getString("error"));
|
||||
assertEquals("The JSONPath '$.nope.deep' specified for the field 'missing.$' could not "
|
||||
assertEquals("An error occurred while executing the state 'Pick' (entered at the event id #2). "
|
||||
+ "The JSONPath '$.nope.deep' specified for the field 'missing.$' could not "
|
||||
+ "be found in the input '{\"other\":1}'",
|
||||
describe.jsonPath().getString("cause"));
|
||||
}
|
||||
@@ -92,7 +93,8 @@ class StepFunctionsUnresolvableJsonPathIntegrationTest {
|
||||
|
||||
assertEquals("FAILED", describe.jsonPath().getString("status"), describe.body().asString());
|
||||
assertEquals("States.Runtime", describe.jsonPath().getString("error"));
|
||||
assertEquals("The JSONPath '$.nope' specified for the field 'missing.$' could not be "
|
||||
assertEquals("An error occurred while executing the state 'M' (entered at the event id #2). "
|
||||
+ "The JSONPath '$.nope' specified for the field 'missing.$' could not be "
|
||||
+ "found in the input '[1,2]'",
|
||||
describe.jsonPath().getString("cause"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user