|
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;
|
|
46 | 48 | import com.uber.cadence.common.RetryOptions;
|
47 | 49 | import com.uber.cadence.converter.JsonDataConverter;
|
48 | 50 | import com.uber.cadence.internal.sync.DeterministicRunnerTest;
|
| 51 | +import com.uber.cadence.serviceclient.WorkflowServiceTChannel; |
49 | 52 | import com.uber.cadence.testing.TestEnvironmentOptions;
|
50 | 53 | import com.uber.cadence.testing.TestEnvironmentOptions.Builder;
|
51 | 54 | import com.uber.cadence.testing.TestWorkflowEnvironment;
|
@@ -140,6 +143,7 @@ protected void failed(Throwable e, Description description) {
|
140 | 143 | private TestWorkflowEnvironment testEnvironment;
|
141 | 144 | private ScheduledExecutorService scheduledExecutor;
|
142 | 145 | private List<ScheduledFuture<?>> delayedCallbacks = new ArrayList<>();
|
| 146 | + private static WorkflowServiceTChannel service = new WorkflowServiceTChannel(); |
143 | 147 |
|
144 | 148 | private static WorkflowOptions.Builder newWorkflowOptionsBuilder(String taskList) {
|
145 | 149 | return new WorkflowOptions.Builder()
|
@@ -173,7 +177,7 @@ public void setUp() {
|
173 | 177 | if (useExternalService) {
|
174 | 178 | WorkerOptions workerOptions =
|
175 | 179 | new WorkerOptions.Builder().setInterceptorFactory(tracer).build();
|
176 |
| - worker = new Worker(DOMAIN, taskList, workerOptions); |
| 180 | + worker = new Worker(service, DOMAIN, taskList, workerOptions); |
177 | 181 | workflowClient = WorkflowClient.newInstance(DOMAIN);
|
178 | 182 | WorkflowClientOptions clientOptions =
|
179 | 183 | new WorkflowClientOptions.Builder()
|
@@ -1011,6 +1015,73 @@ public void testChildAsyncWorkflow() {
|
1011 | 1015 | assertEquals(null, client.execute(taskList));
|
1012 | 1016 | }
|
1013 | 1017 |
|
| 1018 | + // This workflow is designed specifically for testing some internal logic in Async.procedure |
| 1019 | + // and ChildWorkflowStubImpl. See comments on testChildAsyncLambdaWorkflow for more details. |
| 1020 | + public interface WaitOnSignalWorkflow { |
| 1021 | + |
| 1022 | + @WorkflowMethod() |
| 1023 | + void execute(); |
| 1024 | + |
| 1025 | + @SignalMethod |
| 1026 | + void signal(String value); |
| 1027 | + } |
| 1028 | + |
| 1029 | + public static class TestWaitOnSignalWorkflowImpl implements WaitOnSignalWorkflow { |
| 1030 | + private final CompletablePromise<String> signal = Workflow.newPromise(); |
| 1031 | + |
| 1032 | + @Override |
| 1033 | + public void execute() { |
| 1034 | + signal.get(); |
| 1035 | + } |
| 1036 | + |
| 1037 | + @Override |
| 1038 | + public void signal(String value) { |
| 1039 | + signal.complete(value); |
| 1040 | + } |
| 1041 | + } |
| 1042 | + |
| 1043 | + public static class TestChildAsyncLambdaWorkflow implements TestWorkflow1 { |
| 1044 | + |
| 1045 | + @Override |
| 1046 | + public String execute(String taskList) { |
| 1047 | + ChildWorkflowOptions workflowOptions = |
| 1048 | + new ChildWorkflowOptions.Builder() |
| 1049 | + .setExecutionStartToCloseTimeout(Duration.ofSeconds(100)) |
| 1050 | + .setTaskStartToCloseTimeout(Duration.ofSeconds(60)) |
| 1051 | + .setTaskList(taskList) |
| 1052 | + .build(); |
| 1053 | + |
| 1054 | + WaitOnSignalWorkflow child = |
| 1055 | + Workflow.newChildWorkflowStub(WaitOnSignalWorkflow.class, workflowOptions); |
| 1056 | + Promise<Void> promise = Async.procedure(() -> child.execute()); |
| 1057 | + Promise<WorkflowExecution> executionPromise = Workflow.getWorkflowExecution(child); |
| 1058 | + assertNotNull(executionPromise); |
| 1059 | + WorkflowExecution execution = executionPromise.get(); |
| 1060 | + assertNotEquals("", execution.getWorkflowId()); |
| 1061 | + assertNotEquals("", execution.getRunId()); |
| 1062 | + child.signal("test"); |
| 1063 | + |
| 1064 | + promise.get(); |
| 1065 | + return null; |
| 1066 | + } |
| 1067 | + } |
| 1068 | + |
| 1069 | + // The purpose of this test is to exercise the lambda execution logic inside Async.procedure(), |
| 1070 | + // which executes on a different thread than workflow-main. This is different than executing |
| 1071 | + // classes that implements the workflow method interface, which executes on the workflow main |
| 1072 | + // thread. |
| 1073 | + @Test |
| 1074 | + public void testChildAsyncLambdaWorkflow() { |
| 1075 | + startWorkerFor(TestChildAsyncLambdaWorkflow.class, TestWaitOnSignalWorkflowImpl.class); |
| 1076 | + |
| 1077 | + WorkflowOptions.Builder options = new WorkflowOptions.Builder(); |
| 1078 | + options.setExecutionStartToCloseTimeout(Duration.ofSeconds(200)); |
| 1079 | + options.setTaskStartToCloseTimeout(Duration.ofSeconds(60)); |
| 1080 | + options.setTaskList(taskList); |
| 1081 | + TestWorkflow1 client = workflowClient.newWorkflowStub(TestWorkflow1.class, options.build()); |
| 1082 | + assertEquals(null, client.execute(taskList)); |
| 1083 | + } |
| 1084 | + |
1014 | 1085 | public static class TestUntypedChildStubWorkflow implements TestWorkflow1 {
|
1015 | 1086 |
|
1016 | 1087 | @Override
|
|
0 commit comments