-
Notifications
You must be signed in to change notification settings - Fork 103
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
Add a class for comparing versions of the record layer #3036
Conversation
Result of fdb-record-layer-pr on Linux CentOS 7
|
db66999
to
74a17b8
Compare
Result of fdb-record-layer-pr on Linux CentOS 7
|
@@ -55,6 +55,7 @@ dependencies { | |||
implementation(libs.asciitable) | |||
implementation(libs.jsr305) | |||
implementation(libs.junit.api) | |||
implementation(libs.junit.params) |
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.
Ouch. I think this will conflict with a similar change I made.
* Thus, this spec implements only slightly more than what the Record Layer needs, which is to say: | ||
* a sequence of positive numbers ({@code 0|[1-9]\\d*} separated by {@code .}s, and an optional {@code -SNAPSHOT} | ||
* at the end. Each version component is compared as integers, and versions with a different number of components | ||
* are not comparable. A version with {@code -SNAPSHOT} version added to the less than the same set of numbers |
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.
The last sentence is unclear.
...-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersion.java
Show resolved
Hide resolved
"(?:\\+(?<buildMetadata>" + dotSeparated(BUILD_PART) + "))?$"); | ||
private static final Pattern NUMERIC_PATTERN = Pattern.compile("\\d+"); | ||
|
||
private final List<Integer> versionNumbers; |
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.
Some explanation of the prerelease
and metadata
parts (with example) could be useful.
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.
I added a comment about versionNumbers
and ``prerelease`. Some of that was in the class javadoc.
I decided to remove buildMetadata
. It's part of semver
, but we don't support it.
return false; | ||
} | ||
final SemanticVersion that = (SemanticVersion)o; | ||
return Objects.equals(versionNumbers, that.versionNumbers) && Objects.equals(prerelease, that.prerelease) && Objects.equals(buildMetadata, that.buildMetadata); |
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 is theoretical, but is there meaning to the order of prerelease strings?
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.
Yes, I added some flavor text to the javadoc on prerelease
that hopefully makes it clear that there is, but we don't really support it.
...-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersion.java
Show resolved
Hide resolved
if (NUMERIC_PATTERN.matcher(otherPart).matches()) { | ||
int thisNumber = Integer.parseInt(thisPart); | ||
int otherNumber = Integer.parseInt(otherPart); | ||
if (thisNumber < otherNumber) { |
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.
It may add extra cost of boxing and unboxing, but maybe Objects.compare()
here may be clearer?
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.
int result = Objects.compare(thisNumber, otherNumber);
if (result != 0) {
result result;
}
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.
Since we only support SNAPSHOT
or nothing, I removed this whole section, but I took your change and applied a variant of it to the version comparison code.
final SemanticVersion versionB = SemanticVersion.parse(rawVersionB); | ||
Assertions.assertAll( | ||
() -> assertEquals(0, versionA.compareTo(versionB)), | ||
() -> assertEquals(0, versionA.compareTo(versionB))); |
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.
() -> assertEquals(0, versionA.compareTo(versionB))); | |
() -> assertEquals(0, versionB.compareTo(versionA))); |
void alignsWithComparator(int versionA, int versionB) { | ||
// Ensure that the signage aligns with the standard `compare` methods | ||
// the value doesn't have to, but it does, and this is easier than asserting that they have the same sign | ||
assertEquals(Integer.compare(versionA, versionB), |
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.
Can't we use signum()?
assertEquals(
Integer.compare(a, b).signum(),
SemanticVersion.parse(versionA + ".0.0").compareTo(
SemanticVersion.parse(versionB + ".0.0")).signum();
() -> assertThrows(IllegalArgumentException.class, | ||
() -> versionA.compareTo(versionB)), | ||
() -> assertThrows(IllegalArgumentException.class, | ||
() -> versionA.compareTo(versionB))); |
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.
() -> versionA.compareTo(versionB))); | |
() -> versionB.compareTo(versionA))); |
Maybe add some tests with |
This does: 1. expands / cleans up comments in `SemanticVersion` 2. Removes buildMetadata from the regex, and the field. 3. Removes comparison of prerelease with more than one component. We already don't support parsing multiple components. 4. Take advantage of `Integer.compare` and `Integer.signum` in code and tests 5. Fix the tests that were supposed to alternate the comparison order but I accidentally put the same order in twice. 6. Test for null arguments, and add @nonnull annotations
Result of fdb-record-layer-pr on Linux CentOS 7
|
This does: 1. expands / cleans up comments in `SemanticVersion` 2. Removes buildMetadata from the regex, and the field. 3. Removes comparison of prerelease with more than one component. We already don't support parsing multiple components. 4. Take advantage of `Integer.compare` and `Integer.signum` in code and tests 5. Fix the tests that were supposed to alternate the comparison order but I accidentally put the same order in twice. 6. Test for null arguments, and add @nonnull annotations
d99ad0e
to
f291b97
Compare
Conflicted on yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/package-info.java but it was just comments (years and javadoc)
Result of fdb-record-layer-pr on Linux CentOS 7
|
Result of fdb-record-layer-pr on Linux CentOS 7
|
...-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersion.java
Outdated
Show resolved
Hide resolved
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.
Just one comment change
Co-authored-by: ohadzeliger <[email protected]>
Result of fdb-record-layer-pr on Linux CentOS 7
|
...-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/SemanticVersion.java
Outdated
Show resolved
Hide resolved
Result of fdb-record-layer-pr on Linux CentOS 7
|
This introduces a class for parsing and comparing versions of the Record Layer.
This can be combined with the work in #3031 to control what versions a yaml test will run against.