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

Remove unused xContent serialization logic in transport objects. #49346

Merged
merged 3 commits into from
Nov 22, 2019

Conversation

jtibshirani
Copy link
Contributor

Previously, request and response objects related to index creation and mappings
were used in both the transport layer and HLRC. Now that they are no longer
shared, we can remove the extra xContent serialization + deserialization logic.

Previously, request and response objects related to index creation and mappings
were used in both the transport layer and HLRC. Now that they are no longer
shared, we can remove the extra xContent serialization + deserialization logic.
@jtibshirani jtibshirani added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 labels Nov 19, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@jtibshirani
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/oss-distro-docs

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Hi @jtibshirani, thanks for taking care of this, great to be able to remove a bunch of duplicated code.
I left a few comments around testing where I think we might be losing a bit of coverage. Let me know what you think.

mapping.endObject();
mapping.endObject();
request.source(mapping);
public void testFromXContent() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Reading this I was wondering if we need this test at all anymore. The way I understand the server-side request class, is just stores the mapping source definition as a Json String, which is converted back to a map somewhere else I suppose. Let me know what you think, maybe we don't need this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After looking at the logic more closely, I agree this test doesn't seem too valuable.

Copy link
Member

Choose a reason for hiding this comment

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

It might even be worth looking into why we store the source as a json string when we later parse it to a map. But that's digressing from this PR, I can make a note of that and take a look.

@@ -118,65 +112,4 @@ public void testMappingKeyedByType() throws IOException {
assertEquals(request1.mappings(), request2.mappings());
}
}

@Override
protected PutIndexTemplateRequest createTestInstance() {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the server side PutIndexTemplateRequest still supports internal wire serialization, which I think we should still test using random instances. Maybe changing this test to one of the AbstractWire*TestCase (tbh I'm getting confused which one would be appropriate) would be good, as long as we are able to detect faulty writeTo/readFrom implementation if we e.g. add new parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had initially tried this out, but ended up uncovering some small bugs in PutIndexTemplateRequest. So I planned to defer the change to a follow-up PR -- is that okay with you? Currently the test just extends AbstractXContentTestCase, so it doesn't test wire serialization and I don't think we are regressing test coverage in that regard.

Copy link
Member

Choose a reason for hiding this comment

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

No problem, I assumed AbstractXContentTestCase would also include wire serialization tests. I was wrong, but thats part of why I dislike our growing AbstractWire/XContent/*/TestCase family of base tests, because after a while its hard to remember what exactly they are doing. If you could open an issue that we should test serialization here and maybe add your findings about the "small bugs" that you found, that would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


@Override
protected PutIndexTemplateRequest doParseInstance(XContentParser parser) throws IOException {
return new PutIndexTemplateRequest().source(parser.map());
Copy link
Member

Choose a reason for hiding this comment

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

If we don't test parsing for this request any more, we should maybe unit test the source(Map<String, Object> templateSource) method directly here. There's a bunch of code in there that e.g. throws exceptions sets request properties. I think we call this in the PutIndexTemplateRequestTests in the client module, but for good unit testing coverage I think we should add independent testing to this class as well.
This could be done in this PR or in a follow up issue as far as I'm concerned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will add a couple tests around PutIndexTemplateRequest#source.

@jtibshirani
Copy link
Contributor Author

@cbuescher I tried to address your comments, this is now ready for another look.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, I like the additional test.
Can you open the issue around adding wire serialization testing for PutIndexTemplateRequest and link it here before closing the PR?

@jtibshirani
Copy link
Contributor Author

I opened #49507 to track the lack of tests for wire serialization.

@jtibshirani jtibshirani merged commit 17e9cd5 into elastic:master Nov 22, 2019
@jtibshirani jtibshirani deleted the remove-xcontent-serialization branch November 22, 2019 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants