-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Make AbstractSearchAsyncAction more testable and add a basic test case #20890
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
Make AbstractSearchAsyncAction more testable and add a basic test case #20890
Conversation
`AbstractSearchAsyncAction` has only been tested in integration tests. The infrastrucutre is rather critical and should be tested on a unittest level. This change takes the first step
nik9000
left a comment
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.
Left some minor suggestions but LGTM.
| protected abstract String firstPhaseName(); | ||
|
|
||
| protected Executor getExecutor() { | ||
| return threadPool.executor(ThreadPool.Names.SEARCH); |
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.
Maybe pass the Executor in to the ctor instead of ThreadPool? You could keep this method so you can still override it in tests to throw.
| protected final SearchRequest request; | ||
| protected final ClusterState clusterState; | ||
| protected final DiscoveryNodes nodes; | ||
| protected final Function<String, DiscoveryNode> nodes; |
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.
Can you add javadoc for this? I'm happy to keep it protected but think it'd be nice to have some note on the protected members about how we expect them to be used. Something as simple as /** Used by subclasses to resolve node ids to DiscoveryNodes. **/ would be nice.
| SearchPhaseController searchPhaseController, ThreadPool threadPool, SearchRequest request, | ||
| ActionListener<SearchResponse> listener) { | ||
| protected AbstractSearchAsyncAction(Logger logger, SearchTransportService searchTransportService, | ||
| Function<String, DiscoveryNode> nodeLookup, Map<String, String[]> perIndexFilteringAliases, |
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.
Maybe rename nodeLookup to nodeIdToDiscsoveryNode? I love that you've pulled the cluster state stuff out into these functions we can mock out easily in tests but when I first scanned this line I thought "oh, functions that map index name to stuff".
| Map<String, DiscoveryNode> lookup = new HashMap<>(); | ||
| lookup.put(primaryNode.getId(), primaryNode); | ||
| AbstractSearchAsyncAction asyncAction = new AbstractSearchAsyncAction<TestSearchPhaseResult>(logger, transportService, lookup::get, | ||
| Collections.emptyMap(), |
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.
Can you bump the indentation on the parameters one time so they don't line up with the class body?
|
thanks @nik9000 |
#20890) `AbstractSearchAsyncAction` has only been tested in integration tests. The infrastructure is rather critical and should be tested on a unit-test level. This change takes the first step.
This is a followup to elastic#21689 where we removed a misplaced try catch for IndexMissingException and IndexClosedException which was related to elastic#9047 (at least for the index closed case). The code block within the change was moved as part of elastic#20890, which made the catch redundant. It was somehow used before (e.g. in 5.0) but it doesn't seem that this catch had any effect. Added tests to verify that. In fact a specific catch added to the search api only would defeat the purpose of having common indices options that work throughout all our APIs. Relates to elastic#21689
This is a followup to #21689 where we removed a misplaced try catch for IndexMissingException and IndexClosedException which was related to #9047 (at least for the index closed case). The code block within the change was moved as part of #20890, which made the catch redundant. It was somehow used before (e.g. in 5.0) but it doesn't seem that this catch had any effect. Added tests to verify that. In fact a specific catch added to the search api only would defeat the purpose of having common indices options that work throughout all our APIs. Relates to #21689
This is a followup to #21689 where we removed a misplaced try catch for IndexMissingException and IndexClosedException which was related to #9047 (at least for the index closed case). The code block within the change was moved as part of #20890, which made the catch redundant. It was somehow used before (e.g. in 5.0) but it doesn't seem that this catch had any effect. Added tests to verify that. In fact a specific catch added to the search api only would defeat the purpose of having common indices options that work throughout all our APIs. Relates to #21689
AbstractSearchAsyncActionhas only been tested in integration tests.The infrastrucutre is rather critical and should be tested on a unittest
level. This change takes the first step