Skip to content

Commit

Permalink
Add integration test for reset with update (#2104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Jun 11, 2024
1 parent f0a30a6 commit 6da11b9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ static WorkflowClient newInstance(WorkflowServiceStubs service, WorkflowClientOp
<T> T newWorkflowStub(Class<T> workflowInterface, String workflowId);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
package io.temporal.workflow.updateTest;

import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;

import io.temporal.activity.*;
import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.api.enums.v1.ResetReapplyExcludeType;
import io.temporal.api.enums.v1.ResetReapplyType;
import io.temporal.api.workflowservice.v1.ResetWorkflowExecutionRequest;
import io.temporal.api.workflowservice.v1.ResetWorkflowExecutionResponse;
import io.temporal.client.*;
import io.temporal.failure.ApplicationFailure;
import io.temporal.testing.internal.SDKTestOptions;
Expand All @@ -35,10 +40,7 @@
import io.temporal.workflow.shared.TestWorkflows;
import io.temporal.workflow.shared.TestWorkflows.WorkflowWithUpdate;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -143,6 +145,53 @@ public void testUpdateUntyped() throws ExecutionException, InterruptedException
assertEquals("Execute-Hello Execute-World", workflowStub.getResult(String.class));
}

@Test
public void testUpdateResets() {
assumeTrue(
"Test Server doesn't support reset workflow", SDKTestWorkflowRule.useExternalService);
String workflowId = UUID.randomUUID().toString();
WorkflowClient workflowClient = testWorkflowRule.getWorkflowClient();
WorkflowOptions options =
SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder()
.setWorkflowId(workflowId)
.build();
WorkflowWithUpdate workflow = workflowClient.newWorkflowStub(WorkflowWithUpdate.class, options);
WorkflowExecution execution = WorkflowClient.start(workflow::execute);

SDKTestWorkflowRule.waitForOKQuery(workflow);
assertEquals("initial", workflow.getState());

assertEquals(workflowId, execution.getWorkflowId());

assertEquals("Execute-Hello Update", workflow.update(0, "Hello Update"));

// Reset the workflow
ResetWorkflowExecutionResponse resetResponse =
workflowClient
.getWorkflowServiceStubs()
.blockingStub()
.resetWorkflowExecution(
ResetWorkflowExecutionRequest.newBuilder()
.setNamespace(SDKTestWorkflowRule.NAMESPACE)
.setReason("Integration test")
.setWorkflowExecution(execution)
.setWorkflowTaskFinishEventId(4)
.setRequestId(UUID.randomUUID().toString())
.setResetReapplyType(ResetReapplyType.RESET_REAPPLY_TYPE_ALL_ELIGIBLE)
.addAllResetReapplyExcludeTypes(
Collections.singletonList(
ResetReapplyExcludeType.RESET_REAPPLY_EXCLUDE_TYPE_SIGNAL))
.build());
// Create a new workflow stub with the new run ID
workflow =
workflowClient.newWorkflowStub(
WorkflowWithUpdate.class, workflowId, Optional.of(resetResponse.getRunId()));
assertEquals("Execute-Hello Update 2", workflow.update(0, "Hello Update 2"));
// Complete would throw an exception if the update was not applied to the reset workflow.
workflow.complete();
assertEquals("Execute-Hello Update Execute-Hello Update 2", workflow.execute());
}

@Test
public void testUpdateHandleNotReturnedUntilCompleteWhenAsked()
throws ExecutionException, InterruptedException {
Expand Down

0 comments on commit 6da11b9

Please sign in to comment.