Skip to content

Commit 9dba565

Browse files
committed
fix test
1 parent e103d92 commit 9dba565

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package io.temporal.samples.earlyreturn;
2121

22+
import io.temporal.api.enums.v1.WorkflowIdConflictPolicy;
2223
import io.temporal.client.*;
2324
import io.temporal.serviceclient.WorkflowServiceStubs;
2425

@@ -80,6 +81,7 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) {
8081
private static WorkflowOptions buildWorkflowOptions() {
8182
return WorkflowOptions.newBuilder()
8283
.setTaskQueue(TASK_QUEUE)
84+
.setWorkflowIdConflictPolicy(WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL)
8385
.setWorkflowId(WORKFLOW_ID_PREFIX + System.currentTimeMillis())
8486
.build();
8587
}

core/src/test/java/io/temporal/samples/earlyreturn/TransactionWorkflowTest.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.mockito.ArgumentMatchers.any;
2424
import static org.mockito.Mockito.*;
2525

26+
import io.temporal.api.enums.v1.WorkflowIdConflictPolicy;
2627
import io.temporal.client.*;
2728
import io.temporal.failure.ActivityFailure;
2829
import io.temporal.failure.ApplicationFailure;
@@ -63,23 +64,22 @@ public void testUpdateWithStartValidAmount() throws Exception {
6364
TransactionWorkflow workflow =
6465
workflowClient.newWorkflowStub(
6566
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());
7372

7473
// 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));
8081

8182
// Verify both update and final results
82-
TxResult updateResult = handle.getResultAsync().get();
8383
assertEquals(TEST_TRANSACTION_ID, updateResult.getTransactionId());
8484

8585
TxResult finalResult = WorkflowStub.fromTyped(workflow).getResult(TxResult.class);
@@ -111,33 +111,29 @@ public void testUpdateWithStartInvalidAmount() throws Exception {
111111
String workflowId = "test-workflow-" + UUID.randomUUID();
112112
WorkflowOptions options =
113113
WorkflowOptions.newBuilder()
114+
.setWorkflowIdConflictPolicy(WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL)
114115
.setTaskQueue(testWorkflowRule.getTaskQueue())
115116
.setWorkflowId(workflowId)
116117
.build();
117118

118119
TransactionWorkflow workflow =
119120
workflowClient.newWorkflowStub(TransactionWorkflow.class, options);
120121

121-
// Create update operation
122-
UpdateWithStartWorkflowOperation<TxResult> updateOp =
123-
UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult)
124-
.setWaitForStage(WorkflowUpdateStage.COMPLETED)
125-
.build();
126-
127122
// Execute UpdateWithStart and expect the exception
128-
WorkflowServiceException exception =
123+
TransactionRequest txRequest =
124+
new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, INVALID_AMOUNT);
125+
WorkflowUpdateException exception =
129126
assertThrows(
130-
WorkflowServiceException.class,
127+
WorkflowUpdateException.class,
131128
() ->
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)));
136133

137134
// 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();
141137
assertEquals("InvalidAmount", appFailure.getType());
142138
assertTrue(appFailure.getMessage().contains("Invalid Amount"));
143139

core/src/test/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorkerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ public void testUpdateIdempotency() {
105105
.newWorkflowStub(
106106
ClusterManagerWorkflow.class,
107107
WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build());
108-
CompletableFuture<ClusterManagerWorkflow.ClusterManagerResult> result =
109-
WorkflowClient.execute(
110-
cluster::run, new ClusterManagerWorkflow.ClusterManagerInput(Optional.empty(), false));
108+
WorkflowClient.execute(
109+
cluster::run, new ClusterManagerWorkflow.ClusterManagerInput(Optional.empty(), false));
111110

112111
cluster.startCluster();
113112

0 commit comments

Comments
 (0)