Search in sources :

Example 61 with TagContext

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

Example 62 with TagContext

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

Example 63 with TagContext

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

Example 64 with TagContext

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

the class CorrelationContextFormatTest method extract.

@Test
public void extract() throws TagContextDeserializationException {
    Map<String, String> carrier = Collections.singletonMap(CORRELATION_CONTEXT, "k1=v1,k2=v2");
    TagContext tagContext = textFormat.extract(carrier, getter);
    assertThat(TagsTestUtil.tagContextToList(tagContext)).containsExactly(T1, T2);
}
Also used : TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 65 with TagContext

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

the class TagContextRoundtripTest method testRoundtripSerialization.

private void testRoundtripSerialization(TagContext expected) throws Exception {
    byte[] bytes = serializer.toByteArray(expected);
    TagContext actual = serializer.fromByteArray(bytes);
    assertThat(actual).isEqualTo(expected);
}
Also used : TagContext(io.opencensus.tags.TagContext)

Aggregations

TagContext (io.opencensus.tags.TagContext)76 Test (org.junit.Test)56 Tag (io.opencensus.tags.Tag)10 TagContextBuilder (io.opencensus.tags.TagContextBuilder)9 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)7 Context (io.grpc.Context)6 Scope (io.opencensus.common.Scope)5 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)5 View (io.opencensus.stats.View)5 ViewData (io.opencensus.stats.ViewData)5 Metadata (io.grpc.Metadata)3 StatsTestUtils (io.grpc.internal.testing.StatsTestUtils)3 MeasureMap (io.opencensus.stats.MeasureMap)3 TagValue (io.opencensus.tags.TagValue)3 SpanContext (io.opencensus.trace.SpanContext)3 HashMap (java.util.HashMap)3 ServerStreamTracer (io.grpc.ServerStreamTracer)2 CallAttemptsTracerFactory (io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)2 HttpRequestContext (io.opencensus.contrib.http.HttpRequestContext)2 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)2