use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TagContextSerializationTest method testSerialize.
private void testSerialize(Tag... tags) throws IOException, TagContextSerializationException {
TagContextBuilder builder = tagger.emptyBuilder();
for (Tag tag : tags) {
builder.put(tag.getKey(), tag.getValue());
}
byte[] actual = serializer.toByteArray(builder.build());
Collection<List<Tag>> tagPermutation = Collections2.permutations(Arrays.asList(tags));
Set<String> possibleOutputs = new HashSet<String>();
for (List<Tag> list : tagPermutation) {
ByteArrayOutputStream expected = new ByteArrayOutputStream();
expected.write(BinarySerializationUtils.VERSION_ID);
for (Tag tag : list) {
expected.write(BinarySerializationUtils.TAG_FIELD_ID);
encodeString(tag.getKey().getName(), expected);
encodeString(tag.getValue().asString(), expected);
}
possibleOutputs.add(new String(expected.toByteArray(), Charsets.UTF_8));
}
assertThat(possibleOutputs).contains(new String(actual, Charsets.UTF_8));
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TagMapImplTest method put_nullValue.
@Test
public void put_nullValue() {
TagContext tags = new TagMapImpl(ImmutableMap.of(K1, VM1));
TagContextBuilder builder = tagger.toBuilder(tags);
thrown.expect(NullPointerException.class);
thrown.expectMessage("value");
builder.put(K2, null);
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TagContextRoundtripTest method testRoundtrip_TagContextWithMaximumSize.
@Test
public void testRoundtrip_TagContextWithMaximumSize() throws Exception {
TagContextBuilder builder = tagger.emptyBuilder();
for (int i = 0; i < BinarySerializationUtils.TAGCONTEXT_SERIALIZED_SIZE_LIMIT / 8; i++) {
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
// Add 1024 tags, the total size should just be 8192.
String str;
if (i < 10) {
str = "000" + i;
} else if (i < 100) {
str = "00" + i;
} else if (i < 1000) {
str = "0" + i;
} else {
str = "" + i;
}
builder.put(TagKey.create(str), TagValue.create(str));
}
testRoundtripSerialization(builder.build());
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TaggerImplTest method emptyBuilder.
@Test
public void emptyBuilder() {
TagContextBuilder builder = tagger.emptyBuilder();
assertThat(builder).isInstanceOf(TagMapBuilderImpl.class);
assertThat(tagContextToList(builder.build())).isEmpty();
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TaggerImplTest method emptyBuilder_TaggingReenabled.
@Test
public void emptyBuilder_TaggingReenabled() {
tagsComponent.setState(TaggingState.DISABLED);
assertThat(tagger.emptyBuilder()).isSameInstanceAs(NoopTagMapBuilder.INSTANCE);
tagsComponent.setState(TaggingState.ENABLED);
TagContextBuilder builder = tagger.emptyBuilder();
assertThat(builder).isInstanceOf(TagMapBuilderImpl.class);
assertThat(tagContextToList(builder.put(K1, V1).build())).containsExactly(Tag.create(K1, V1));
}
Aggregations