Search in sources :

Example 16 with NonThrowingCloseable

use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.

the class SpanBuilderTest method startScopedSpanRootWithOptions.

@Test
public void startScopedSpanRootWithOptions() {
    StartSpanOptions startSpanOptions = new StartSpanOptions();
    startSpanOptions.setSampler(Samplers.neverSample());
    when(spanFactory.startSpan(isNull(Span.class), same(SPAN_NAME), eq(startSpanOptions))).thenReturn(span);
    NonThrowingCloseable ss = spanBuilder.becomeRoot().setSampler(Samplers.neverSample()).startScopedSpan();
    try {
        assertThat(tracer.getCurrentSpan()).isSameAs(span);
    } finally {
        ss.close();
    }
    verify(span).end(same(EndSpanOptions.DEFAULT));
}
Also used : NonThrowingCloseable(com.google.instrumentation.common.NonThrowingCloseable) Test(org.junit.Test)

Example 17 with NonThrowingCloseable

use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.

the class ContextUtilsTest method testWithStatsContext.

@Test
public void testWithStatsContext() {
    assertThat(ContextUtils.getCurrentStatsContext()).isNull();
    NonThrowingCloseable scopedStatsCtx = ContextUtils.withStatsContext(statsContext);
    try {
        assertThat(ContextUtils.getCurrentStatsContext()).isSameAs(statsContext);
    } finally {
        scopedStatsCtx.close();
    }
    assertThat(ContextUtils.getCurrentStatsContext()).isNull();
}
Also used : NonThrowingCloseable(com.google.instrumentation.common.NonThrowingCloseable) Test(org.junit.Test)

Aggregations

NonThrowingCloseable (com.google.instrumentation.common.NonThrowingCloseable)17 Test (org.junit.Test)13 Span (com.google.instrumentation.trace.Span)3 StatsContext (com.google.instrumentation.stats.StatsContext)1