-
Notifications
You must be signed in to change notification settings - Fork 150
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
Move workflow update polling inside of interceptor #2159
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,11 @@ | |
import io.temporal.api.workflowservice.v1.ResetWorkflowExecutionRequest; | ||
import io.temporal.api.workflowservice.v1.ResetWorkflowExecutionResponse; | ||
import io.temporal.client.*; | ||
import io.temporal.common.interceptors.WorkflowClientCallsInterceptor; | ||
import io.temporal.common.interceptors.WorkflowClientCallsInterceptorBase; | ||
import io.temporal.common.interceptors.WorkflowClientInterceptorBase; | ||
import io.temporal.failure.ApplicationFailure; | ||
import io.temporal.internal.client.CompletedUpdateHandleImpl; | ||
import io.temporal.testing.internal.SDKTestOptions; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.worker.WorkerOptions; | ||
|
@@ -103,6 +107,55 @@ public void testUpdate() { | |
assertEquals("Execute-Hello Update Execute-Hello Update 2", result); | ||
} | ||
|
||
private static class FakesResultUpdateInterceptor extends WorkflowClientInterceptorBase { | ||
@Override | ||
public WorkflowClientCallsInterceptor workflowClientCallsInterceptor( | ||
WorkflowClientCallsInterceptor next) { | ||
return new WorkflowClientCallsInterceptorBase(next) { | ||
@Override | ||
public <R> UpdateHandle<R> startUpdate(StartUpdateInput<R> input) { | ||
super.startUpdate(input); | ||
Comment on lines
+116
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note: Why don't we have something like I get why they're not directly mutable, but, might be nice to have a convenient way to do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modify inputs is not really an encouraged pattern. Not that some users don't but I it is a advanced path to take. |
||
return new CompletedUpdateHandleImpl<>( | ||
"someid", input.getWorkflowExecution(), (R) "fake"); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
@Test | ||
public void testUpdateIntercepted() { | ||
String workflowId = UUID.randomUUID().toString(); | ||
WorkflowClient workflowClient = | ||
WorkflowClient.newInstance( | ||
testWorkflowRule.getWorkflowServiceStubs(), | ||
WorkflowClientOptions.newBuilder(testWorkflowRule.getWorkflowClient().getOptions()) | ||
.setInterceptors(new FakesResultUpdateInterceptor()) | ||
.validateAndBuildWithDefaults()); | ||
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); | ||
|
||
SDKTestWorkflowRule.waitForOKQuery(workflow); | ||
assertEquals("initial", workflow.getState()); | ||
assertEquals(workflowId, execution.getWorkflowId()); | ||
|
||
assertEquals("fake", workflow.update(0, "Hello Update")); | ||
assertEquals("fake", workflow.update(1, "Hello Update 2")); | ||
workflow.complete(); | ||
|
||
String result = | ||
testWorkflowRule | ||
.getWorkflowClient() | ||
.newUntypedWorkflowStub(execution, Optional.empty()) | ||
.getResult(String.class); | ||
assertEquals("Execute-Hello Update Execute-Hello Update 2", result); | ||
} | ||
|
||
@Test | ||
public void testUpdateUntyped() throws ExecutionException, InterruptedException { | ||
WorkflowClient workflowClient = testWorkflowRule.getWorkflowClient(); | ||
|
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.
Hm I wonder if we would ever need to return more then
UpdateHandle
here? I think other SDKs just returnUpdateHandle
so if we do will have to address in all SDKs