|
23 | 23 | import static org.mockito.ArgumentMatchers.any; |
24 | 24 | import static org.mockito.Mockito.*; |
25 | 25 |
|
| 26 | +import io.temporal.api.enums.v1.WorkflowIdConflictPolicy; |
26 | 27 | import io.temporal.client.*; |
27 | 28 | import io.temporal.failure.ActivityFailure; |
28 | 29 | import io.temporal.failure.ApplicationFailure; |
@@ -63,23 +64,22 @@ public void testUpdateWithStartValidAmount() throws Exception { |
63 | 64 | TransactionWorkflow workflow = |
64 | 65 | workflowClient.newWorkflowStub( |
65 | 66 | TransactionWorkflow.class, |
66 | | - WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build()); |
67 | | - |
68 | | - // Create update operation |
69 | | - UpdateWithStartWorkflowOperation<TxResult> updateOp = |
70 | | - UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult) |
71 | | - .setWaitForStage(WorkflowUpdateStage.COMPLETED) |
72 | | - .build(); |
| 67 | + WorkflowOptions.newBuilder() |
| 68 | + .setWorkflowIdConflictPolicy( |
| 69 | + WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL) |
| 70 | + .setTaskQueue(testWorkflowRule.getTaskQueue()) |
| 71 | + .build()); |
73 | 72 |
|
74 | 73 | // Execute UpdateWithStart |
75 | | - WorkflowUpdateHandle<TxResult> handle = |
76 | | - WorkflowClient.updateWithStart( |
77 | | - workflow::processTransaction, |
78 | | - new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, VALID_AMOUNT), |
79 | | - updateOp); |
| 74 | + TransactionRequest txRequest = |
| 75 | + new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, VALID_AMOUNT); |
| 76 | + TxResult updateResult = |
| 77 | + WorkflowClient.executeUpdateWithStart( |
| 78 | + workflow::returnInitResult, |
| 79 | + UpdateOptions.<TxResult>newBuilder().build(), |
| 80 | + new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest)); |
80 | 81 |
|
81 | 82 | // Verify both update and final results |
82 | | - TxResult updateResult = handle.getResultAsync().get(); |
83 | 83 | assertEquals(TEST_TRANSACTION_ID, updateResult.getTransactionId()); |
84 | 84 |
|
85 | 85 | TxResult finalResult = WorkflowStub.fromTyped(workflow).getResult(TxResult.class); |
@@ -111,33 +111,29 @@ public void testUpdateWithStartInvalidAmount() throws Exception { |
111 | 111 | String workflowId = "test-workflow-" + UUID.randomUUID(); |
112 | 112 | WorkflowOptions options = |
113 | 113 | WorkflowOptions.newBuilder() |
| 114 | + .setWorkflowIdConflictPolicy(WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL) |
114 | 115 | .setTaskQueue(testWorkflowRule.getTaskQueue()) |
115 | 116 | .setWorkflowId(workflowId) |
116 | 117 | .build(); |
117 | 118 |
|
118 | 119 | TransactionWorkflow workflow = |
119 | 120 | workflowClient.newWorkflowStub(TransactionWorkflow.class, options); |
120 | 121 |
|
121 | | - // Create update operation |
122 | | - UpdateWithStartWorkflowOperation<TxResult> updateOp = |
123 | | - UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult) |
124 | | - .setWaitForStage(WorkflowUpdateStage.COMPLETED) |
125 | | - .build(); |
126 | | - |
127 | 122 | // Execute UpdateWithStart and expect the exception |
128 | | - WorkflowServiceException exception = |
| 123 | + TransactionRequest txRequest = |
| 124 | + new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, INVALID_AMOUNT); |
| 125 | + WorkflowUpdateException exception = |
129 | 126 | assertThrows( |
130 | | - WorkflowServiceException.class, |
| 127 | + WorkflowUpdateException.class, |
131 | 128 | () -> |
132 | | - WorkflowClient.updateWithStart( |
133 | | - workflow::processTransaction, |
134 | | - new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, INVALID_AMOUNT), |
135 | | - updateOp)); |
| 129 | + WorkflowClient.executeUpdateWithStart( |
| 130 | + workflow::returnInitResult, |
| 131 | + UpdateOptions.<TxResult>newBuilder().build(), |
| 132 | + new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest))); |
136 | 133 |
|
137 | 134 | // Verify the exception chain |
138 | | - assertTrue(exception.getCause() instanceof WorkflowUpdateException); |
139 | | - assertTrue(exception.getCause().getCause() instanceof ActivityFailure); |
140 | | - ApplicationFailure appFailure = (ApplicationFailure) exception.getCause().getCause().getCause(); |
| 135 | + assertTrue(exception.getCause() instanceof ActivityFailure); |
| 136 | + ApplicationFailure appFailure = (ApplicationFailure) exception.getCause().getCause(); |
141 | 137 | assertEquals("InvalidAmount", appFailure.getType()); |
142 | 138 | assertTrue(appFailure.getMessage().contains("Invalid Amount")); |
143 | 139 |
|
|
0 commit comments