[BEAM-2541] Check Elasticsearch backend version when the pipeline is run not when it is constructed#3493
Conversation
peihe
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Move it back to keep the history (And, I think private methods are not that important to be on the top.)
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
update to checkNotNull (since you are here)
There was a problem hiding this comment.
-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.
There was a problem hiding this comment.
+1 with @echauchot: checkArgument() and checkState() should be always preferred.
| @Override | ||
| public void validate(PipelineOptions options) { | ||
| ConnectionConfiguration connectionConfiguration = getConnectionConfiguration(); | ||
| checkState( |
There was a problem hiding this comment.
update to checkNotNull (since you are here)
| connectionConfiguration != null, | ||
| "ElasticsearchIO.write() requires a connection configuration" | ||
| + " to be set via withConnectionConfiguration(configuration)"); | ||
| try { |
There was a problem hiding this comment.
catch checkVersion and re-throw in checkVersion.
There was a problem hiding this comment.
Totally agree, thanks.
|
R: +@peihe |
|
@peihe, thanks for your review. |
f64156c to
8a3acfb
Compare
|
I pushed another commit for the unit testing |
|
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. |
|
Agree to revert the last commit. |
|
We all agree that the UT of |
186115c to
8a3acfb
Compare
|
@jbonofre, I pushed a cleaning commit, PTAL. |
…run not when it is constructed
5bbbbfd to
5ca988a
Compare
jbonofre
left a comment
There was a problem hiding this comment.
LGTM. I'm waiting the end of Jenkins before merging. Thanks !
Be sure to do all of the following to help us incorporate your contribution
quickly and easily:
[BEAM-<Jira issue #>] Description of pull requestmvn clean verify.<Jira issue #>in the title with the actual Jira issuenumber, if there is one.
Individual Contributor License Agreement.
R: @jbonofre