Skip to content

Convert InternalAggTestCase to AbstractNamedWriteableTestCase#55250

Merged
polyfractal merged 7 commits intoelastic:masterfrom
polyfractal:internal_agg_namedwriteable_test
Apr 17, 2020
Merged

Convert InternalAggTestCase to AbstractNamedWriteableTestCase#55250
polyfractal merged 7 commits intoelastic:masterfrom
polyfractal:internal_agg_namedwriteable_test

Conversation

@polyfractal
Copy link
Copy Markdown
Contributor

Some aggregations, such as the Terms* family, will use an alternate class to represent unmapped shard results (while the rest of the aggs use the same object but with some form of "empty" or "nullish" values to represent unmapped).

This was problematic with AbstractWireSerializingTestCase because it expects the instanceReader to always match the original class. Instead, we need to use the NamedWriteable version so that the registry can be consulted for the proper deserialization reader.

Fixes #55149

Some aggregations, such as the Terms* family, will use an alternate
class to represent unmapped shard results (while the rest of the aggs
use the same object but with some form of "empty" or "nullish" values
to represent unmapped).

This was problematic with AbstractWireSerializingTestCase because it
expects the instanceReader to always match the original class.  Instead,
we need to use the NamedWriteable version so that the registry
can be consulted for the proper deserialization reader.
@polyfractal polyfractal added >test Issues or PRs that are addressing/adding tests :Analytics/Aggregations Aggregations v8.0.0 v7.8.0 labels Apr 15, 2020
@polyfractal polyfractal requested a review from nik9000 April 15, 2020 16:58
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

import static org.hamcrest.Matchers.lessThanOrEqualTo;

public abstract class InternalAggregationTestCase<T extends InternalAggregation> extends AbstractWireSerializingTestCase<T> {
public abstract class InternalAggregationTestCase<T extends InternalAggregation> extends AbstractNamedWriteableTestCase<T> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is worth adding a comment that subclasses need to make sure that xContentRegistry includes the agg we're going to parse. Built in aggs are included automatically but other aggs won't be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Buncha xpack tests needed this treatment, and it was non-trivial for tests to convert aggspecs into namedwriteables, so I did a bit of refactoring to make it easier in the general case.

*/
@Override
@SuppressWarnings("unchecked")
protected Class<T> categoryClass() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be final?

Copy link
Copy Markdown
Contributor Author

@polyfractal polyfractal Apr 15, 2020

Choose a reason for hiding this comment

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

It could be. I left it non-final in case an implementor needs to override it for some reason. But I suppose with the generic bounds on <InternalAggregation> it's pretty definitive what the class should be...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do think this should be final then. I guess the suppresswarnings means that the bounds on AbstractNamedWriteableTestCase are wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah to be honest I really have no idea what's going on with the generic... scratched my head over it for a while and just gave up :/

I'll make final 👍

*/
protected List<NamedWriteableRegistry.Entry> getNamedWriteables() {
List<NamedWriteableRegistry.Entry> entries
= new ArrayList<>(new SearchModule(Settings.EMPTY, emptyList()).getNamedWriteables());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you pass the plugins in instead of emptyList() then I think SearchModule will do this stuff for you.

Copy link
Copy Markdown
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM

@polyfractal
Copy link
Copy Markdown
Contributor Author

Thanks @nik9000!

@polyfractal polyfractal merged commit d72eb68 into elastic:master Apr 17, 2020
polyfractal pushed a commit that referenced this pull request Apr 17, 2020
Some aggregations, such as the Terms* family, will use an alternate
class to represent unmapped shard results (while the rest of the aggs
use the same object but with some form of "empty" or "nullish" values
to represent unmapped).

This was problematic with AbstractWireSerializingTestCase because it
expects the instanceReader to always match the original class.  Instead,
we need to use the NamedWriteable version so that the registry
can be consulted for the proper deserialization reader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/Aggregations Aggregations >test Issues or PRs that are addressing/adding tests v7.8.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] SignificantLongTermsTests.testReduceRandom failure on 7x

4 participants