diff options
author | Kristen Kozak <sebright@google.com> | 2017-11-17 12:37:12 -0800 |
---|---|---|
committer | Kristen Kozak <sebright@google.com> | 2017-11-17 12:51:24 -0800 |
commit | 0f344d4f0d98f8d65a783a93b763eff00446d69b (patch) | |
tree | c4523ba39b02e5b65f94f1fd9ecce408a6125132 | |
parent | f01394e3f067a8045e8a5651bbc5b95622d8a37e (diff) | |
download | opencensus-java-0f344d4f0d98f8d65a783a93b763eff00446d69b.tar.gz |
Test deserializing duplicate tag keys and duplicate tags.
Deserialization should succeed, and only the last tag value should be used.
-rw-r--r-- | impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java b/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java index f6d8dd09..09f6878d 100644 --- a/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java +++ b/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java @@ -137,6 +137,68 @@ public class TagContextDeserializationTest { } @Test + public void testDeserializeDuplicateKeys() throws TagContextDeserializationException { + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.write(SerializationUtils.VERSION_ID); + encodeTagToOutput("Key1", "Value1", output); + encodeTagToOutput("Key1", "Value2", output); + TagContext expected = + tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value2")).build(); + assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected); + } + + @Test + public void testDeserializeNonConsecutiveDuplicateKeys() + throws TagContextDeserializationException { + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.write(SerializationUtils.VERSION_ID); + encodeTagToOutput("Key1", "Value1", output); + encodeTagToOutput("Key2", "Value2", output); + encodeTagToOutput("Key3", "Value3", output); + encodeTagToOutput("Key1", "Value4", output); + encodeTagToOutput("Key2", "Value5", output); + TagContext expected = + tagger + .emptyBuilder() + .put(TagKey.create("Key1"), TagValue.create("Value4")) + .put(TagKey.create("Key2"), TagValue.create("Value5")) + .put(TagKey.create("Key3"), TagValue.create("Value3")) + .build(); + assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected); + } + + @Test + public void testDeserializeDuplicateTags() throws TagContextDeserializationException { + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.write(SerializationUtils.VERSION_ID); + encodeTagToOutput("Key1", "Value1", output); + encodeTagToOutput("Key1", "Value1", output); + TagContext expected = + tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value1")).build(); + assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected); + } + + @Test + public void testDeserializeNonConsecutiveDuplicateTags() + throws TagContextDeserializationException { + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.write(SerializationUtils.VERSION_ID); + encodeTagToOutput("Key1", "Value1", output); + encodeTagToOutput("Key2", "Value2", output); + encodeTagToOutput("Key3", "Value3", output); + encodeTagToOutput("Key1", "Value1", output); + encodeTagToOutput("Key2", "Value2", output); + TagContext expected = + tagger + .emptyBuilder() + .put(TagKey.create("Key1"), TagValue.create("Value1")) + .put(TagKey.create("Key2"), TagValue.create("Value2")) + .put(TagKey.create("Key3"), TagValue.create("Value3")) + .build(); + assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected); + } + + @Test public void stopParsingAtUnknownField() throws TagContextDeserializationException { ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.write(SerializationUtils.VERSION_ID); |