aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java
diff options
context:
space:
mode:
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.java25
1 files changed, 23 insertions, 2 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 09f6878d..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
@@ -78,9 +78,30 @@ public class TagContextDeserializationTest {
@Test
public void testDeserializeTooLargeByteArrayThrowException()
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 : "0123", 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(str, 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("last", "last1", output);
+
+ byte[] bytes = output.toByteArray();
thrown.expect(TagContextDeserializationException.class);
- thrown.expectMessage("Size of input byte[] exceeds the maximum serialized size ");
- serializer.fromByteArray(new byte[SerializationUtils.TAGCONTEXT_SERIALIZED_SIZE_LIMIT + 1]);
+ thrown.expectMessage("Size of TagContext exceeds the maximum serialized size ");
+ serializer.fromByteArray(bytes);
}
@Test