Skip to content
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

Adds unit test for sampler aggregation #23243

Merged
merged 3 commits into from
Feb 21, 2017

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Feb 17, 2017

Relates to #22278

@nik9000 nik9000 added review >test Issues or PRs that are addressing/adding tests v6.0.0-alpha1 labels Feb 17, 2017
/**
* Unwrap an aggregator. Used for testing.
*/
public static Aggregator unwrap(Aggregator in) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super comfortable about exposing this but I can't think of a much better way to actually close the aggregations during testing without reworking aggregations to make parent aggs close their subaggregations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do searchContext.clearReleasables(Lifetime.PHASE) like the main code does since all aggregators are supposed to register themselves on to the search context.

when(queryShardContext.fieldMapper(fieldType.name())).thenReturn(fieldType);
when(queryShardContext.getForField(fieldType)).thenReturn(fieldData);
when(queryShardContext.getForField(fieldType)).then(invocation -> fieldType.fielddataBuilder().build(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blew up without fielddata enabled so I made it return when used instead of all the time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a suggestion for the closing issue.

/**
* Unwrap an aggregator. Used for testing.
*/
public static Aggregator unwrap(Aggregator in) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do searchContext.clearReleasables(Lifetime.PHASE) like the main code does since all aggregators are supposed to register themselves on to the search context.

when(queryShardContext.fieldMapper(fieldType.name())).thenReturn(fieldType);
when(queryShardContext.getForField(fieldType)).thenReturn(fieldData);
when(queryShardContext.getForField(fieldType)).then(invocation -> fieldType.fielddataBuilder().build(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

Sampler sampler = searchAndReduce(searcher, new TermQuery(new Term("text", "good")), aggBuilder, textFieldType,
numericFieldType);
Min min = sampler.getAggregations().get("min");
assertEquals(5.0, min.getValue(), Double.MIN_NORMAL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Double.MIN_NORMAL/0/ ? the computation of the min value should not be subject to accuracy issues.

@nik9000
Copy link
Member Author

nik9000 commented Feb 21, 2017

@jpountz, I pushed the changes you asked for. Kind of. Have a look?

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are a mockito artist! LGTM.

@nik9000 nik9000 merged commit 7475175 into elastic:master Feb 21, 2017
@nik9000
Copy link
Member Author

nik9000 commented Feb 21, 2017

You are a mockito artist! LGTM.

Thanks!

@nik9000 nik9000 deleted the sampler_unit_tests branch February 21, 2017 17:52
@nik9000
Copy link
Member Author

nik9000 commented Feb 21, 2017

Grumble grumble, it looks like this merged instead of squashed, rebased, and merged. I must have lost my cookie.... Sorry!

@cbuescher
Copy link
Member

Backported to 5.x with d73d89c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>test Issues or PRs that are addressing/adding tests v5.4.0 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants