|
19 | 19 |
|
20 | 20 | import static org.junit.Assert.assertEquals;
|
21 | 21 | import static org.junit.Assert.assertFalse;
|
| 22 | +import static org.junit.Assert.assertNotEquals; |
| 23 | +import static org.junit.Assert.assertNotNull; |
22 | 24 | import static org.junit.Assert.assertNull;
|
23 | 25 | import static org.junit.Assert.assertTrue;
|
24 | 26 | import static org.junit.Assert.fail;
|
@@ -1011,6 +1013,73 @@ public void testChildAsyncWorkflow() {
|
1011 | 1013 | assertEquals(null, client.execute(taskList));
|
1012 | 1014 | }
|
1013 | 1015 |
|
| 1016 | + // This workflow is designed specifically for testing some internal logic in Async.procedure |
| 1017 | + // and ChildWorkflowStubImpl. See comments on testChildAsyncLambdaWorkflow for more details. |
| 1018 | + public interface WaitOnSignalWorkflow { |
| 1019 | + |
| 1020 | + @WorkflowMethod() |
| 1021 | + void execute(); |
| 1022 | + |
| 1023 | + @SignalMethod |
| 1024 | + void signal(String value); |
| 1025 | + } |
| 1026 | + |
| 1027 | + public static class TestWaitOnSignalWorkflowImpl implements WaitOnSignalWorkflow { |
| 1028 | + private final CompletablePromise<String> signal = Workflow.newPromise(); |
| 1029 | + |
| 1030 | + @Override |
| 1031 | + public void execute() { |
| 1032 | + signal.get(); |
| 1033 | + } |
| 1034 | + |
| 1035 | + @Override |
| 1036 | + public void signal(String value) { |
| 1037 | + signal.complete(value); |
| 1038 | + } |
| 1039 | + } |
| 1040 | + |
| 1041 | + public static class TestChildAsyncLambdaWorkflow implements TestWorkflow1 { |
| 1042 | + |
| 1043 | + @Override |
| 1044 | + public String execute(String taskList) { |
| 1045 | + ChildWorkflowOptions workflowOptions = |
| 1046 | + new ChildWorkflowOptions.Builder() |
| 1047 | + .setExecutionStartToCloseTimeout(Duration.ofSeconds(100)) |
| 1048 | + .setTaskStartToCloseTimeout(Duration.ofSeconds(60)) |
| 1049 | + .setTaskList(taskList) |
| 1050 | + .build(); |
| 1051 | + |
| 1052 | + WaitOnSignalWorkflow child = |
| 1053 | + Workflow.newChildWorkflowStub(WaitOnSignalWorkflow.class, workflowOptions); |
| 1054 | + Promise<Void> promise = Async.procedure(() -> child.execute()); |
| 1055 | + Promise<WorkflowExecution> executionPromise = Workflow.getWorkflowExecution(child); |
| 1056 | + assertNotNull(executionPromise); |
| 1057 | + WorkflowExecution execution = executionPromise.get(); |
| 1058 | + assertNotEquals("", execution.getWorkflowId()); |
| 1059 | + assertNotEquals("", execution.getRunId()); |
| 1060 | + child.signal("test"); |
| 1061 | + |
| 1062 | + promise.get(); |
| 1063 | + return null; |
| 1064 | + } |
| 1065 | + } |
| 1066 | + |
| 1067 | + // The purpose of this test is to exercise the lambda execution logic inside Async.procedure(), |
| 1068 | + // which executes on a different thread than workflow-main. This is different than executing |
| 1069 | + // classes that implements the workflow method interface, which executes on the workflow main |
| 1070 | + // thread. |
| 1071 | + @Test |
| 1072 | + public void testChildAsyncLambdaWorkflow() { |
| 1073 | + startWorkerFor(TestChildAsyncLambdaWorkflow.class, TestWaitOnSignalWorkflowImpl.class); |
| 1074 | + |
| 1075 | + WorkflowOptions.Builder options = new WorkflowOptions.Builder(); |
| 1076 | + options.setExecutionStartToCloseTimeout(Duration.ofSeconds(200)); |
| 1077 | + options.setTaskStartToCloseTimeout(Duration.ofSeconds(60)); |
| 1078 | + options.setTaskList(taskList); |
| 1079 | + TestWorkflow1 client = workflowClient.newWorkflowStub(TestWorkflow1.class, options.build()); |
| 1080 | + assertEquals(null, client.execute(taskList)); |
| 1081 | + } |
| 1082 | + |
1014 | 1083 | public static class TestUntypedChildStubWorkflow implements TestWorkflow1 {
|
1015 | 1084 |
|
1016 | 1085 | @Override
|
|
0 commit comments