-
Notifications
You must be signed in to change notification settings - Fork 114
Fix ResolvedKeySpacePath.equals and hashCode #3591
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
Merged
ScottDugas
merged 14 commits into
FoundationDB:main
from
ScottDugas:resolved-path-equals
Oct 17, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f153d1e
Test and fix ResolvedKeySpacePath.equals/hashCode
ScottDugas f6bdc40
Test with constant directories, and AnyValue
ScottDugas ffc000c
Explain reason for suppliers
ScottDugas a84876b
Ensure parent ResolvedKeySpacePaths are equal
ScottDugas c35d1d4
Add @Nonnull/@Nullable to test class
ScottDugas a070102
Remainder should be included in equals/hashCode + some cleanup
ScottDugas a64373e
Add parent to ResolvedKeySpacePath.hashCode()
ScottDugas 0720af5
Introduce a new KeySpaceDirectory.equalsIgnoringHierarchy
ScottDugas f2691b4
Utilize equalsIgnoringHierarchy and add a couple tests
ScottDugas 89174b8
Cover some test gaps
ScottDugas 98d4b03
Some more cleanup
ScottDugas 6db80e8
Instead of equalsIgnoringHierarchy just use reference equality
ScottDugas e4fbffd
Test methods should be package-protected
ScottDugas 03b2d0c
Update ResolvedKeySpacePathTest to only create one directory structure
ScottDugas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...test/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/PathValueTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* PathValueTest.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.provider.foundationdb.keyspace; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
/** | ||
* Tests for {@link PathValue}. | ||
*/ | ||
class PathValueTest { | ||
|
||
/** | ||
* Test data for PathValue equality tests. | ||
*/ | ||
static Stream<Arguments> equalPathValuePairs() { | ||
return Stream.of( | ||
Arguments.of("null values", null, null, null, null), | ||
Arguments.of("same string values", "test", null, "test", null), | ||
Arguments.of("same long values", 42L, null, 42L, null), | ||
Arguments.of("same boolean values", true, null, true, null), | ||
Arguments.of("same byte[] values", new byte[] {1, 2, 3}, null, new byte[] {1, 2, 3}, null), | ||
Arguments.of("same metadata", "test", new byte[]{1, 2, 3}, "test", new byte[]{1, 2, 3}) | ||
); | ||
} | ||
|
||
/** | ||
* Test data for PathValue inequality tests. | ||
*/ | ||
static Stream<Arguments> unequalPathValuePairs() { | ||
return Stream.of( | ||
Arguments.of("different string values", "test1", null, "test2", null), | ||
Arguments.of("different long values", 42L, null, 100L, null), | ||
Arguments.of("different boolean values", true, null, false, null), | ||
Arguments.of("different types", "string", null, 42L, null), | ||
Arguments.of("different metadata", "test", new byte[]{1, 2, 3}, "test", new byte[]{4, 5, 6}), | ||
Arguments.of("one null metadata", "test", new byte[]{1, 2, 3}, "test", null), | ||
Arguments.of("one null value", null, null, "test", null), | ||
Arguments.of("different value with same metadata", "test1", new byte[]{1, 2, 3}, "test2", new byte[]{1, 2, 3}) | ||
ohadzeliger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@MethodSource("equalPathValuePairs") | ||
void testEqualsAndHashCodeForEqualValues(String description, Object resolvedValue1, byte[] metadata1, | ||
Object resolvedValue2, byte[] metadata2) { | ||
PathValue value1 = new PathValue(resolvedValue1, metadata1); | ||
PathValue value2 = new PathValue(resolvedValue2, metadata2); | ||
|
||
assertEquals(value1, value2, "PathValues should be equal: " + description); | ||
assertEquals(value1.hashCode(), value2.hashCode(), "Equal PathValues should have equal hash codes: " + description); | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@MethodSource("unequalPathValuePairs") | ||
void testNotEqualsForUnequalValues(String description, Object resolvedValue1, byte[] metadata1, | ||
Object resolvedValue2, byte[] metadata2) { | ||
PathValue value1 = new PathValue(resolvedValue1, metadata1); | ||
PathValue value2 = new PathValue(resolvedValue2, metadata2); | ||
|
||
assertNotEquals(value1, value2, "PathValues should not be equal: " + description); | ||
} | ||
|
||
@Test | ||
void testTrivialEquality() { | ||
PathValue value1 = new PathValue("Foo", null); | ||
|
||
assertEquals(value1, value1, "Cover reference equality shortcut"); | ||
assertNotEquals("Foo", value1, "Check it doesn't fail with non-PathValue"); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.