-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Add base class for writing unit test for aggregations #22279
Conversation
* Base class for testing {@link Aggregator} implementations. | ||
* Provides a helper constructing the {@link Aggregator} implementation based on a provided {@link AggregationBuilder} instance. | ||
*/ | ||
public abstract class AggregratorTestCase extends ESTestCase { |
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.
Aggregator
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 left some comments, but +1 to start from there.
when(searchContext.getQueryShardContext()).thenReturn(queryShardContext); | ||
|
||
@SuppressWarnings("unchecked") | ||
A aggregator = (A) aggregatorBuilder.build(searchContext, null).create(null, true); |
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 don't think the generics on this method are buying anything since we do a blind cast here?
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.
The reason I did the cast here is that we don't have to do the cast in all tests that need an aggregator.
aggregator.postCollection(); | ||
InternalMin result = (InternalMin) aggregator.buildAggregation(0L); | ||
assertEquals(-1.0, result.getValue(), 0); | ||
} |
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 also test what happens when no docs match the query?
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.
or when some docs match the query but do not have a value
*/ | ||
public abstract class AggregatorTestCase extends ESTestCase { | ||
|
||
protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregatorBuilder, |
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 call it aggregationBuilder rather than aggregatorBuilder to be more consistent with the class name?
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.
This looks like a good start! Thanks for working on that!
7b847a0
to
0346583
Compare
…terms`, `top_hits` and `min` aggregations.
0346583
to
417746c
Compare
Also adds some initial tests for some aggregations.
First PR for #22278.