HDDS-14104. Refactor RequestContext creation#9493
Conversation
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @Russole for the patch. The change in RequestContext looks good. TestRequestContext can be simplified.
| .setIp(null) | ||
| .setHost(null) |
There was a problem hiding this comment.
nit: null is the default value in the builder for these properties, so this can be removed.
| .setIp(null) | |
| .setHost(null) |
| .setSessionPolicy(policy) | ||
| .build(); | ||
| assertTrue(context.isRecursiveAccessCheck(), "recursiveAccessCheck should be true"); | ||
| assertEquals(policy, context.getSessionPolicy(), "sessionPolicy should be set via constructor"); |
There was a problem hiding this comment.
Looks like testSessionPolicy() has been testing sessionPolicy for various ways of creating RequestContext. Now constructor is private and getBuilder no longer exists, so all variants are testing the builder. We can remove the parts that perform duplicate verifications, and simplify this to:
@Test
void testSessionPolicy() {
RequestContext.Builder builder = RequestContext.newBuilder();
assertNull(builder.build().getSessionPolicy(), "default value");
final String policy = "{\"Statement\":[]}";
builder.setSessionPolicy(policy);
assertEquals(policy, builder.build().getSessionPolicy());
}| RequestContext.Builder builder = RequestContext.newBuilder(); | ||
|
|
||
| assertFalse(builder.build().isRecursiveAccessCheck(), | ||
| "Wrongly sets recursive flag value"); |
There was a problem hiding this comment.
testRecursiveAccessFlag() has also been testing constructor, builder and getBuilder. Now there are only 3 possible combinations:
- default value (without explicit
setRecursiveAccessCheck) setRecursiveAccessCheck(false)setRecursiveAccessCheck(true)
So we can simplify this test case further:
@Test
void testRecursiveAccessFlag() {
RequestContext.Builder builder = RequestContext.newBuilder();
assertFalse(builder.build().isRecursiveAccessCheck(), "default value");
builder.setRecursiveAccessCheck(true);
assertTrue(builder.build().isRecursiveAccessCheck());
builder.setRecursiveAccessCheck(false);
assertFalse(builder.build().isRecursiveAccessCheck());
}getUserRequestContext() and baseBuilder() can be removed, as well as unused imports.
|
Thanks @adoroszlai for the review and suggestions. |
|
Thanks @Russole for updating the patch. |
What changes were proposed in this pull request?
Refactored RequestContext to use a builder-only construction pattern.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-14104
How was this patch tested?
All CI checks passed.