Search in sources :

Example 26 with TagContext

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

the class TagContextDeserializationTest method stopParsingAtUnknownField.

@Test
public void stopParsingAtUnknownField() throws TagContextDeserializationException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.write(BinarySerializationUtils.VERSION_ID);
    encodeTagToOutput("Key1", "Value1", output);
    encodeTagToOutput("Key2", "Value2", output);
    // Write unknown field ID 1.
    output.write(1);
    output.write(new byte[] { 1, 2, 3, 4 });
    encodeTagToOutput("Key3", "Value3", output);
    // key 3 should not be included
    TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value1")).put(TagKey.create("Key2"), TagValue.create("Value2")).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 27 with TagContext

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

the class TagContextDeserializationTest method testDeserializeNonConsecutiveDuplicateTags.

@Test
public void testDeserializeNonConsecutiveDuplicateTags() 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", "Value1", output);
    encodeTagToOutput("Key2", "Value2", output);
    TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value1")).put(TagKey.create("Key2"), TagValue.create("Value2")).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 28 with TagContext

use of io.opencensus.tags.TagContext 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)

Example 29 with TagContext

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

the class TaggerImplTest method getCurrentTagContext_SkipNullTag.

@Test
public void getCurrentTagContext_SkipNullTag() {
    TagContext tagContextWithNullTag = new SimpleTagContext(TAG1, null, TAG2);
    TagContext result = getResultOfGetCurrentTagContext(tagContextWithNullTag);
    assertThat(tagContextToList(result)).containsExactly(TAG1, TAG2);
}
Also used : TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 30 with TagContext

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

the class TaggerImplTest method toBuilder_ConvertUnknownTagContextToTagMapImpl.

@Test
public void toBuilder_ConvertUnknownTagContextToTagMapImpl() {
    TagContext unknownTagContext = new SimpleTagContext(TAG1, TAG2, TAG3);
    TagContext newTagContext = tagger.toBuilder(unknownTagContext).build();
    assertThat(tagContextToList(newTagContext)).containsExactly(TAG1, TAG2, TAG3);
    assertThat(newTagContext).isInstanceOf(TagMapImpl.class);
}
Also used : TagContext(io.opencensus.tags.TagContext) 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