-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNestedStepIntegrationTest.java
More file actions
67 lines (57 loc) · 2.92 KB
/
Copy pathNestedStepIntegrationTest.java
File metadata and controls
67 lines (57 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.lambda.durable;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import software.amazon.lambda.durable.config.StepConfig;
import software.amazon.lambda.durable.model.ExecutionStatus;
import software.amazon.lambda.durable.retry.RetryStrategies;
import software.amazon.lambda.durable.testing.LocalDurableTestRunner;
/** Tests that nested step calling is properly rejected. */
class NestedStepIntegrationTest {
@Test
void nestedStepCallingThrowsIllegalStateException() {
var runner = LocalDurableTestRunner.create(String.class, (input, context) -> {
// outer-step's supplier calls context.step() which internally calls stepAsync().get()
// The get() is called from the outer step's thread (named "1-step"), triggering the check
var future = context.stepAsync(
"outer-step",
String.class,
stepCtx -> context.step("inner-step", String.class, stepCtx2 -> "inner-result"),
StepConfig.builder()
.retryStrategy(RetryStrategies.Presets.NO_RETRY)
.build());
return future.get();
});
var result = runner.run("test");
assertEquals(ExecutionStatus.FAILED, result.getStatus());
var errorMessage = result.getError().get().errorMessage();
assertTrue(
errorMessage.contains("Nested STEP operation is not supported"),
"Expected error about nested step calling, got: " + errorMessage);
}
@Test
void awaitingAsyncStepInsideSyncStepThrowsIllegalStateException() {
var runner = LocalDurableTestRunner.create(String.class, (input, context) -> {
// Start async step from handler thread
var asyncFuture = context.stepAsync("async-step", String.class, stepCtx -> "async-result");
// Sync step tries to await the async step's result inside its supplier
return context.step(
"sync-step",
String.class,
stepCtx -> {
// This get() is called from sync-step's thread ("2-step"), which is not allowed
return "combined: " + asyncFuture.get();
},
StepConfig.builder()
.retryStrategy(RetryStrategies.Presets.NO_RETRY)
.build());
});
var result = runner.run("test");
assertEquals(ExecutionStatus.FAILED, result.getStatus());
var errorMessage = result.getError().get().errorMessage();
assertTrue(
errorMessage.contains("Nested STEP operation is not supported"),
"Expected error about nested step calling, got: " + errorMessage);
}
}