aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2017-11-17 13:53:21 -0800
committerKristen Kozak <sebright@google.com>2017-11-17 13:53:28 -0800
commitb9a69dc944c75483a39827618b3457b8839f91b3 (patch)
tree69835a50b9ae6964a4a3676ea054c3f50ad5b616 /impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java
parent55fcf06522a1ff0eac6ebb49ebfeb7279df046b6 (diff)
downloadopencensus-java-b9a69dc944c75483a39827618b3457b8839f91b3.tar.gz
Test deserializing TagContext with all duplicate keys that is over size limit.
TagContextBinarySerializer.fromByteArray should throw an exception, even though the input represents a relatively small TagContext.
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.java31
1 files changed, 31 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 a2245255..c465ee94 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
@@ -104,6 +104,37 @@ public class TagContextDeserializationTest {
serializer.fromByteArray(bytes);
}
+ // Deserializing this input should cause an error, even though it represents a relatively small
+ // TagContext.
+ @Test
+ public void testDeserializeTooLargeByteArrayThrowException_WithDuplicateTagKeys()
+ throws TagContextDeserializationException {
+ ByteArrayDataOutput output = ByteStreams.newDataOutput();
+ output.write(SerializationUtils.VERSION_ID);
+ for (int i = 0; i < SerializationUtils.TAGCONTEXT_SERIALIZED_SIZE_LIMIT / 8 - 1; i++) {
+ // Each tag will be with format {key : "key_", value : "0123"}, so the length of it is 8.
+ String str;
+ if (i < 10) {
+ str = "000" + i;
+ } else if (i < 100) {
+ str = "00" + i;
+ } else if (i < 1000) {
+ str = "0" + i;
+ } else {
+ str = String.valueOf(i);
+ }
+ encodeTagToOutput("key_", str, output);
+ }
+ // The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
+ // more than limit.
+ encodeTagToOutput("key_", "last1", output);
+
+ byte[] bytes = output.toByteArray();
+ thrown.expect(TagContextDeserializationException.class);
+ thrown.expectMessage("Size of TagContext exceeds the maximum serialized size ");
+ serializer.fromByteArray(bytes);
+ }
+
@Test
public void testDeserializeInvalidTagKey() throws TagContextDeserializationException {
ByteArrayDataOutput output = ByteStreams.newDataOutput();