-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
HADOOP-18980. Invalid inputs for getTrimmedStringCollectionSplitByEquals (ADDENDUM) #6546
Conversation
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed; mainly about use of intercept()
if (!emptyKey && !emptyVal) { | ||
pairs.put(splitByKeyVal[0], splitByKeyVal[1]); | ||
} else { | ||
throw new IllegalArgumentException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Preconditions.checkArgument(!emptyKey && !emptyVal with its built in string formatting.
STRING_COLLECTION_SPLIT_EQUALS_INVALID_ARG + " Input: " + str); | ||
} | ||
} else { | ||
throw new IllegalArgumentException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, make a precondition on L511
.containsEntry("element.first.key1", "element.first.val1"); | ||
|
||
try { | ||
StringUtils.getTrimmedStringCollectionSplitByEquals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LambdaTestUtils.intercept(). It's predictable I will insist on that, so save time in future. and it includes a string value check. so all you need is
intercept(IllegalArgumentException.class,
STRING_COLLECTION_SPLIT_EQUALS_INVALID_ARG, () ->
StringUtils.getTrimmedStringCollectionSplitByEquals(
"element.abc.key1="));
See: much better. and if the closure doesn't fail, will even include the string value of the result in the exception raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, that's already an amazing utility
final Configuration configuration = new Configuration(); | ||
configuration.set("custom_key", " = element.abc.val1"); | ||
try { | ||
S3AUtils.getTrimmedStringCollectionSplitByEquals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intercept(), and again, consider a factored out assertion to call repeatedly
*/ | ||
@Test | ||
public void testStringCollectionSplitByEquals2() { | ||
final Configuration configuration = new Configuration(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use new Configuration(false); ensures no core-site/auth-keys values can interferer
.hasMessageStartingWith(STRING_COLLECTION_SPLIT_EQUALS_INVALID_ARG); | ||
} | ||
|
||
configuration.set( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pull the expected-to-succeed tests into their own test case.
Addressed comments in the latest revision. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@steveloughran the PR is ready for another round of review if you have some bandwidth. |
@steveloughran a gentle reminder :) |
Addressed previous review with the latest revision. |
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
production code looks good, just want to tune the test code so
- there's as little cut and paste test code with the maintenance costs that come with that
- different tests are in their own test methods, for isolation
* Tests for the string utility that will be used by S3A credentials provider. | ||
*/ | ||
@Test | ||
public void testStringCollectionSplitByEqualsFailure() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be better off with a helper method "expectInvalidArgument(value)" and 5 separate test methods. less code, more isolation.
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java
Show resolved
Hide resolved
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
+1
remember: save time by not using copy and paste in tests, as you know I'm fussy there...
in trunk; testing cherrypick to 3.4 |
…als (ADDENDUM) (#6546) This is a followup to #6406: HADOOP-18980. S3A credential provider remapping: make extensible It adds extra validation of key-value pairs in a configuration option, with tests. Contributed by Viraj Jasani
Jira: HADOOP-18980