Search in sources :

Example 21 with TagContext

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

Example 22 with 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();
}
Also used : TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 23 with TagContext

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

Example 24 with TagContext

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);
}
Also used : TagContext(io.opencensus.tags.TagContext) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) Test(org.junit.Test)

Example 25 with TagContext

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);
}
Also used : TagContext(io.opencensus.tags.TagContext) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) Test(org.junit.Test)

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