diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetriever.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetriever.java index 666ee573759ab5..fff88cd0d5cfd7 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetriever.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetriever.java @@ -33,6 +33,7 @@ import com.google.devtools.build.skyframe.SkyValue; import com.google.protobuf.ByteString; import java.io.IOException; +import java.util.Arrays; import java.util.concurrent.ExecutionException; /** Fetches remotely stored {@link SkyValue}s by {@link SkyKey}. */ @@ -349,18 +350,28 @@ public FrontierNodeVersion( this.blazeInstallMD5Fingerprint); } - @SuppressWarnings("unused") - public byte[] getTopLevelConfigFingerprint() { - return topLevelConfigFingerprint; - } - - @SuppressWarnings("unused") - public byte[] getDirectoryMatcherFingerprint() { - return directoryMatcherFingerprint; + public byte[] getPrecomputedFingerprint() { + return precomputedFingerprint; } public byte[] concat(byte[] input) { return Bytes.concat(precomputedFingerprint, input); } + + @Override + public int hashCode() { + return Arrays.hashCode(precomputedFingerprint); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof FrontierNodeVersion that)) { + return false; + } + return Arrays.equals(precomputedFingerprint, that.precomputedFingerprint); + } } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetrieverTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetrieverTest.java index 871fb254a6fb1d..7e784049915232 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetrieverTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/SkyValueRetrieverTest.java @@ -544,6 +544,50 @@ public void exceptionWhileWaitingForResult_throwsException() throws Exception { assertThat(thrown).hasCauseThat().hasMessageThat().contains("error setting value"); } + @Test + public void frontierNodeVersions_areEqual_ifTupleComponentsAreEqual() { + var first = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("bar"), HashCode.fromInt(42)); + var second = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("bar"), HashCode.fromInt(42)); + + assertThat(first.getPrecomputedFingerprint()).isEqualTo(second.getPrecomputedFingerprint()); + assertThat(first).isEqualTo(second); + } + + @Test + public void frontierNodeVersions_areNotEqual_ifTopLevelConfigChecksumIsDifferent() { + var first = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("bar"), HashCode.fromInt(42)); + var second = + new FrontierNodeVersion("CHANGED", ByteString.copyFromUtf8("bar"), HashCode.fromInt(42)); + + assertThat(first.getPrecomputedFingerprint()).isNotEqualTo(second.getPrecomputedFingerprint()); + assertThat(first).isNotEqualTo(second); + } + + @Test + public void frontierNodeVersions_areNotEqual_ifActiveDirectoriesAreDifferent() { + var first = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("bar"), HashCode.fromInt(42)); + var second = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("CHANGED"), HashCode.fromInt(42)); + + assertThat(first.getPrecomputedFingerprint()).isNotEqualTo(second.getPrecomputedFingerprint()); + assertThat(first).isNotEqualTo(second); + } + + @Test + public void frontierNodeVersions_areNotEqual_ifBlazeInstallMD5IsDifferent() { + var first = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("bar"), HashCode.fromInt(42)); + var second = + new FrontierNodeVersion("foo", ByteString.copyFromUtf8("bar"), HashCode.fromInt(9000)); + + assertThat(first.getPrecomputedFingerprint()).isNotEqualTo(second.getPrecomputedFingerprint()); + assertThat(first).isNotEqualTo(second); + } + // ---------- Begin SerializationStateProvider implementation ---------- @Override public SerializationState getSerializationState() {