Search in sources :

Example 11 with TagContext

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

the class ViewManagerImplTest method testRecordCumulative.

private void testRecordCumulative(Measure measure, Aggregation aggregation, double... values) {
    View view = createCumulativeView(VIEW_NAME, measure, aggregation, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 2));
    viewManager.registerView(view);
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    for (double val : values) {
        putToMeasureMap(statsRecorder.newMeasureMap(), measure, val).record(tags);
    }
    clock.setTime(Timestamp.create(3, 4));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData.getView()).isEqualTo(view);
    assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 2), Timestamp.create(3, 4)));
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(aggregation, measure, values)), EPSILON);
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View)

Example 12 with TagContext

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

the class ScopedTagMapTest method withTagContext.

@Test
public void withTagContext() {
    assertThat(tagContextToList(tagger.getCurrentTagContext())).isEmpty();
    TagContext scopedTags = tagger.emptyBuilder().put(KEY_1, VALUE_1).build();
    Scope scope = tagger.withTagContext(scopedTags);
    try {
        assertThat(tagger.getCurrentTagContext()).isSameInstanceAs(scopedTags);
    } finally {
        scope.close();
    }
    assertThat(tagContextToList(tagger.getCurrentTagContext())).isEmpty();
}
Also used : Scope(io.opencensus.common.Scope) TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 13 with TagContext

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

the class CurrentTagMapUtilsTest method testGetCurrentTagMap_ContextSetToNull.

@Test
public void testGetCurrentTagMap_ContextSetToNull() {
    Context orig = ContextUtils.withValue(Context.current(), null).attach();
    try {
        TagContext tags = CurrentTagMapUtils.getCurrentTagMap();
        assertThat(tags).isNotNull();
        assertThat(tagContextToList(tags)).isEmpty();
    } finally {
        Context.current().detach(orig);
    }
}
Also used : Context(io.grpc.Context) TagContext(io.opencensus.tags.TagContext) TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 14 with TagContext

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

the class TagMapImplTest method put_existingKey.

@Test
public void put_existingKey() {
    TagContext tags = new TagMapImpl(ImmutableMap.of(K1, VM1));
    assertThat(((TagMapImpl) tagger.toBuilder(tags).put(K1, V2).build()).getTags()).containsExactly(K1, VM2);
}
Also used : TagContext(io.opencensus.tags.TagContext) Test(org.junit.Test)

Example 15 with TagContext

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

the class TagMapImplTest method putPropagating.

@Test
public void putPropagating() {
    TagContext tags1 = tagger.emptyBuilder().put(K1, V1, METADATA_UNLIMITED_PROPAGATION).build();
    TagContext tags2 = tagger.emptyBuilder().putPropagating(K1, V1).build();
    assertThat(tags1).isEqualTo(tags2);
}
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