|
21 | 21 | package io.temporal.workflow.updateTest;
|
22 | 22 |
|
23 | 23 | import static org.junit.Assert.*;
|
| 24 | +import static org.junit.Assume.assumeTrue; |
24 | 25 |
|
25 | 26 | import io.temporal.activity.*;
|
26 | 27 | import io.temporal.api.common.v1.WorkflowExecution;
|
| 28 | +import io.temporal.api.enums.v1.ResetReapplyExcludeType; |
| 29 | +import io.temporal.api.enums.v1.ResetReapplyType; |
| 30 | +import io.temporal.api.workflowservice.v1.ResetWorkflowExecutionRequest; |
| 31 | +import io.temporal.api.workflowservice.v1.ResetWorkflowExecutionResponse; |
27 | 32 | import io.temporal.client.*;
|
28 | 33 | import io.temporal.failure.ApplicationFailure;
|
29 | 34 | import io.temporal.testing.internal.SDKTestOptions;
|
|
35 | 40 | import io.temporal.workflow.shared.TestWorkflows;
|
36 | 41 | import io.temporal.workflow.shared.TestWorkflows.WorkflowWithUpdate;
|
37 | 42 | import java.time.Duration;
|
38 |
| -import java.util.ArrayList; |
39 |
| -import java.util.List; |
40 |
| -import java.util.Optional; |
41 |
| -import java.util.UUID; |
| 43 | +import java.util.*; |
42 | 44 | import java.util.concurrent.ExecutionException;
|
43 | 45 | import java.util.concurrent.Executors;
|
44 | 46 | import java.util.concurrent.Future;
|
@@ -143,6 +145,53 @@ public void testUpdateUntyped() throws ExecutionException, InterruptedException
|
143 | 145 | assertEquals("Execute-Hello Execute-World", workflowStub.getResult(String.class));
|
144 | 146 | }
|
145 | 147 |
|
| 148 | + @Test |
| 149 | + public void testUpdateResets() { |
| 150 | + assumeTrue( |
| 151 | + "Test Server doesn't support reset workflow", SDKTestWorkflowRule.useExternalService); |
| 152 | + String workflowId = UUID.randomUUID().toString(); |
| 153 | + WorkflowClient workflowClient = testWorkflowRule.getWorkflowClient(); |
| 154 | + WorkflowOptions options = |
| 155 | + SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder() |
| 156 | + .setWorkflowId(workflowId) |
| 157 | + .build(); |
| 158 | + WorkflowWithUpdate workflow = workflowClient.newWorkflowStub(WorkflowWithUpdate.class, options); |
| 159 | + WorkflowExecution execution = WorkflowClient.start(workflow::execute); |
| 160 | + |
| 161 | + SDKTestWorkflowRule.waitForOKQuery(workflow); |
| 162 | + assertEquals("initial", workflow.getState()); |
| 163 | + |
| 164 | + assertEquals(workflowId, execution.getWorkflowId()); |
| 165 | + |
| 166 | + assertEquals("Execute-Hello Update", workflow.update(0, "Hello Update")); |
| 167 | + |
| 168 | + // Reset the workflow |
| 169 | + ResetWorkflowExecutionResponse resetResponse = |
| 170 | + workflowClient |
| 171 | + .getWorkflowServiceStubs() |
| 172 | + .blockingStub() |
| 173 | + .resetWorkflowExecution( |
| 174 | + ResetWorkflowExecutionRequest.newBuilder() |
| 175 | + .setNamespace(SDKTestWorkflowRule.NAMESPACE) |
| 176 | + .setReason("Integration test") |
| 177 | + .setWorkflowExecution(execution) |
| 178 | + .setWorkflowTaskFinishEventId(4) |
| 179 | + .setRequestId(UUID.randomUUID().toString()) |
| 180 | + .setResetReapplyType(ResetReapplyType.RESET_REAPPLY_TYPE_ALL_ELIGIBLE) |
| 181 | + .addAllResetReapplyExcludeTypes( |
| 182 | + Collections.singletonList( |
| 183 | + ResetReapplyExcludeType.RESET_REAPPLY_EXCLUDE_TYPE_SIGNAL)) |
| 184 | + .build()); |
| 185 | + // Create a new workflow stub with the new run ID |
| 186 | + workflow = |
| 187 | + workflowClient.newWorkflowStub( |
| 188 | + WorkflowWithUpdate.class, workflowId, Optional.of(resetResponse.getRunId())); |
| 189 | + assertEquals("Execute-Hello Update 2", workflow.update(0, "Hello Update 2")); |
| 190 | + // Complete would throw an exception if the update was not applied to the reset workflow. |
| 191 | + workflow.complete(); |
| 192 | + assertEquals("Execute-Hello Update Execute-Hello Update 2", workflow.execute()); |
| 193 | + } |
| 194 | + |
146 | 195 | @Test
|
147 | 196 | public void testUpdateHandleNotReturnedUntilCompleteWhenAsked()
|
148 | 197 | throws ExecutionException, InterruptedException {
|
|
0 commit comments