Skip to content

[BEAM-2541] Check Elasticsearch backend version when the pipeline is run not when it is constructed#3493

Closed
echauchot wants to merge 4 commits intoapache:masterfrom
echauchot:BEAM-2541-move-ES-version-check-to-validate
Closed

[BEAM-2541] Check Elasticsearch backend version when the pipeline is run not when it is constructed#3493
echauchot wants to merge 4 commits intoapache:masterfrom
echauchot:BEAM-2541-move-ES-version-check-to-validate

Conversation

@echauchot
Copy link
Copy Markdown
Contributor

Be sure to do all of the following to help us incorporate your contribution
quickly and easily:

  • Make sure the PR title is formatted like:
    [BEAM-<Jira issue #>] Description of pull request
  • Make sure tests pass via mvn clean verify.
  • Replace <Jira issue #> in the title with the actual Jira issue
    number, if there is one.
  • If this contribution is large, please file an Apache
    Individual Contributor License Agreement.

R: @jbonofre

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.02%) to 70.829% when pulling f64156c on echauchot:BEAM-2541-move-ES-version-check-to-validate into b8ac326 on apache:master.

Copy link
Copy Markdown
Contributor

@peihe peihe left a comment

Choose a reason for hiding this comment

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

Is that possible to add a unit test (maybe by mocking or faking RestClient)?

@Experimental(Experimental.Kind.SOURCE_SINK)
public class ElasticsearchIO {

private static void checkVersion(ConnectionConfiguration connectionConfiguration)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move it back to keep the history (And, I think private methods are not that important to be on the top.)

Copy link
Copy Markdown
Contributor Author

@echauchot echauchot Jul 19, 2017

Choose a reason for hiding this comment

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

Previously checkVersion was in ConnectionConfiguration class. I cannot move it back to that class because otherwise version check would be done at configuration time and all the point of this PR is to do the check at run time and not at configuration time. But I agree, with the other part of your comment: private method needs to be at the bottom, I'll move the method at the bottom of ElasticsearchIO class

@Override
public void validate(PipelineOptions options) {
ConnectionConfiguration connectionConfiguration = getConnectionConfiguration();
checkState(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

update to checkNotNull (since you are here)

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.

-1. There was a discussion about that in the original PR (#1439) and also in https://issues.apache.org/jira/browse/BEAM-959 (see also related PR). CheckNotNull does not generate an explicit enough message to users in that case. And besides the javadoc of checkNotNull specifies "Ensures that an object reference passed as a parameter to the calling method is not null". It is not a parameter in that case.

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.

+1 with @echauchot: checkArgument() and checkState() should be always preferred.

@Override
public void validate(PipelineOptions options) {
ConnectionConfiguration connectionConfiguration = getConnectionConfiguration();
checkState(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

update to checkNotNull (since you are here)

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.

see above

connectionConfiguration != null,
"ElasticsearchIO.write() requires a connection configuration"
+ " to be set via withConnectionConfiguration(configuration)");
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

catch checkVersion and re-throw in checkVersion.

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.

Totally agree, thanks.

@peihe
Copy link
Copy Markdown
Contributor

peihe commented Jul 17, 2017

R: +@peihe

@echauchot
Copy link
Copy Markdown
Contributor Author

@peihe, thanks for your review.
I'll mock the RestClient to test checkVersion (mainly to verify that the exception is thrown while running the pipeline and not while configuring it) and ping you for another look.

@echauchot echauchot force-pushed the BEAM-2541-move-ES-version-check-to-validate branch from f64156c to 8a3acfb Compare July 21, 2017 10:09
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.01%) to 70.599% when pulling 8a3acfb on echauchot:BEAM-2541-move-ES-version-check-to-validate into 1d9160f on apache:master.

@echauchot
Copy link
Copy Markdown
Contributor Author

echauchot commented Jul 21, 2017

I pushed another commit for the unit testing checkVersion using mock that you required. But I find it is a weak test because in the end, it just tests json parsing and exception throwing as we cannot use mocks in a real pipeline because mocks are not serializable. @peihe WDYT?

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.003%) to 70.606% when pulling 186115c on echauchot:BEAM-2541-move-ES-version-check-to-validate into 1d9160f on apache:master.

@peihe
Copy link
Copy Markdown
Contributor

peihe commented Jul 24, 2017

I agree mocking the response string in the unit tests doesn't have much value, and the string is hard to understand and maintain. So, I would prefer to revert the last commit.
The rest changes looks good to me.

@jbonofre
Copy link
Copy Markdown
Member

Agree to revert the last commit.

@echauchot
Copy link
Copy Markdown
Contributor Author

We all agree that the UT of checkVersion is very weak, I'll remove the last commit

@echauchot echauchot force-pushed the BEAM-2541-move-ES-version-check-to-validate branch from 186115c to 8a3acfb Compare July 24, 2017 09:22
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 70.596% when pulling 8a3acfb on echauchot:BEAM-2541-move-ES-version-check-to-validate into f54072a on apache:master.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.2%) to 70.404% when pulling 5bbbbfd on echauchot:BEAM-2541-move-ES-version-check-to-validate into f54072a on apache:master.

@echauchot
Copy link
Copy Markdown
Contributor Author

@jbonofre, I pushed a cleaning commit, PTAL.

@echauchot echauchot force-pushed the BEAM-2541-move-ES-version-check-to-validate branch from 5bbbbfd to 5ca988a Compare July 27, 2017 15:25
Copy link
Copy Markdown
Member

@jbonofre jbonofre left a comment

Choose a reason for hiding this comment

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

LGTM. I'm waiting the end of Jenkins before merging. Thanks !

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 70.471% when pulling 5ca988a on echauchot:BEAM-2541-move-ES-version-check-to-validate into 892a2cf on apache:master.

@asfgit asfgit closed this in 6ca5305 Jul 28, 2017
@echauchot echauchot deleted the BEAM-2541-move-ES-version-check-to-validate branch July 28, 2017 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants