mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(sfn): resolve Reference Paths rooted at the Context Object (#4445)
* fix(sfn): resolve Reference Paths rooted at the Context Object ASL accepts a string_sampler wherever it accepts a Reference Path, and a Context Object path ($$) is one of its three spellings, so a definition that deploys on AWS was rejected or silently mishandled here. Validation rejected $$ outright. isReferencePath required a $-rooted path, so CreateStateMachine answered "Value is not a Reference Path" for the six Map numeric path fields (MaxConcurrencyPath, MaxItemsPath, ToleratedFailureCountPath, ToleratedFailurePercentagePath and the two ItemBatcher ones). The walk now strips a $$ root and keeps the existing strictness that rejects wildcards, filters and slices. Resolution never saw the Context Object. Five sites called the context-free resolvePath overload, so an accepted $$ path resolved to a missing node: InputPath narrowed the state input to null, OutputPath returned null, Wait's SecondsPath fell through without waiting at all, Wait's TimestampPath failed with "Invalid Timestamp: null", and the ItemReader's MaxItemsPath failed with "MaxItems must resolve to an integer of 0 or more", each blaming the value rather than the unresolved path. applyInputPath and applyOutputPath now take the Context Object and it is threaded through all fifteen state-handler call sites, each of which already received it. StepFunctionsValidateStateMachineDefinitionIntegrationTest used "$$.Execution.Input.count" as its example of an invalid Reference Path, so the test pinned the defect and CI stayed green while the behaviour was wrong. It now uses "$.counts[*]", which is genuinely not a Reference Path, and that assertion still passes against the unpatched validator. Grammar reference: ASLParser.g4 input_path_decl:85, output_path_decl:91, seconds_path:110, timestamp_path:115, max_concurrency_path:128, max_items_path:330, tolerated_failure_count_path:336, tolerated_failure_percentage_path:342, all string_sampler at :475. * test(sfn): pin Context Object Wait paths through the sleeper seam and execute Map batch and tolerance paths The two Wait cases timed the whole execution from the client, so setup and polling counted toward the wait and they spent about two seconds proving a path resolves. They now live in AslExecutorWaitStateTest, where the fixed clock and recording sleeper assert the exact requested pause for SecondsPath and TimestampPath rooted at $$. MaxItemsPerBatchPath and ToleratedFailureCountPath were only validated with a $$ root; two execution cases now run a distributed Map that reads each from the Context Object, with InputPath narrowing the input so a resolver that sees only the state input cannot pass. applyOutputPath drops its state-input parameter, which it never read.
This commit is contained in:
1 parent
f51679c1f6
commit
7a583cc293
7 files changed
+313
-25
No files matched your search
@@ -740,7 +740,7 @@ public class AslExecutor {
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
|
||||
JsonNode effectiveInput = applyInputPath(stateDef, input);
|
||||
JsonNode effectiveInput = applyInputPath(stateDef, input, context);
|
||||
|
||||
// Pass states transform their input through Parameters (with intrinsics), then a static
|
||||
// Result overrides if present.
|
||||
@@ -753,7 +753,7 @@ public class AslExecutor {
|
||||
}
|
||||
|
||||
JsonNode output = mergeResult(stateDef, input, result);
|
||||
output = applyOutputPath(stateDef, input, output);
|
||||
output = applyOutputPath(stateDef, output, context);
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
|
||||
@@ -787,7 +787,7 @@ public class AslExecutor {
|
||||
stateDef.get("Arguments"), "Arguments", statesVar, variables);
|
||||
}
|
||||
} else {
|
||||
effectiveInput = applyInputPath(stateDef, input);
|
||||
effectiveInput = applyInputPath(stateDef, input, context);
|
||||
if (stateDef.has("Parameters")) {
|
||||
effectiveInput = resolveParameters(stateDef.get("Parameters"), effectiveInput, context);
|
||||
}
|
||||
@@ -849,7 +849,7 @@ public class AslExecutor {
|
||||
taskResult = resolveParameters(stateDef.get("ResultSelector"), taskResult, context);
|
||||
}
|
||||
JsonNode output = mergeResult(stateDef, input, taskResult);
|
||||
output = applyOutputPath(stateDef, input, output);
|
||||
output = applyOutputPath(stateDef, output, context);
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
}
|
||||
@@ -2241,18 +2241,18 @@ public class AslExecutor {
|
||||
throw new FailStateException("States.Runtime", NO_NEXT_STATE_CAUSE);
|
||||
}
|
||||
|
||||
JsonNode effectiveInput = applyInputPath(stateDef, input);
|
||||
JsonNode effectiveInput = applyInputPath(stateDef, input, context);
|
||||
JsonNode choices = stateDef.path("Choices");
|
||||
for (JsonNode choice : choices) {
|
||||
if (evaluateCondition(choice, effectiveInput, context)) {
|
||||
JsonNode output = applyOutputPath(stateDef, input, effectiveInput);
|
||||
JsonNode output = applyOutputPath(stateDef, effectiveInput, context);
|
||||
return new StateResult(output, choice.path("Next").asText());
|
||||
}
|
||||
}
|
||||
// Default branch
|
||||
String defaultState = stateDef.path("Default").asText(null);
|
||||
if (defaultState != null) {
|
||||
JsonNode output = applyOutputPath(stateDef, input, effectiveInput);
|
||||
JsonNode output = applyOutputPath(stateDef, effectiveInput, context);
|
||||
return new StateResult(output, defaultState);
|
||||
}
|
||||
throw new FailStateException("States.Runtime", NO_NEXT_STATE_CAUSE);
|
||||
@@ -2298,16 +2298,16 @@ public class AslExecutor {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
effectiveInput = applyInputPath(stateDef, input);
|
||||
effectiveInput = applyInputPath(stateDef, input, context);
|
||||
if (stateDef.has("Seconds")) {
|
||||
waitNanos = secondsToNanos(stateDef.get("Seconds").asLong());
|
||||
} else if (stateDef.has("SecondsPath")) {
|
||||
JsonNode val = resolvePath(stateDef.get("SecondsPath").asText(), effectiveInput);
|
||||
JsonNode val = resolvePath(stateDef.get("SecondsPath").asText(), effectiveInput, context);
|
||||
waitNanos = secondsToNanos(val.asLong());
|
||||
} else if (stateDef.has("Timestamp")) {
|
||||
waitNanos = nanosUntil(stateDef.get("Timestamp").asText());
|
||||
} else if (stateDef.has("TimestampPath")) {
|
||||
JsonNode val = resolvePath(stateDef.get("TimestampPath").asText(), effectiveInput);
|
||||
JsonNode val = resolvePath(stateDef.get("TimestampPath").asText(), effectiveInput, context);
|
||||
waitNanos = nanosUntil(val.asText());
|
||||
}
|
||||
}
|
||||
@@ -2318,7 +2318,7 @@ public class AslExecutor {
|
||||
JsonNode output = applyJsonataOutput(stateDef, input, null, context, variables);
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
JsonNode output = applyOutputPath(stateDef, input, effectiveInput);
|
||||
JsonNode output = applyOutputPath(stateDef, effectiveInput, context);
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
|
||||
@@ -2378,8 +2378,8 @@ public class AslExecutor {
|
||||
JsonNode output = applyJsonataOutput(stateDef, input, input, context, variables);
|
||||
return new StateResult(output, null);
|
||||
}
|
||||
JsonNode effectiveInput = applyInputPath(stateDef, input);
|
||||
return new StateResult(applyOutputPath(stateDef, input, effectiveInput), null);
|
||||
JsonNode effectiveInput = applyInputPath(stateDef, input, context);
|
||||
return new StateResult(applyOutputPath(stateDef, effectiveInput, context), null);
|
||||
}
|
||||
|
||||
private StateResult executeFail(JsonNode stateDef, JsonNode input, boolean jsonata, JsonNode context,
|
||||
@@ -2428,7 +2428,7 @@ public class AslExecutor {
|
||||
String topLevelQueryLanguage, JsonNode context,
|
||||
ObjectNode variables, long executionDeadlineNanos)
|
||||
throws Exception {
|
||||
JsonNode effectiveInput = jsonata ? input : applyInputPath(stateDef, input);
|
||||
JsonNode effectiveInput = jsonata ? input : applyInputPath(stateDef, input, context);
|
||||
JsonNode branches = stateDef.path("Branches");
|
||||
chain.publish("ParallelStateStarted", null);
|
||||
var branchChains = new ArrayList<HistoryChain>();
|
||||
@@ -2519,7 +2519,7 @@ public class AslExecutor {
|
||||
? resolveParameters(stateDef.get("ResultSelector"), results, context)
|
||||
: results;
|
||||
JsonNode output = mergeResult(stateDef, input, selected);
|
||||
output = applyOutputPath(stateDef, input, output);
|
||||
output = applyOutputPath(stateDef, output, context);
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
|
||||
@@ -2559,7 +2559,7 @@ public class AslExecutor {
|
||||
|
||||
// Map input-processing fields, including ItemsPath and MaxConcurrencyPath, resolve against
|
||||
// the effective state input after InputPath has been applied.
|
||||
JsonNode mapInput = applyInputPath(stateDef, input);
|
||||
JsonNode mapInput = applyInputPath(stateDef, input, context);
|
||||
ResolvedMapItems resolvedItems = resolveMapItems(stateDef, mapInput, jsonata, context, variables);
|
||||
JsonNode items = resolvedItems.items();
|
||||
|
||||
@@ -2767,7 +2767,7 @@ public class AslExecutor {
|
||||
? resolveParameters(stateDef.get("ResultSelector"), mapResult, context)
|
||||
: mapResult;
|
||||
JsonNode output = mergeResult(stateDef, input, selected);
|
||||
output = applyOutputPath(stateDef, input, output);
|
||||
output = applyOutputPath(stateDef, output, context);
|
||||
return new StateResult(output, stateDef.path("Next").asText(null));
|
||||
}
|
||||
|
||||
@@ -2775,14 +2775,16 @@ public class AslExecutor {
|
||||
* Resolves an integer Map field from its literal, {@code <field>Path} or JSONata expression form,
|
||||
* as MaxConcurrency and the ItemBatcher limits all take. An absent field is 0. {@code minimum} is
|
||||
* the smallest accepted value, which is what separates MaxConcurrency, where 0 means the service
|
||||
* ceiling, from a batch limit, where it is meaningless.
|
||||
* ceiling, from a batch limit, where it is meaningless. The {@code <field>Path} form is a
|
||||
* Reference Path, so it reads the Context Object as readily as the state input and the resolver
|
||||
* is given both.
|
||||
*/
|
||||
private int resolveMapIntegerField(JsonNode container, String field, int minimum, JsonNode mapInput,
|
||||
boolean jsonata, JsonNode context, ObjectNode variables) {
|
||||
JsonNode value;
|
||||
boolean jsonataExpression = false;
|
||||
if (container.has(field + "Path")) {
|
||||
value = resolvePath(container.get(field + "Path").asText(), mapInput);
|
||||
value = resolvePath(container.get(field + "Path").asText(), mapInput, context);
|
||||
} else if (container.has(field)) {
|
||||
value = container.get(field);
|
||||
if (jsonata && value.isTextual() && JsonataEvaluator.isExpression(value.asText())) {
|
||||
@@ -3431,7 +3433,7 @@ public class AslExecutor {
|
||||
&& readerConfig.get("MaxItems").isTextual()
|
||||
&& JsonataEvaluator.isExpression(readerConfig.get("MaxItems").asText());
|
||||
if (hasMaxItemsPath) {
|
||||
JsonNode value = resolvePath(readerConfig.get("MaxItemsPath").asText(), mapInput);
|
||||
JsonNode value = resolvePath(readerConfig.get("MaxItemsPath").asText(), mapInput, context);
|
||||
long maxItems;
|
||||
try {
|
||||
maxItems = Long.parseLong(value.asText());
|
||||
@@ -3710,7 +3712,12 @@ public class AslExecutor {
|
||||
|
||||
// ──────────────────────────── Path resolution ────────────────────────────
|
||||
|
||||
private JsonNode applyInputPath(JsonNode stateDef, JsonNode input) {
|
||||
/**
|
||||
* {@code InputPath} is a Reference Path, so it may be rooted at the Context Object as well as
|
||||
* at the state input; {@code context} is what makes a {@code $$} path resolve instead of
|
||||
* narrowing the input to null.
|
||||
*/
|
||||
private JsonNode applyInputPath(JsonNode stateDef, JsonNode input, JsonNode context) {
|
||||
if (!stateDef.has("InputPath")) {
|
||||
return input;
|
||||
}
|
||||
@@ -3718,7 +3725,7 @@ public class AslExecutor {
|
||||
if (path == null || path.equals("null")) {
|
||||
return objectMapper.createObjectNode();
|
||||
}
|
||||
return resolvePath(path, input);
|
||||
return resolvePath(path, input, context);
|
||||
}
|
||||
|
||||
private JsonNode mergeResult(JsonNode stateDef, JsonNode input, JsonNode result) throws Exception {
|
||||
@@ -3735,7 +3742,8 @@ public class AslExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private JsonNode applyOutputPath(JsonNode stateDef, JsonNode input, JsonNode output) {
|
||||
/** {@code OutputPath} is a Reference Path, so it reads the Context Object as InputPath does. */
|
||||
private JsonNode applyOutputPath(JsonNode stateDef, JsonNode output, JsonNode context) {
|
||||
if (!stateDef.has("OutputPath")) {
|
||||
return output;
|
||||
}
|
||||
@@ -3743,7 +3751,7 @@ public class AslExecutor {
|
||||
if (path == null || path.equals("null")) {
|
||||
return objectMapper.createObjectNode();
|
||||
}
|
||||
return resolvePath(path, output);
|
||||
return resolvePath(path, output, context);
|
||||
}
|
||||
|
||||
JsonNode resolveParameters(JsonNode parameters, JsonNode input, JsonNode context) throws Exception {
|
||||
|
||||
+9
@@ -2671,10 +2671,19 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Reference Path selects a single node, so wildcards, filters and slices are rejected. The
|
||||
* root is either the state input ({@code $}) or the Context Object ({@code $$}): ASL takes a
|
||||
* {@code string_sampler} wherever it takes a Reference Path, and a context path is one of its
|
||||
* spellings, so {@code "$$.Execution.Input.count"} is as valid as {@code "$.count"}.
|
||||
*/
|
||||
private static boolean isReferencePath(String path) {
|
||||
if (path == null || path.isEmpty() || path.charAt(0) != '$') {
|
||||
return false;
|
||||
}
|
||||
if (path.startsWith("$$")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
int index = 1;
|
||||
while (index < path.length()) {
|
||||
if (path.charAt(index) == '.') {
|
||||
|
||||
+34
@@ -95,6 +95,40 @@ class AslExecutorWaitStateTest {
|
||||
assertEquals(TimeUnit.SECONDS.toNanos(20), sleeper.singleSleep());
|
||||
}
|
||||
|
||||
/**
|
||||
* SecondsPath is a Reference Path, so {@code $$} reads the Context Object. InputPath narrows the
|
||||
* state input to a subtree without the delay, so a resolver that sees only the input finds
|
||||
* nothing and never sleeps.
|
||||
*/
|
||||
@Test
|
||||
void secondsPathReadsTheContextObject() {
|
||||
RecordingSleeper sleeper = new RecordingSleeper();
|
||||
AslExecutor executor = newExecutor(sleeper, 120);
|
||||
|
||||
Execution execution = run(executor, """
|
||||
{"StartAt":"W","States":{"W":{"Type":"Wait","InputPath":"$.payload",
|
||||
"SecondsPath":"$$.Execution.Input.delay","End":true}}}
|
||||
""", "{\"delay\":45,\"payload\":{\"kept\":true}}");
|
||||
|
||||
assertEquals("SUCCEEDED", execution.getStatus());
|
||||
assertEquals(TimeUnit.SECONDS.toNanos(45), sleeper.singleSleep());
|
||||
}
|
||||
|
||||
@Test
|
||||
void timestampPathReadsTheContextObject() {
|
||||
RecordingSleeper sleeper = new RecordingSleeper();
|
||||
AslExecutor executor = newExecutor(sleeper, 120);
|
||||
Instant wake = NOW.plusSeconds(20);
|
||||
|
||||
Execution execution = run(executor, """
|
||||
{"StartAt":"W","States":{"W":{"Type":"Wait","InputPath":"$.payload",
|
||||
"TimestampPath":"$$.Execution.Input.until","End":true}}}
|
||||
""", "{\"until\":\"" + wake + "\",\"payload\":{\"kept\":true}}");
|
||||
|
||||
assertEquals("SUCCEEDED", execution.getStatus());
|
||||
assertEquals(TimeUnit.SECONDS.toNanos(20), sleeper.singleSleep());
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonataLiteralTimestampWaitsUntilThatInstant() {
|
||||
RecordingSleeper sleeper = new RecordingSleeper();
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* ASL takes a {@code string_sampler} wherever it takes a Reference Path, and a Context Object path
|
||||
* ({@code $$}) is one of its spellings, so the fields below read the Context Object as readily as
|
||||
* the state input. Each case narrows the state input with {@code InputPath} or starts from an input
|
||||
* that does not carry the value, so a resolver that only ever sees the state input cannot pass.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class StepFunctionsContextObjectPathIntegrationTest {
|
||||
|
||||
private static final String SFN_CONTENT_TYPE = "application/x-amz-json-1.0";
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/test-role";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void inputPathSelectsFromTheContextObject() throws Exception {
|
||||
String definition = """
|
||||
{"StartAt":"P","States":{"P":{"Type":"Pass",
|
||||
"InputPath":"$$.Execution.Input.payload","End":true}}}
|
||||
""";
|
||||
|
||||
JsonNode output = mapper.readTree(run(definition, "{\"payload\":{\"kept\":true}}"));
|
||||
|
||||
assertTrue(output.path("kept").asBoolean(), "InputPath must select the context subtree");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outputPathSelectsFromTheContextObject() throws Exception {
|
||||
String definition = """
|
||||
{"StartAt":"P","States":{"P":{"Type":"Pass",
|
||||
"OutputPath":"$$.Execution.Input.wanted","End":true}}}
|
||||
""";
|
||||
|
||||
JsonNode output = mapper.readTree(run(definition, "{\"wanted\":{\"value\":7},\"noise\":1}"));
|
||||
|
||||
assertEquals(7, output.path("value").asInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemBatcher's MaxItemsPerBatchPath is a Reference Path. InputPath narrows the state input to
|
||||
* the items, so the batch size exists only on the Context Object.
|
||||
*/
|
||||
@Test
|
||||
void itemBatcherMaxItemsPerBatchPathReadsTheContextObject() throws Exception {
|
||||
String definition = """
|
||||
{"StartAt":"M","States":{"M":{"Type":"Map",
|
||||
"InputPath":"$.payload","ItemsPath":"$.items",
|
||||
"ItemBatcher":{"MaxItemsPerBatchPath":"$$.Execution.Input.batch"},
|
||||
"ItemProcessor":{"ProcessorConfig":{"Mode":"DISTRIBUTED","ExecutionType":"STANDARD"},
|
||||
"StartAt":"P","States":{"P":{"Type":"Pass","End":true}}},
|
||||
"End":true}}}
|
||||
""";
|
||||
|
||||
JsonNode batches = mapper.readTree(run(definition,
|
||||
"{\"batch\":2,\"payload\":{\"items\":[{\"n\":1},{\"n\":2},{\"n\":3},{\"n\":4},{\"n\":5}]}}"));
|
||||
|
||||
assertEquals(3, batches.size(), "batches: " + batches);
|
||||
assertEquals(2, batches.get(0).path("Items").size());
|
||||
assertEquals(2, batches.get(1).path("Items").size());
|
||||
assertEquals(1, batches.get(2).path("Items").size());
|
||||
}
|
||||
|
||||
/**
|
||||
* ToleratedFailureCountPath is a Reference Path. One item fails, and the Map succeeds only if
|
||||
* the tolerance of one is read from the Context Object; the narrowed input does not carry it.
|
||||
*/
|
||||
@Test
|
||||
void toleratedFailureCountPathReadsTheContextObject() throws Exception {
|
||||
String definition = """
|
||||
{"StartAt":"M","States":{"M":{"Type":"Map",
|
||||
"InputPath":"$.payload","ItemsPath":"$.items",
|
||||
"ToleratedFailureCountPath":"$$.Execution.Input.tolerate",
|
||||
"ItemProcessor":{"ProcessorConfig":{"Mode":"DISTRIBUTED","ExecutionType":"STANDARD"},
|
||||
"StartAt":"Check","States":{
|
||||
"Check":{"Type":"Choice",
|
||||
"Choices":[{"Variable":"$.n","NumericLessThan":0,"Next":"Boom"}],
|
||||
"Default":"Keep"},
|
||||
"Boom":{"Type":"Fail","Error":"ItemFailed"},
|
||||
"Keep":{"Type":"Pass","End":true}}},
|
||||
"End":true}}}
|
||||
""";
|
||||
|
||||
JsonNode results = mapper.readTree(run(definition,
|
||||
"{\"tolerate\":1,\"payload\":{\"items\":[{\"n\":1},{\"n\":-1},{\"n\":3}]}}"));
|
||||
|
||||
assertEquals(2, results.size(), "results: " + results);
|
||||
}
|
||||
|
||||
private String run(String definition, String input) throws InterruptedException {
|
||||
String name = "context-path-" + System.nanoTime();
|
||||
Response create = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body("{\"name\":\"" + name + "\",\"definition\":" + quote(definition)
|
||||
+ ",\"roleArn\":\"" + ROLE_ARN + "\"}")
|
||||
.when().post("/");
|
||||
create.then().statusCode(200);
|
||||
String smArn = create.jsonPath().getString("stateMachineArn");
|
||||
|
||||
Response start = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.StartExecution")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body("{\"stateMachineArn\":\"" + smArn + "\",\"input\":" + quote(input) + "}")
|
||||
.when().post("/");
|
||||
start.then().statusCode(200);
|
||||
String execArn = start.jsonPath().getString("executionArn");
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Response describe = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.DescribeExecution")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body("{\"executionArn\":\"" + execArn + "\"}")
|
||||
.when().post("/");
|
||||
String status = describe.jsonPath().getString("status");
|
||||
if ("SUCCEEDED".equals(status)) {
|
||||
return describe.jsonPath().getString("output");
|
||||
}
|
||||
if ("FAILED".equals(status)) {
|
||||
fail("Execution failed: " + describe.body().asString());
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
fail("Execution did not complete");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String quote(String raw) {
|
||||
return "\"" + raw.replace("\\", "\\\\").replace("\"", "\\\"")
|
||||
.replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t") + "\"";
|
||||
}
|
||||
}
|
||||
+52
@@ -468,6 +468,58 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
assertFalse(output.contains("\"workerId\":\"w3\"") || output.contains("\"workerId\": \"w3\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapWithS3JsonItemReader_maxItemsPathReadsTheContextObject() throws Exception {
|
||||
createBucket("map-inputs-max-items-context-path");
|
||||
putObject("map-inputs-max-items-context-path", "workers.json", """
|
||||
[{"workerId":"w1"},{"workerId":"w2"},{"workerId":"w3"}]
|
||||
""");
|
||||
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "ProcessWorkers",
|
||||
"States": {
|
||||
"ProcessWorkers": {
|
||||
"Type": "Map",
|
||||
"ItemReader": {
|
||||
"Resource": "arn:aws:states:::s3:getObject",
|
||||
"ReaderConfig": {
|
||||
"InputType": "JSON",
|
||||
"MaxItemsPath": "$$.Execution.Input.limit"
|
||||
},
|
||||
"Parameters": {
|
||||
"Bucket": "map-inputs-max-items-context-path",
|
||||
"Key": "workers.json"
|
||||
}
|
||||
},
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {
|
||||
"Mode": "DISTRIBUTED",
|
||||
"ExecutionType": "STANDARD"
|
||||
},
|
||||
"StartAt": "PassItem",
|
||||
"States": {
|
||||
"PassItem": {
|
||||
"Type": "Pass",
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String smArn = createStateMachine("map-itemreader-s3-max-items-context-path-test", definition);
|
||||
String execArn = startExecution(smArn, "{\"limit\":2}");
|
||||
String output = waitForExecution(execArn);
|
||||
|
||||
assertTrue(output.contains("\"workerId\":\"w1\"") || output.contains("\"workerId\": \"w1\""));
|
||||
assertTrue(output.contains("\"workerId\":\"w2\"") || output.contains("\"workerId\": \"w2\""));
|
||||
assertFalse(output.contains("\"workerId\":\"w3\"") || output.contains("\"workerId\": \"w3\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapWithS3JsonItemReader_maxItemsLimitsObjectDataset() throws Exception {
|
||||
createBucket("map-inputs-max-items-object");
|
||||
|
||||
+15
@@ -83,6 +83,21 @@ class StepFunctionsMapConcurrencyIntegrationTest {
|
||||
+ "\"MaxConcurrencyPath\":\"$.config.['max-limit']\","), input), 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Reference Path may be rooted at the Context Object, so MaxConcurrencyPath reads
|
||||
* {@code $$.Execution.Input} even though InputPath has narrowed the state input to a subtree
|
||||
* that does not contain the limit.
|
||||
*/
|
||||
@Test
|
||||
void mapResolvesMaxConcurrencyPathFromTheContextObject() throws Exception {
|
||||
String input = "{\"maxLimit\":2,\"payload\":{\"items\":["
|
||||
+ "{\"i\":0},{\"i\":1},{\"i\":2},{\"i\":3}]}}";
|
||||
|
||||
assertOrderedItems(run(mapDefWithConcurrencyField(
|
||||
"\"InputPath\":\"$.payload\","
|
||||
+ "\"MaxConcurrencyPath\":\"$$.Execution.Input.maxLimit\","), input), 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapResolvesItemsPathFromEffectiveInputWithoutResultWriter() throws Exception {
|
||||
String definition = """
|
||||
|
||||
+21
-1
@@ -452,7 +452,7 @@ class StepFunctionsValidateStateMachineDefinitionIntegrationTest {
|
||||
void mapNumberPathFieldsMustBeMutuallyExclusiveAndReferencePaths() {
|
||||
String def = mapDefinition("", "\"ItemBatcher\":{\"MaxItemsPerBatch\":2,"
|
||||
+ "\"MaxItemsPerBatchPath\":\"$.batch\"},"
|
||||
+ "\"ToleratedFailureCountPath\":\"$$.Execution.Input.count\",");
|
||||
+ "\"ToleratedFailureCountPath\":\"$.counts[*]\",");
|
||||
|
||||
validateDefinition(def)
|
||||
.then().statusCode(200)
|
||||
@@ -464,6 +464,26 @@ class StepFunctionsValidateStateMachineDefinitionIntegrationTest {
|
||||
.body("diagnostics[1].location", equalTo("/States/M/ToleratedFailureCountPath"));
|
||||
}
|
||||
|
||||
/**
|
||||
* ASL accepts a {@code string_sampler} wherever it accepts a Reference Path, and a Context
|
||||
* Object path is one of its spellings, so every Map numeric path field takes {@code $$.} as
|
||||
* readily as {@code $.}.
|
||||
*/
|
||||
@Test
|
||||
void mapNumberPathFieldsAcceptContextObjectPaths() {
|
||||
String def = mapDefinition("", "\"MaxConcurrencyPath\":\"$$.Execution.Input.limit\","
|
||||
+ "\"ItemBatcher\":{\"MaxItemsPerBatchPath\":\"$$.Execution.Input.batch\","
|
||||
+ "\"MaxInputBytesPerBatchPath\":\"$$.Execution.Input.bytes\"},"
|
||||
+ "\"ToleratedFailureCountPath\":\"$$.Execution.Input.count\","
|
||||
+ "\"ToleratedFailurePercentagePath\":\"$$.Execution.Input.percentage\","
|
||||
+ "\"ItemReader\":{\"ReaderConfig\":{\"MaxItemsPath\":\"$$.Execution.Input.max\"}},");
|
||||
|
||||
validateDefinition(def)
|
||||
.then().statusCode(200)
|
||||
.body("result", equalTo("OK"))
|
||||
.body("diagnostics", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapNumberLiteralsEnforcePercentageAndReaderMaximums() {
|
||||
String def = mapDefinition("", "\"ItemBatcher\":{\"MaxInputBytesPerBatch\":262145},"
|
||||
|
||||
Reference in new issue
Block a user