Search in sources :

Example 1 with Tag

use of io.opencensus.tags.Tag in project instrumentation-java by census-instrumentation.

the class TagMapImplTest method testIterator.

@Test
public void testIterator() {
    TagMapImpl tags = new TagMapImpl(ImmutableMap.of(K1, VM1, K2, VM2));
    Iterator<Tag> i = tags.getIterator();
    assertTrue(i.hasNext());
    Tag tag1 = i.next();
    assertTrue(i.hasNext());
    Tag tag2 = i.next();
    assertFalse(i.hasNext());
    assertThat(Arrays.asList(tag1, tag2)).containsExactly(Tag.create(K1, V1), Tag.create(K2, V2));
    thrown.expect(NoSuchElementException.class);
    i.next();
}
Also used : Tag(io.opencensus.tags.Tag) Test(org.junit.Test)

Example 2 with Tag

use of io.opencensus.tags.Tag in project instrumentation-java by census-instrumentation.

the class CorrelationContextFormatTest method inject_SkipNonPropagatingTag.

@Test
public void inject_SkipNonPropagatingTag() throws TagContextSerializationException {
    Map<String, String> carrier = new HashMap<String, String>();
    Tag tag = Tag.create(K1, V1, METADATA_NO_PROPAGATION);
    textFormat.inject(makeTagContext(tag), carrier, setter);
    assertThat(carrier).containsExactly(CORRELATION_CONTEXT, "");
}
Also used : HashMap(java.util.HashMap) Tag(io.opencensus.tags.Tag) Test(org.junit.Test)

Example 3 with Tag

use of io.opencensus.tags.Tag 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));
}
Also used : TagContext(io.opencensus.tags.TagContext) HashMap(java.util.HashMap) Tag(io.opencensus.tags.Tag) Test(org.junit.Test)

Example 4 with Tag

use of io.opencensus.tags.Tag 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);
}
Also used : TagContext(io.opencensus.tags.TagContext) Tag(io.opencensus.tags.Tag) Test(org.junit.Test)

Example 5 with Tag

use of io.opencensus.tags.Tag in project instrumentation-java by census-instrumentation.

the class TaggerImplTest method currentBuilder_RemoveDuplicateTags.

@Test
public void currentBuilder_RemoveDuplicateTags() {
    Tag tag1 = Tag.create(K1, V1);
    Tag tag2 = Tag.create(K1, V2);
    TagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
    TagContextBuilder result = getResultOfCurrentBuilder(tagContextWithDuplicateTags);
    assertThat(tagContextToList(result.build())).containsExactly(tag2);
}
Also used : TagContext(io.opencensus.tags.TagContext) Tag(io.opencensus.tags.Tag) TagContextBuilder(io.opencensus.tags.TagContextBuilder) Test(org.junit.Test)

Aggregations

Tag (io.opencensus.tags.Tag)18 Test (org.junit.Test)13 TagContext (io.opencensus.tags.TagContext)10 HashMap (java.util.HashMap)5 TagContextBuilder (io.opencensus.tags.TagContextBuilder)2 TagContextSerializationException (io.opencensus.tags.propagation.TagContextSerializationException)2 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 TagMapImpl (io.opencensus.implcore.tags.TagMapImpl)1 TagValueWithMetadata (io.opencensus.implcore.tags.TagValueWithMetadata)1 TagKey (io.opencensus.tags.TagKey)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1