Skip to content

Commit

Permalink
Add equality tests for FrontierNodeVersion.
Browse files Browse the repository at this point in the history
The frontier node version's representation is uniquely identified by the composition of its components, i.e. the precomputed byte array. So we can base the object's equality on that.

PiperOrigin-RevId: 681860462
Change-Id: I47ae11096b1d123219cca8c27f32c6387f9157da
  • Loading branch information
jin authored and copybara-github committed Oct 3, 2024
1 parent 0b0d908 commit 21e65e6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}. */
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 21e65e6

Please sign in to comment.