-
Notifications
You must be signed in to change notification settings - Fork 195
Wrap GRPC::CANCELED and DEADLINE_EXCEEDED in new exception type #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Quinn-With-Two-Ns
merged 4 commits into
temporalio:master
from
Quinn-With-Two-Ns:issue-2069
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
temporal-sdk/src/main/java/io/temporal/client/WorkflowUpdateTimeoutOrCancelledException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
| * | ||
| * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this material except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.temporal.client; | ||
|
|
||
| import io.temporal.api.common.v1.WorkflowExecution; | ||
|
|
||
| /** | ||
| * Error that occurs when an update call times out or is cancelled. | ||
| * | ||
| * <p>Note, this is not related to any general concept of timing out or cancelling a running update, | ||
| * this is only related to the client call itself. | ||
| */ | ||
| public class WorkflowUpdateTimeoutOrCancelledException extends WorkflowServiceException { | ||
| public WorkflowUpdateTimeoutOrCancelledException( | ||
| WorkflowExecution execution, String updateId, String updateName, Throwable cause) { | ||
| super(execution, "", cause); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateExceptionWrapped.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
| * | ||
| * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this material except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.temporal.workflow.updateTest; | ||
|
|
||
| import static org.junit.Assert.assertThrows; | ||
|
|
||
| import io.grpc.Context; | ||
| import io.temporal.api.common.v1.WorkflowExecution; | ||
| import io.temporal.client.*; | ||
| import io.temporal.testing.internal.SDKTestOptions; | ||
| import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
| import io.temporal.worker.WorkerOptions; | ||
| import io.temporal.workflow.CompletablePromise; | ||
| import io.temporal.workflow.Workflow; | ||
| import io.temporal.workflow.shared.TestWorkflows.WorkflowWithUpdate; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.*; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
||
| public class UpdateExceptionWrapped { | ||
|
|
||
| private static ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1); | ||
|
|
||
| @Rule | ||
| public SDKTestWorkflowRule testWorkflowRule = | ||
| SDKTestWorkflowRule.newBuilder() | ||
| .setWorkerOptions(WorkerOptions.newBuilder().build()) | ||
| .setWorkflowTypes(TestUpdateWorkflowImpl.class) | ||
| .build(); | ||
|
|
||
| @Test | ||
| public void testUpdateStart() { | ||
| 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); | ||
| // To execute workflow client.execute() would do. But we want to start workflow and immediately | ||
| // return. | ||
| WorkflowExecution execution = WorkflowClient.start(workflow::execute); | ||
| testWorkflowRule.getTestEnvironment().shutdownNow(); | ||
| testWorkflowRule.getTestEnvironment().awaitTermination(1000, TimeUnit.MILLISECONDS); | ||
|
|
||
| final AtomicReference<WorkflowUpdateTimeoutOrCancelledException> exception = | ||
| new AtomicReference<>(); | ||
|
|
||
| Context.current() | ||
| .withDeadlineAfter(500, TimeUnit.MILLISECONDS, scheduledExecutor) | ||
| .run( | ||
| () -> | ||
| exception.set( | ||
| assertThrows( | ||
| WorkflowUpdateTimeoutOrCancelledException.class, | ||
| () -> workflow.update(0, "")))); | ||
| Assert.assertEquals(execution.getWorkflowId(), exception.get().getExecution().getWorkflowId()); | ||
| } | ||
|
|
||
| public static class TestUpdateWorkflowImpl implements WorkflowWithUpdate { | ||
| String state = "initial"; | ||
| List<String> updates = new ArrayList<>(); | ||
| CompletablePromise<Void> promise = Workflow.newPromise(); | ||
|
|
||
| @Override | ||
| public String execute() { | ||
| promise.get(); | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public String getState() { | ||
| return state; | ||
| } | ||
|
|
||
| @Override | ||
| public String update(Integer index, String value) { | ||
| Workflow.await(() -> false); | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public void updateValidator(Integer index, String value) {} | ||
|
|
||
| @Override | ||
| public void complete() { | ||
| promise.complete(null); | ||
| } | ||
|
|
||
| @Override | ||
| public void completeValidator() {} | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be worth docs here stating this constructor is for internal use only and that the parameters may not be stable, but maybe not if we never expect to change or we can overload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine as is, we do the same thing for all the other children of
WorkflowServiceException. A user may construct it for mocking/testsingUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my only concern is that we can't ever change it now, only overload it. But no big deal.