use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextDeserializationTest method testDeserializeNoTags.
@Test
public void testDeserializeNoTags() throws TagContextDeserializationException {
TagContext expected = tagger.empty();
TagContext actual = serializer.fromByteArray(new byte[] { BinarySerializationUtils.VERSION_ID });
// One byte that represents Version ID.
assertThat(actual).isEqualTo(expected);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextDeserializationTest method testDeserializeOneTag.
@Test
public void testDeserializeOneTag() throws TagContextDeserializationException {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.write(BinarySerializationUtils.VERSION_ID);
encodeTagToOutput("Key", "Value", output);
TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key"), TagValue.create("Value")).build();
assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextDeserializationTest method testDeserializeDuplicateKeys.
@Test
public void testDeserializeDuplicateKeys() throws TagContextDeserializationException {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.write(BinarySerializationUtils.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);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextSerializationTest method testSerializeTooLargeTagContext.
@Test
public void testSerializeTooLargeTagContext() throws TagContextSerializationException {
TagContextBuilder builder = tagger.emptyBuilder();
for (int i = 0; i < BinarySerializationUtils.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);
}
builder.put(TagKey.create(str), TagValue.create(str));
}
// The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
// more than limit.
builder.put(TagKey.create("last"), TagValue.create("last1"));
TagContext tagContext = builder.build();
thrown.expect(TagContextSerializationException.class);
thrown.expectMessage("Size of TagContext exceeds the maximum serialized size ");
serializer.toByteArray(tagContext);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testRecord_MeasureNotMatch.
private void testRecord_MeasureNotMatch(Measure measure1, Measure measure2, double value) {
viewManager.registerView(createCumulativeView(VIEW_NAME, measure1, MEAN, Arrays.asList(KEY)));
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
putToMeasureMap(statsRecorder.newMeasureMap(), measure2, value).record(tags);
ViewData view = viewManager.getView(VIEW_NAME);
assertThat(view.getAggregationMap()).isEmpty();
}
Aggregations