Search in sources :

Example 6 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_StatsDisabled.

@Test
@SuppressWarnings("deprecation")
public void record_StatsDisabled() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    statsComponent.setState(StatsCollectionState.DISABLED);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    assertThat(viewManager.getView(VIEW_NAME)).isEqualTo(createEmptyViewData(view));
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 7 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_CurrentContextSet.

@Test
public void record_CurrentContextSet() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    TagContext tags = new SimpleTagContext(Tag.create(KEY, VALUE));
    Context orig = ContextUtils.withValue(Context.current(), tags).attach();
    try {
        statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record();
    } finally {
        Context.current().detach(orig);
    }
    ViewData viewData = viewManager.getView(VIEW_NAME);
    // record() should have used the given TagContext.
    assertThat(viewData.getAggregationMap().keySet()).containsExactly(Arrays.asList(VALUE));
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) Context(io.grpc.Context) TagContext(io.opencensus.tags.TagContext) SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) TagContext(io.opencensus.tags.TagContext) SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Aggregations

SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)7 View (io.opencensus.stats.View)6 Test (org.junit.Test)6 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)4 ViewData (io.opencensus.stats.ViewData)4 MeasureMap (io.opencensus.stats.MeasureMap)2 TagContext (io.opencensus.tags.TagContext)2 Context (io.grpc.Context)1