|
1 | 1 | package io.temporal.client.functional; |
2 | 2 |
|
| 3 | +import io.temporal.api.enums.v1.EventType; |
3 | 4 | import io.temporal.client.*; |
4 | 5 | import io.temporal.testing.internal.SDKTestWorkflowRule; |
5 | 6 | import io.temporal.workflow.Workflow; |
|
12 | 13 | public class WorkflowStubFirstExecutionRunIdTest { |
13 | 14 | @Rule |
14 | 15 | public SDKTestWorkflowRule testWorkflowRule = |
15 | | - SDKTestWorkflowRule.newBuilder() |
16 | | - .setUseExternalService(true) |
17 | | - .setWorkflowTypes(AwaitingWorkflow.class) |
18 | | - .build(); |
| 16 | + SDKTestWorkflowRule.newBuilder().setWorkflowTypes(AwaitingWorkflow.class).build(); |
19 | 17 |
|
20 | 18 | @Test |
21 | 19 | public void terminateFollowFirstRunId() throws InterruptedException { |
@@ -52,6 +50,73 @@ public void terminateFollowFirstRunId() throws InterruptedException { |
52 | 50 | () -> untyped.getResult(String.class)); |
53 | 51 | } |
54 | 52 |
|
| 53 | + @Test |
| 54 | + public void cancelFollowFirstRunId() throws InterruptedException { |
| 55 | + TestWorkflows.TestWorkflow1 workflow = |
| 56 | + testWorkflowRule.newWorkflowStub(TestWorkflows.TestWorkflow1.class); |
| 57 | + WorkflowClient.start(workflow::execute, "input1"); |
| 58 | + WorkflowStub untyped = WorkflowStub.fromTyped(workflow); |
| 59 | + // TODO wait for the continue as new to be visible |
| 60 | + Thread.sleep(1000); |
| 61 | + testWorkflowRule |
| 62 | + .getWorkflowClient() |
| 63 | + .newUntypedWorkflowStub( |
| 64 | + Optional.empty(), |
| 65 | + WorkflowTargetOptions.newBuilder().setWorkflowExecution(untyped.getExecution()).build()) |
| 66 | + .cancel(); |
| 67 | + testWorkflowRule.assertNoHistoryEvent( |
| 68 | + untyped.getExecution().getWorkflowId(), |
| 69 | + untyped.getExecution().getRunId(), |
| 70 | + EventType.EVENT_TYPE_WORKFLOW_EXECUTION_CANCEL_REQUESTED); |
| 71 | + |
| 72 | + testWorkflowRule |
| 73 | + .getWorkflowClient() |
| 74 | + .newUntypedWorkflowStub( |
| 75 | + Optional.empty(), |
| 76 | + WorkflowTargetOptions.newBuilder() |
| 77 | + .setWorkflowExecution(untyped.getExecution()) |
| 78 | + .setFirstExecutionRunId(untyped.getExecution().getRunId()) |
| 79 | + .build()) |
| 80 | + .cancel(); |
| 81 | + Assert.assertThrows( |
| 82 | + "Workflow should be cancelled", |
| 83 | + WorkflowFailedException.class, |
| 84 | + () -> untyped.getResult(String.class)); |
| 85 | + testWorkflowRule.assertHistoryEvent( |
| 86 | + untyped.getExecution().getWorkflowId(), |
| 87 | + EventType.EVENT_TYPE_WORKFLOW_EXECUTION_CANCEL_REQUESTED); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void signalRespectRunId() throws InterruptedException { |
| 92 | + TestWorkflows.TestWorkflow1 workflow = |
| 93 | + testWorkflowRule.newWorkflowStub(TestWorkflows.TestWorkflow1.class); |
| 94 | + WorkflowClient.start(workflow::execute, "input1"); |
| 95 | + WorkflowStub untyped = WorkflowStub.fromTyped(workflow); |
| 96 | + // TODO wait for the continue as new to be visible |
| 97 | + Thread.sleep(1000); |
| 98 | + Assert.assertThrows( |
| 99 | + WorkflowNotFoundException.class, |
| 100 | + () -> |
| 101 | + testWorkflowRule |
| 102 | + .getWorkflowClient() |
| 103 | + .newUntypedWorkflowStub( |
| 104 | + Optional.empty(), |
| 105 | + WorkflowTargetOptions.newBuilder() |
| 106 | + .setWorkflowExecution(untyped.getExecution()) |
| 107 | + .build()) |
| 108 | + .signal("signal")); |
| 109 | + |
| 110 | + testWorkflowRule |
| 111 | + .getWorkflowClient() |
| 112 | + .newUntypedWorkflowStub( |
| 113 | + Optional.empty(), |
| 114 | + WorkflowTargetOptions.newBuilder() |
| 115 | + .setWorkflowId(untyped.getExecution().getWorkflowId()) |
| 116 | + .build()) |
| 117 | + .signal("signal"); |
| 118 | + } |
| 119 | + |
55 | 120 | public static class AwaitingWorkflow implements TestWorkflows.TestWorkflow1 { |
56 | 121 |
|
57 | 122 | @Override |
|
0 commit comments