use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method roundTrip.
@Test
public void roundTrip() throws TagContextSerializationException, TagContextDeserializationException {
Tag[] tags = new Tag[40];
for (int i = 0; i < tags.length; i++) {
tags[i] = Tag.create(TagKey.create(generateRandom(10)), TagValue.create(generateRandom(10)), METADATA_UNLIMITED_PROPAGATION);
}
TagContext tagContext = makeTagContext(tags);
Map<String, String> carrier = new HashMap<String, String>();
textFormat.inject(tagContext, carrier, setter);
TagContext actual = textFormat.extract(carrier, getter);
assertThat(TagsTestUtil.tagContextToList(actual)).containsExactlyElementsIn(TagsTestUtil.tagContextToList(tagContext));
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method extract_Empty.
@Test
public void extract_Empty() throws TagContextDeserializationException {
Map<String, String> carrier = Collections.singletonMap(CORRELATION_CONTEXT, "");
TagContext tagContext = textFormat.extract(carrier, getter);
assertThat(TagsTestUtil.tagContextToList(tagContext)).isEmpty();
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormatTest method extract_TrimSpaces.
@Test
public void extract_TrimSpaces() throws TagContextDeserializationException {
Map<String, String> carrier = Collections.singletonMap(CORRELATION_CONTEXT, "k1= v1, k2=v2 ");
Tag expected1 = Tag.create(K1, V1, METADATA_UNLIMITED_PROPAGATION);
Tag expected2 = Tag.create(K2, V2, METADATA_UNLIMITED_PROPAGATION);
TagContext tagContext = textFormat.extract(carrier, getter);
assertThat(TagsTestUtil.tagContextToList(tagContext)).containsExactly(expected1, expected2);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextDeserializationTest method testDeserializeNonConsecutiveDuplicateKeys.
@Test
public void testDeserializeNonConsecutiveDuplicateKeys() throws TagContextDeserializationException {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.write(BinarySerializationUtils.VERSION_ID);
encodeTagToOutput("Key1", "Value1", output);
encodeTagToOutput("Key2", "Value2", output);
encodeTagToOutput("Key3", "Value3", output);
encodeTagToOutput("Key1", "Value4", output);
encodeTagToOutput("Key2", "Value5", output);
TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value4")).put(TagKey.create("Key2"), TagValue.create("Value5")).put(TagKey.create("Key3"), TagValue.create("Value3")).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 testDeserializeDuplicateTags.
@Test
public void testDeserializeDuplicateTags() throws TagContextDeserializationException {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.write(BinarySerializationUtils.VERSION_ID);
encodeTagToOutput("Key1", "Value1", output);
encodeTagToOutput("Key1", "Value1", output);
TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value1")).build();
assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
Aggregations