diff options
author | 2018-04-10 15:16:09 -0700 | |
---|---|---|
committer | 2018-04-10 15:17:20 -0700 | |
commit | 2b533aba878698d50525826fd3e40571af87a1b9 (patch) | |
tree | 5e9e04befc6d1f035e8f128e1d35f7d8cd200031 /src/test/java/com/google/devtools/build/lib/skyframe | |
parent | 9594f2c454acf71beb4bccdcf4f7e40c83288e51 (diff) |
Add value constants to ObjectCodecRegistry. Value constants are to be used when there may not be a canonical instance of the object we want (or the canonical instance isn't available at registry construction time), but we can reasonably cheaply do value equality comparisons. Strings are a good example.
PiperOrigin-RevId: 192354865
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skyframe')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecRegistryTest.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecRegistryTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecRegistryTest.java index dca168b6c6..b5272defcc 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecRegistryTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecRegistryTest.java @@ -118,15 +118,15 @@ public class ObjectCodecRegistryTest { ObjectCodecRegistry underTest1 = ObjectCodecRegistry.newBuilder() .setAllowDefaultCodec(false) - .addConstant(constant1) - .addConstant(constant2) - .addConstant(constant1) + .addReferenceConstant(constant1) + .addReferenceConstant(constant2) + .addReferenceConstant(constant1) .build(); ObjectCodecRegistry underTest2 = ObjectCodecRegistry.newBuilder() .setAllowDefaultCodec(false) - .addConstant(constant1) - .addConstant(constant2) + .addReferenceConstant(constant1) + .addReferenceConstant(constant2) .build(); assertThat(underTest1.maybeGetTagForConstant(constant1)).isEqualTo(3); assertThat(underTest1.maybeGetTagForConstant(constant2)).isEqualTo(2); @@ -135,6 +135,19 @@ public class ObjectCodecRegistryTest { } @Test + public void valueConstant() { + String valueConstant = "ab"; + ObjectCodecRegistry underTest = + ObjectCodecRegistry.newBuilder() + .setAllowDefaultCodec(false) + .addValueConstant(valueConstant) + .build(); + assertThat(underTest.maybeGetTagForConstant("a")).isNull(); + assertThat(underTest.maybeGetTagForConstant("ab")).isNotNull(); + assertThat(underTest.maybeGetTagForConstant("cab".substring(1))).isNotNull(); + } + + @Test public void testGetBuilder() throws NoCodecException { SingletonCodec<String> codec1 = SingletonCodec.of("value1", "mnemonic1"); SingletonCodec<Integer> codec2 = SingletonCodec.of(1, "mnemonic2"); @@ -145,7 +158,7 @@ public class ObjectCodecRegistryTest { .setAllowDefaultCodec(false) .add(codec1) .add(codec2) - .addConstant(constant) + .addReferenceConstant(constant) .build(); ObjectCodecRegistry copy = underTest.getBuilder().build(); |