Skip to content

Commit 69db545

Browse files
authored
Update Java SDK (temporalio#705)
1 parent dcee476 commit 69db545

File tree

7 files changed

+40
-53
lines changed

7 files changed

+40
-53
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ subprojects {
2828
ext {
2929
otelVersion = '1.30.1'
3030
otelVersionAlpha = "${otelVersion}-alpha"
31-
javaSDKVersion = '1.26.1'
31+
javaSDKVersion = '1.27.0'
3232
camelVersion = '3.22.1'
3333
jarVersion = '1.0.0'
3434
}

core/src/main/java/io/temporal/samples/countinterceptor/SimpleCountWorkerInterceptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919

2020
package io.temporal.samples.countinterceptor;
2121

22-
import io.temporal.common.interceptors.ActivityInboundCallsInterceptor;
23-
import io.temporal.common.interceptors.WorkerInterceptor;
24-
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
22+
import io.temporal.common.interceptors.*;
2523

26-
public class SimpleCountWorkerInterceptor implements WorkerInterceptor {
24+
public class SimpleCountWorkerInterceptor extends WorkerInterceptorBase {
2725

2826
@Override
2927
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {

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

Lines changed: 7 additions & 9 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

@@ -49,17 +50,13 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) {
4950

5051
System.out.println("Starting workflow with UpdateWithStart");
5152

52-
UpdateWithStartWorkflowOperation<TxResult> updateOp =
53-
UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult)
54-
.setWaitForStage(WorkflowUpdateStage.COMPLETED) // Wait for update to complete
55-
.build();
56-
5753
TxResult updateResult = null;
5854
try {
59-
WorkflowUpdateHandle<TxResult> updateHandle =
60-
WorkflowClient.updateWithStart(workflow::processTransaction, txRequest, updateOp);
61-
62-
updateResult = updateHandle.getResultAsync().get();
55+
updateResult =
56+
WorkflowClient.executeUpdateWithStart(
57+
workflow::returnInitResult,
58+
UpdateOptions.<TxResult>newBuilder().build(),
59+
new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest));
6360

6461
System.out.println(
6562
"Workflow initialized with result: "
@@ -84,6 +81,7 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) {
8481
private static WorkflowOptions buildWorkflowOptions() {
8582
return WorkflowOptions.newBuilder()
8683
.setTaskQueue(TASK_QUEUE)
84+
.setWorkflowIdConflictPolicy(WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL)
8785
.setWorkflowId(WORKFLOW_ID_PREFIX + System.currentTimeMillis())
8886
.build();
8987
}

core/src/main/java/io/temporal/samples/excludefrominterceptor/interceptor/MyWorkerInterceptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919

2020
package io.temporal.samples.excludefrominterceptor.interceptor;
2121

22-
import io.temporal.common.interceptors.ActivityInboundCallsInterceptor;
23-
import io.temporal.common.interceptors.WorkerInterceptor;
24-
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
22+
import io.temporal.common.interceptors.*;
2523
import java.util.ArrayList;
2624
import java.util.List;
2725

28-
public class MyWorkerInterceptor implements WorkerInterceptor {
26+
public class MyWorkerInterceptor extends WorkerInterceptorBase {
2927
private List<String> excludeWorkflowTypes = new ArrayList<>();
3028
private List<String> excludeActivityTypes = new ArrayList<>();
3129

core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalWorkerInterceptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919

2020
package io.temporal.samples.retryonsignalinterceptor;
2121

22-
import io.temporal.common.interceptors.ActivityInboundCallsInterceptor;
23-
import io.temporal.common.interceptors.WorkerInterceptor;
24-
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
22+
import io.temporal.common.interceptors.*;
2523

2624
/** Should be registered through WorkerFactoryOptions. */
27-
public class RetryOnSignalWorkerInterceptor implements WorkerInterceptor {
25+
public class RetryOnSignalWorkerInterceptor extends WorkerInterceptorBase {
2826
@Override
2927
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
3028
return new RetryOnSignalWorkflowInboundCallsInterceptor(next);

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)