Skip to content

Commit 6da11b9

Browse files
Add integration test for reset with update (#2104)
1 parent f0a30a6 commit 6da11b9

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

temporal-sdk/src/main/java/io/temporal/client/WorkflowClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ static WorkflowClient newInstance(WorkflowServiceStubs service, WorkflowClientOp
167167
<T> T newWorkflowStub(Class<T> workflowInterface, String workflowId);
168168

169169
/**
170-
* Creates workflow client stub for a known execution. Use it to send signals or queries to a
171-
* running workflow. Do not call methods annotated with @WorkflowMethod.
170+
* Creates workflow client stub for a known execution. Use it to send signals, updates, or queries
171+
* to a running workflow. Do not call methods annotated with @WorkflowMethod.
172172
*
173173
* @param workflowInterface interface that given workflow implements.
174174
* @param workflowId Workflow id.
175175
* @param runId Run id of the workflow execution.
176-
* @return Stub that implements workflowInterface and can be used to signal or query it.
176+
* @return Stub that implements workflowInterface and can be used to signal, update, or query it.
177177
*/
178178
<T> T newWorkflowStub(Class<T> workflowInterface, String workflowId, Optional<String> runId);
179179

temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateTest.java

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
package io.temporal.workflow.updateTest;
2222

2323
import static org.junit.Assert.*;
24+
import static org.junit.Assume.assumeTrue;
2425

2526
import io.temporal.activity.*;
2627
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;
2732
import io.temporal.client.*;
2833
import io.temporal.failure.ApplicationFailure;
2934
import io.temporal.testing.internal.SDKTestOptions;
@@ -35,10 +40,7 @@
3540
import io.temporal.workflow.shared.TestWorkflows;
3641
import io.temporal.workflow.shared.TestWorkflows.WorkflowWithUpdate;
3742
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.*;
4244
import java.util.concurrent.ExecutionException;
4345
import java.util.concurrent.Executors;
4446
import java.util.concurrent.Future;
@@ -143,6 +145,53 @@ public void testUpdateUntyped() throws ExecutionException, InterruptedException
143145
assertEquals("Execute-Hello Execute-World", workflowStub.getResult(String.class));
144146
}
145147

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+
146195
@Test
147196
public void testUpdateHandleNotReturnedUntilCompleteWhenAsked()
148197
throws ExecutionException, InterruptedException {

0 commit comments

Comments
 (0)