Skip to content
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

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

swamirishi
Copy link
Contributor

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

…ce to accomodate in the request validator framework

Change-Id: I4c1844a1dfb6127a73b46a92933db33b09c6b06e
Change-Id: I63cddb955ea6178cd489c2a83922576e8d2ea5eb
@adoroszlai
Copy link
Contributor

Please wait for clean CI run in fork before opening PR.

Copy link
Contributor

@adoroszlai adoroszlai left a 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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use @EnumSource for enums.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 65 to 73
@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());
}
Copy link
Contributor

@adoroszlai adoroszlai Dec 19, 2024

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, exlucde FUTURE_VERSION, get ClientVersion.version() in the test case
  • versions larger than latest existing are mapped to FUTURE_VERSION: parameterize with @ValueSource for int delta

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 45 to 52
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());
}
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.).

Copy link
Contributor Author

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
Copy link
Contributor

@adoroszlai adoroszlai left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
.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());
Copy link
Contributor

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

@swamirishi swamirishi requested a review from errose28 December 19, 2024 13:47
Copy link
Contributor

@sumitagrawl sumitagrawl left a 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.

@adoroszlai adoroszlai merged commit 7af38a9 into apache:master Dec 20, 2024
42 checks passed
@adoroszlai
Copy link
Contributor

Thanks @swamirishi for the patch, @sumitagrawl for the review.

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.

3 participants