-
Notifications
You must be signed in to change notification settings - Fork 161
Add an interceptor for listExecutions #2524
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
Open
Quinn-With-Two-Ns
wants to merge
3
commits into
temporalio:master
Choose a base branch
from
Quinn-With-Two-Ns:issue-2328
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
63 changes: 63 additions & 0 deletions
63
temporal-sdk/src/test/java/io/temporal/client/ListWorkflowExecutionsInterceptorTest.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,63 @@ | ||
package io.temporal.client; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import io.temporal.common.interceptors.WorkflowClientCallsInterceptor; | ||
import io.temporal.common.interceptors.WorkflowClientCallsInterceptorBase; | ||
import io.temporal.common.interceptors.WorkflowClientInterceptorBase; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ListWorkflowExecutionsInterceptorTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestWorkflows.DoNothingNoArgsWorkflow.class) | ||
.build(); | ||
|
||
@Test | ||
public void listExecutions_isIntercepted() throws InterruptedException { | ||
assumeTrue( | ||
"Test Server doesn't support listWorkflowExecutions endpoint yet", | ||
SDKTestWorkflowRule.useExternalService); | ||
|
||
AtomicInteger intercepted = new AtomicInteger(); | ||
WorkflowClient workflowClient = | ||
WorkflowClient.newInstance( | ||
testWorkflowRule.getWorkflowServiceStubs(), | ||
WorkflowClientOptions.newBuilder(testWorkflowRule.getWorkflowClient().getOptions()) | ||
.setInterceptors( | ||
new WorkflowClientInterceptorBase() { | ||
@Override | ||
public WorkflowClientCallsInterceptor workflowClientCallsInterceptor( | ||
WorkflowClientCallsInterceptor next) { | ||
return new WorkflowClientCallsInterceptorBase(next) { | ||
@Override | ||
public ListWorkflowExecutionsOutput listWorkflowExecutions( | ||
ListWorkflowExecutionsInput input) { | ||
intercepted.incrementAndGet(); | ||
return super.listWorkflowExecutions(input); | ||
} | ||
}; | ||
} | ||
}) | ||
.validateAndBuildWithDefaults()); | ||
|
||
WorkflowStub.fromTyped(testWorkflowRule.newWorkflowStub(TestWorkflows.NoArgsWorkflow.class)) | ||
.start(); | ||
|
||
// Visibility API is eventually consistent | ||
Thread.sleep(2_000); | ||
java.util.List<WorkflowExecutionMetadata> result = | ||
workflowClient | ||
.listExecutions("TaskQueue='" + testWorkflowRule.getTaskQueue() + "'") | ||
.collect(java.util.stream.Collectors.toList()); | ||
assertFalse(result.isEmpty()); | ||
assertEquals(1, intercepted.get()); | ||
} | ||
} |
Oops, something went wrong.
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.
Does this need to be public to support the interceptor? In .NET for example we felt there was no need to expose the underlying machinery of list workflows because creating an async iterator (or Java stream) should be easy enough if they must completely replace the logic and not just delegate to the next interceptor.
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.
ideally no, the problem is the RootWorkflowClientInvoker.java is in internal so it can't be private, moving this class causes a lot of other issues
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.
Hrmm. I wonder making public and moving from
io.temporal.client
toio.temporal.client.internal
would make sense.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.
Let me try, I think I had some issue doing that since some other classes in
io.temporal.client
also have Iterators