Search in sources :

Example 46 with TagContext

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

the class TagContextDeserializationTest method testDeserializeNoTags.

@Test
public void testDeserializeNoTags() throws TagContextDeserializationException {
    TagContext expected = tagger.empty();
    TagContext actual = serializer.fromByteArray(new byte[] { BinarySerializationUtils.VERSION_ID });
    // One byte that represents Version ID.
    assertThat(actual).isEqualTo(expected);
}
Also used : TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 47 with TagContext

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

the class TagContextDeserializationTest method testDeserializeOneTag.

@Test
public void testDeserializeOneTag() throws TagContextDeserializationException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.write(BinarySerializationUtils.VERSION_ID);
    encodeTagToOutput("Key", "Value", output);
    TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key"), TagValue.create("Value")).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 48 with TagContext

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

the class TagContextDeserializationTest method testDeserializeDuplicateKeys.

@Test
public void testDeserializeDuplicateKeys() throws TagContextDeserializationException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.write(BinarySerializationUtils.VERSION_ID);
    encodeTagToOutput("Key1", "Value1", output);
    encodeTagToOutput("Key1", "Value2", output);
    TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key1"), 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 49 with TagContext

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

the class TagContextSerializationTest method testSerializeTooLargeTagContext.

@Test
public void testSerializeTooLargeTagContext() throws TagContextSerializationException {
    TagContextBuilder builder = tagger.emptyBuilder();
    for (int i = 0; i < BinarySerializationUtils.TAGCONTEXT_SERIALIZED_SIZE_LIMIT / 8 - 1; i++) {
        // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
        String str;
        if (i < 10) {
            str = "000" + i;
        } else if (i < 100) {
            str = "00" + i;
        } else if (i < 1000) {
            str = "0" + i;
        } else {
            str = String.valueOf(i);
        }
        builder.put(TagKey.create(str), TagValue.create(str));
    }
    // The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
    // more than limit.
    builder.put(TagKey.create("last"), TagValue.create("last1"));
    TagContext tagContext = builder.build();
    thrown.expect(TagContextSerializationException.class);
    thrown.expectMessage("Size of TagContext exceeds the maximum serialized size ");
    serializer.toByteArray(tagContext);
}
Also used : TagContext(io.opencensus.tags.TagContext) TagContextBuilder(io.opencensus.tags.TagContextBuilder) Test(org.junit.Test)

Example 50 with TagContext

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

the class ViewManagerImplTest method testRecord_MeasureNotMatch.

private void testRecord_MeasureNotMatch(Measure measure1, Measure measure2, double value) {
    viewManager.registerView(createCumulativeView(VIEW_NAME, measure1, MEAN, Arrays.asList(KEY)));
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    putToMeasureMap(statsRecorder.newMeasureMap(), measure2, value).record(tags);
    ViewData view = viewManager.getView(VIEW_NAME);
    assertThat(view.getAggregationMap()).isEmpty();
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData)

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