diff --git a/build.gradle b/build.gradle index 43c50ce5b..92d13ca62 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ subprojects { ext { otelVersion = '1.30.1' otelVersionAlpha = "${otelVersion}-alpha" - javaSDKVersion = '1.26.1' + javaSDKVersion = '1.27.0' camelVersion = '3.22.1' jarVersion = '1.0.0' } diff --git a/core/src/main/java/io/temporal/samples/countinterceptor/SimpleCountWorkerInterceptor.java b/core/src/main/java/io/temporal/samples/countinterceptor/SimpleCountWorkerInterceptor.java index 268d2620a..156002e42 100644 --- a/core/src/main/java/io/temporal/samples/countinterceptor/SimpleCountWorkerInterceptor.java +++ b/core/src/main/java/io/temporal/samples/countinterceptor/SimpleCountWorkerInterceptor.java @@ -19,11 +19,9 @@ package io.temporal.samples.countinterceptor; -import io.temporal.common.interceptors.ActivityInboundCallsInterceptor; -import io.temporal.common.interceptors.WorkerInterceptor; -import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor; +import io.temporal.common.interceptors.*; -public class SimpleCountWorkerInterceptor implements WorkerInterceptor { +public class SimpleCountWorkerInterceptor extends WorkerInterceptorBase { @Override public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) { diff --git a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java index 6ccb11da1..36da78d87 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java @@ -19,6 +19,7 @@ package io.temporal.samples.earlyreturn; +import io.temporal.api.enums.v1.WorkflowIdConflictPolicy; import io.temporal.client.*; import io.temporal.serviceclient.WorkflowServiceStubs; @@ -49,17 +50,13 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) { System.out.println("Starting workflow with UpdateWithStart"); - UpdateWithStartWorkflowOperation updateOp = - UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult) - .setWaitForStage(WorkflowUpdateStage.COMPLETED) // Wait for update to complete - .build(); - TxResult updateResult = null; try { - WorkflowUpdateHandle updateHandle = - WorkflowClient.updateWithStart(workflow::processTransaction, txRequest, updateOp); - - updateResult = updateHandle.getResultAsync().get(); + updateResult = + WorkflowClient.executeUpdateWithStart( + workflow::returnInitResult, + UpdateOptions.newBuilder().build(), + new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest)); System.out.println( "Workflow initialized with result: " @@ -84,6 +81,7 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) { private static WorkflowOptions buildWorkflowOptions() { return WorkflowOptions.newBuilder() .setTaskQueue(TASK_QUEUE) + .setWorkflowIdConflictPolicy(WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL) .setWorkflowId(WORKFLOW_ID_PREFIX + System.currentTimeMillis()) .build(); } diff --git a/core/src/main/java/io/temporal/samples/excludefrominterceptor/interceptor/MyWorkerInterceptor.java b/core/src/main/java/io/temporal/samples/excludefrominterceptor/interceptor/MyWorkerInterceptor.java index 7674013dc..761f39b70 100644 --- a/core/src/main/java/io/temporal/samples/excludefrominterceptor/interceptor/MyWorkerInterceptor.java +++ b/core/src/main/java/io/temporal/samples/excludefrominterceptor/interceptor/MyWorkerInterceptor.java @@ -19,13 +19,11 @@ package io.temporal.samples.excludefrominterceptor.interceptor; -import io.temporal.common.interceptors.ActivityInboundCallsInterceptor; -import io.temporal.common.interceptors.WorkerInterceptor; -import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor; +import io.temporal.common.interceptors.*; import java.util.ArrayList; import java.util.List; -public class MyWorkerInterceptor implements WorkerInterceptor { +public class MyWorkerInterceptor extends WorkerInterceptorBase { private List excludeWorkflowTypes = new ArrayList<>(); private List excludeActivityTypes = new ArrayList<>(); diff --git a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalWorkerInterceptor.java b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalWorkerInterceptor.java index 6e4ba7db0..180306447 100644 --- a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalWorkerInterceptor.java +++ b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalWorkerInterceptor.java @@ -19,12 +19,10 @@ package io.temporal.samples.retryonsignalinterceptor; -import io.temporal.common.interceptors.ActivityInboundCallsInterceptor; -import io.temporal.common.interceptors.WorkerInterceptor; -import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor; +import io.temporal.common.interceptors.*; /** Should be registered through WorkerFactoryOptions. */ -public class RetryOnSignalWorkerInterceptor implements WorkerInterceptor { +public class RetryOnSignalWorkerInterceptor extends WorkerInterceptorBase { @Override public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) { return new RetryOnSignalWorkflowInboundCallsInterceptor(next); diff --git a/core/src/test/java/io/temporal/samples/earlyreturn/TransactionWorkflowTest.java b/core/src/test/java/io/temporal/samples/earlyreturn/TransactionWorkflowTest.java index 5661d28a9..97cda3583 100644 --- a/core/src/test/java/io/temporal/samples/earlyreturn/TransactionWorkflowTest.java +++ b/core/src/test/java/io/temporal/samples/earlyreturn/TransactionWorkflowTest.java @@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import io.temporal.api.enums.v1.WorkflowIdConflictPolicy; import io.temporal.client.*; import io.temporal.failure.ActivityFailure; import io.temporal.failure.ApplicationFailure; @@ -63,23 +64,22 @@ public void testUpdateWithStartValidAmount() throws Exception { TransactionWorkflow workflow = workflowClient.newWorkflowStub( TransactionWorkflow.class, - WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build()); - - // Create update operation - UpdateWithStartWorkflowOperation updateOp = - UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult) - .setWaitForStage(WorkflowUpdateStage.COMPLETED) - .build(); + WorkflowOptions.newBuilder() + .setWorkflowIdConflictPolicy( + WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL) + .setTaskQueue(testWorkflowRule.getTaskQueue()) + .build()); // Execute UpdateWithStart - WorkflowUpdateHandle handle = - WorkflowClient.updateWithStart( - workflow::processTransaction, - new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, VALID_AMOUNT), - updateOp); + TransactionRequest txRequest = + new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, VALID_AMOUNT); + TxResult updateResult = + WorkflowClient.executeUpdateWithStart( + workflow::returnInitResult, + UpdateOptions.newBuilder().build(), + new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest)); // Verify both update and final results - TxResult updateResult = handle.getResultAsync().get(); assertEquals(TEST_TRANSACTION_ID, updateResult.getTransactionId()); TxResult finalResult = WorkflowStub.fromTyped(workflow).getResult(TxResult.class); @@ -111,6 +111,7 @@ public void testUpdateWithStartInvalidAmount() throws Exception { String workflowId = "test-workflow-" + UUID.randomUUID(); WorkflowOptions options = WorkflowOptions.newBuilder() + .setWorkflowIdConflictPolicy(WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_FAIL) .setTaskQueue(testWorkflowRule.getTaskQueue()) .setWorkflowId(workflowId) .build(); @@ -118,26 +119,21 @@ public void testUpdateWithStartInvalidAmount() throws Exception { TransactionWorkflow workflow = workflowClient.newWorkflowStub(TransactionWorkflow.class, options); - // Create update operation - UpdateWithStartWorkflowOperation updateOp = - UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult) - .setWaitForStage(WorkflowUpdateStage.COMPLETED) - .build(); - // Execute UpdateWithStart and expect the exception - WorkflowServiceException exception = + TransactionRequest txRequest = + new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, INVALID_AMOUNT); + WorkflowUpdateException exception = assertThrows( - WorkflowServiceException.class, + WorkflowUpdateException.class, () -> - WorkflowClient.updateWithStart( - workflow::processTransaction, - new TransactionRequest(SOURCE_ACCOUNT, TARGET_ACCOUNT, INVALID_AMOUNT), - updateOp)); + WorkflowClient.executeUpdateWithStart( + workflow::returnInitResult, + UpdateOptions.newBuilder().build(), + new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest))); // Verify the exception chain - assertTrue(exception.getCause() instanceof WorkflowUpdateException); - assertTrue(exception.getCause().getCause() instanceof ActivityFailure); - ApplicationFailure appFailure = (ApplicationFailure) exception.getCause().getCause().getCause(); + assertTrue(exception.getCause() instanceof ActivityFailure); + ApplicationFailure appFailure = (ApplicationFailure) exception.getCause().getCause(); assertEquals("InvalidAmount", appFailure.getType()); assertTrue(appFailure.getMessage().contains("Invalid Amount")); diff --git a/core/src/test/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorkerTest.java b/core/src/test/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorkerTest.java index 382ea1107..55ea41fd9 100644 --- a/core/src/test/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorkerTest.java +++ b/core/src/test/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorkerTest.java @@ -105,9 +105,8 @@ public void testUpdateIdempotency() { .newWorkflowStub( ClusterManagerWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build()); - CompletableFuture result = - WorkflowClient.execute( - cluster::run, new ClusterManagerWorkflow.ClusterManagerInput(Optional.empty(), false)); + WorkflowClient.execute( + cluster::run, new ClusterManagerWorkflow.ClusterManagerInput(Optional.empty(), false)); cluster.startCluster();