-
Notifications
You must be signed in to change notification settings - Fork 507
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
HDDS-11963. Unify client version and layout version under one interface to accomodate in the request validator framework #7598
Conversation
…ce to accomodate in the request validator framework Change-Id: I4c1844a1dfb6127a73b46a92933db33b09c6b06e
Change-Id: I63cddb955ea6178cd489c2a83922576e8d2ea5eb
Please wait for clean CI run in fork before opening PR. |
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.
Thanks @swamirishi for continuing work on the request validator.
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("layoutValues") |
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 @EnumSource
for enums.
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.
done
@ParameterizedTest | ||
@MethodSource("clientVersionValues") | ||
void testClientVersionExtractor(ClientVersion expectedClientVersion, int clientVersion) { | ||
OMRequest request = mock(OMRequest.class); | ||
when(request.getVersion()).thenReturn(clientVersion); | ||
Version version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); | ||
assertEquals(expectedClientVersion, version); | ||
assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); | ||
} |
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.
Split to two test cases:
- finds existing version: parameterize with
@EnumSource
, exlucdeFUTURE_VERSION
, getClientVersion.version()
in the test case - versions larger than latest existing are mapped to
FUTURE_VERSION
: parameterize with@ValueSource
forint delta
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.
done
private static Stream<Arguments> clientVersionValues() { | ||
return Stream.of( | ||
Arrays.stream(ClientVersion.values()) | ||
.map(clientVersion -> Arguments.of(clientVersion, clientVersion.version())), | ||
IntStream.range(1, 10) | ||
.mapToObj(delta -> Arguments.of(ClientVersion.FUTURE_VERSION, ClientVersion.CURRENT_VERSION + delta)) | ||
).flatMap(Function.identity()); | ||
} |
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.
Unnecessary complexity for simple test cases.
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.
addressed the review comments to simplify
/** | ||
* Base class defining the version in the entire system. | ||
*/ | ||
public interface Version { |
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.
Versioned
may be better for an interface (like Cloneable
, etc.).
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.
done
Change-Id: I11bff280f429d2eb64f8828887f7349e169e938f
Change-Id: I9ebc447eb9b60caa69e140b06fe899c58dd712a3
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.
Thanks @swamirishi for improving the patch, LGTM.
I have two more nits. They can be addressed in follow-up PR you'll be working on for the request validator, unless someone else requests other changes.
ClientVersion[] versions = ClientVersion.values(); | ||
return versions[versions.length - 2]; | ||
return Arrays.stream(ClientVersion.values()) | ||
.max(Comparator.comparingInt(ComponentVersion::toProtoValue)).orElse(null); |
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.
nit:
.max(Comparator.comparingInt(ComponentVersion::toProtoValue)).orElse(null); | |
.max(Comparator.comparingInt(ClientVersion::toProtoValue)).orElseThrow(); |
when(request.getVersion()).thenReturn(ClientVersion.CURRENT_VERSION + futureVersion); | ||
Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); | ||
assertEquals(ClientVersion.FUTURE_VERSION, version); | ||
assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); |
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.
nit: move assertion about classes to separate test case
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, part of #6932 as breakdown.
Thanks @swamirishi for the patch, @sumitagrawl for the review. |
What changes were proposed in this pull request?
Currently LayoutVersion & ClientVersion classes don't have a common base class even though they represent some sort version in the overall system. We should unify both these classes under one single interface which would help us perform some set of operations on the common base class in the request validator framework.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-11963
How was this patch tested?
Added new unit tests & existing unit tests