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);
}
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();
}
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);
}
}
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);
}
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);
}
Aggregations