aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java
diff options
context:
space:
mode:
authorGravatar cpeyser <cpeyser@google.com>2018-06-13 13:06:17 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-13 13:07:41 -0700
commit9bbc66c8613deb4233e3cb116d0aae5724eece7f (patch)
treec1a95e1cb6b0370a616f5d9daf9ce966a6d6fea0 /src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java
parentd6bd9eb43b8e4b47acd4e5003b586bd47edaba4e (diff)
Allow deserialization futures as NestedSet contents, with unrolling blocking on that future.
This allows NestedSet deserialization not to block on storage reads - in-progress deserializations are simply made a member of the NestedSets they produce. PiperOrigin-RevId: 200440131
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java
index ea455f87e1..36171b5cdc 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java
@@ -23,6 +23,7 @@ import com.google.devtools.build.lib.skyframe.serialization.SerializationExcepti
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
+import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester.VerificationFunction;
import java.io.IOException;
/** Utilities for testing NestedSet serialization. */
@@ -49,7 +50,7 @@ public class NestedSetCodecTestUtils {
return false;
}
HasNestedSet that = (HasNestedSet) o;
- return Objects.equal(nestedSetField.rawChildren(), that.nestedSetField.rawChildren());
+ return Objects.equal(nestedSetField.getChildren(), that.nestedSetField.getChildren());
}
@Override
@@ -59,7 +60,8 @@ public class NestedSetCodecTestUtils {
}
/** Perform serialization/deserialization checks for several simple NestedSet examples. */
- public static void checkCodec(ObjectCodecs objectCodecs, boolean allowFutureBlocking)
+ public static void checkCodec(
+ ObjectCodecs objectCodecs, boolean allowFutureBlocking, boolean assertSymmetricEquality)
throws Exception {
new SerializationTester(
NestedSetBuilder.emptySet(Order.STABLE_ORDER),
@@ -86,7 +88,7 @@ public class NestedSetCodecTestUtils {
new HasNestedSet(NestedSetBuilder.create(Order.STABLE_ORDER, "a"))))
.setObjectCodecs(objectCodecs)
.makeMemoizingAndAllowFutureBlocking(allowFutureBlocking)
- .setVerificationFunction(NestedSetCodecTestUtils::verifyDeserialization)
+ .setVerificationFunction(verificationFunction(assertSymmetricEquality))
.runTests();
}
@@ -94,15 +96,21 @@ public class NestedSetCodecTestUtils {
NestedSetStore store, NestedSet<?> nestedSet, SerializationContext serializationContext)
throws IOException, SerializationException {
return store
- .computeFingerprintAndStore((Object[]) nestedSet.rawChildren(), serializationContext)
+ .computeFingerprintAndStore((Object[]) nestedSet.getChildren(), serializationContext)
.writeStatus();
}
- private static void verifyDeserialization(
- NestedSet<String> subject, NestedSet<String> deserialized) {
- assertThat(subject.getOrder()).isEqualTo(deserialized.getOrder());
- assertThat(subject.toSet()).isEqualTo(deserialized.toSet());
- verifyStructure(subject.rawChildren(), deserialized.rawChildren());
+ private static VerificationFunction<NestedSet<String>> verificationFunction(
+ boolean assertSymmetricEquality) {
+ return (subject, deserialized) -> {
+ if (assertSymmetricEquality) {
+ assertThat(subject).isEqualTo(deserialized);
+ assertThat(deserialized).isEqualTo(subject);
+ }
+ assertThat(subject.getOrder()).isEqualTo(deserialized.getOrder());
+ assertThat(subject.toSet()).isEqualTo(deserialized.toSet());
+ verifyStructure(subject.getChildren(), deserialized.getChildren());
+ };
}
private static void verifyStructure(Object lhs, Object rhs) {