Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To provide a base implementation for Nexus.


@Override
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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

UpdateWithStartWorkflowOperation<TxResult> updateOp =
UpdateWithStartWorkflowOperation.newBuilder(workflow::returnInitResult)
.setWaitForStage(WorkflowUpdateStage.COMPLETED) // Wait for update to complete
.build();

TxResult updateResult = null;
try {
WorkflowUpdateHandle<TxResult> updateHandle =
WorkflowClient.updateWithStart(workflow::processTransaction, txRequest, updateOp);

updateResult = updateHandle.getResultAsync().get();
updateResult =
WorkflowClient.executeUpdateWithStart(
workflow::returnInitResult,
UpdateOptions.<TxResult>newBuilder().build(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner implementation!

new WithStartWorkflowOperation<>(workflow::processTransaction, txRequest));

System.out.println(
"Workflow initialized with result: "
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> excludeWorkflowTypes = new ArrayList<>();
private List<String> excludeActivityTypes = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TxResult> 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<TxResult> 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.<TxResult>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);
Expand Down Expand Up @@ -111,33 +111,29 @@ 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();

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

// Create update operation
UpdateWithStartWorkflowOperation<TxResult> 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.<TxResult>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"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ public void testUpdateIdempotency() {
.newWorkflowStub(
ClusterManagerWorkflow.class,
WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build());
CompletableFuture<ClusterManagerWorkflow.ClusterManagerResult> result =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error for an unused variable 🤷

WorkflowClient.execute(
cluster::run, new ClusterManagerWorkflow.ClusterManagerInput(Optional.empty(), false));
WorkflowClient.execute(
cluster::run, new ClusterManagerWorkflow.ClusterManagerInput(Optional.empty(), false));

cluster.startCluster();

Expand Down
Loading