Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 977a795

Browse files
authored
Merge pull request #814 from sebright/test-deserializing-duplicate-keys-over-size-limit
Test deserializing TagContext with all duplicate keys that is over size limit.
2 parents 4c36f49 + b9a69dc commit 977a795

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,37 @@ public void testDeserializeTooLargeByteArrayThrowException()
104104
serializer.fromByteArray(bytes);
105105
}
106106

107+
// Deserializing this input should cause an error, even though it represents a relatively small
108+
// TagContext.
109+
@Test
110+
public void testDeserializeTooLargeByteArrayThrowException_WithDuplicateTagKeys()
111+
throws TagContextDeserializationException {
112+
ByteArrayDataOutput output = ByteStreams.newDataOutput();
113+
output.write(SerializationUtils.VERSION_ID);
114+
for (int i = 0; i < SerializationUtils.TAGCONTEXT_SERIALIZED_SIZE_LIMIT / 8 - 1; i++) {
115+
// Each tag will be with format {key : "key_", value : "0123"}, so the length of it is 8.
116+
String str;
117+
if (i < 10) {
118+
str = "000" + i;
119+
} else if (i < 100) {
120+
str = "00" + i;
121+
} else if (i < 1000) {
122+
str = "0" + i;
123+
} else {
124+
str = String.valueOf(i);
125+
}
126+
encodeTagToOutput("key_", str, output);
127+
}
128+
// The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
129+
// more than limit.
130+
encodeTagToOutput("key_", "last1", output);
131+
132+
byte[] bytes = output.toByteArray();
133+
thrown.expect(TagContextDeserializationException.class);
134+
thrown.expectMessage("Size of TagContext exceeds the maximum serialized size ");
135+
serializer.fromByteArray(bytes);
136+
}
137+
107138
@Test
108139
public void testDeserializeInvalidTagKey() throws TagContextDeserializationException {
109140
ByteArrayDataOutput output = ByteStreams.newDataOutput();

0 commit comments

Comments
 (0)