use of io.opencensus.tags.Tag 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.Tag in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method extract_OverrideTagWithSpaces.
@Test
public void extract_OverrideTagWithSpaces() throws TagContextDeserializationException {
Map<String, String> carrier = Collections.singletonMap(CORRELATION_CONTEXT, "k1= v1, k1=v2 ");
Tag expected = Tag.create(K1, V2, METADATA_UNLIMITED_PROPAGATION);
TagContext tagContext = textFormat.extract(carrier, getter);
assertThat(TagsTestUtil.tagContextToList(tagContext)).containsExactly(expected);
}
use of io.opencensus.tags.Tag in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method inject_TooManyTags.
@Test
public void inject_TooManyTags() throws TagContextSerializationException {
Tag[] tags = new Tag[CorrelationContextFormat.MAX_NUMBER_OF_TAGS + 1];
for (int i = 0; i < tags.length; i++) {
tags[i] = Tag.create(TagKey.create("k" + i), TagValue.create("v" + i), METADATA_UNLIMITED_PROPAGATION);
}
TagContext tagContext = makeTagContext(tags);
Map<String, String> carrier = new HashMap<String, String>();
thrown.expect(TagContextSerializationException.class);
textFormat.inject(tagContext, carrier, setter);
}
use of io.opencensus.tags.Tag in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method inject_SizeTooLarge.
@Test
public void inject_SizeTooLarge() throws TagContextSerializationException {
Tag[] tags = new Tag[40];
for (int i = 0; i < tags.length; i++) {
tags[i] = Tag.create(TagKey.create(generateRandom(240)), TagValue.create(generateRandom(240)), METADATA_UNLIMITED_PROPAGATION);
}
TagContext tagContext = makeTagContext(tags);
Map<String, String> carrier = new HashMap<String, String>();
thrown.expect(TagContextSerializationException.class);
textFormat.inject(tagContext, carrier, setter);
}
use of io.opencensus.tags.Tag in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method extract_WithUnknownProperties.
@Test
public void extract_WithUnknownProperties() throws TagContextDeserializationException {
Map<String, String> carrier = Collections.singletonMap(CORRELATION_CONTEXT, "k1=v1;property1=p1;property2=p2,k2=v2");
Tag expected = Tag.create(K1, TagValue.create("v1"), METADATA_UNLIMITED_PROPAGATION);
TagContext tagContext = textFormat.extract(carrier, getter);
assertThat(TagsTestUtil.tagContextToList(tagContext)).containsExactly(expected, T2);
}
Aggregations