aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java
diff options
context:
space:
mode:
authorsebright <sebright@google.com>2017-11-17 13:05:55 -0800
committerGitHub <noreply@github.com>2017-11-17 13:05:55 -0800
commit55fcf06522a1ff0eac6ebb49ebfeb7279df046b6 (patch)
tree264dee8707567759be2a1435a20d7249899c912f /impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java
parent467028253aa02ce7e0763a9d472dc0dde8f3038d (diff)
parent0f344d4f0d98f8d65a783a93b763eff00446d69b (diff)
downloadopencensus-java-55fcf06522a1ff0eac6ebb49ebfeb7279df046b6.tar.gz
Merge pull request #811 from sebright/test-deserializing-duplicate-tag-keys
Test deserializing duplicate tag keys and duplicate tags.
Diffstat (limited to 'impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java')
-rw-r--r--impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java62
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 273a6ce2..a2245255 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
@@ -158,6 +158,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);