Search in sources :

Example 6 with NonThrowingCloseable

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

the class TracerTest method getCurrentSpan_WithSpan.

@Test
public void getCurrentSpan_WithSpan() {
    assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
    NonThrowingCloseable ws = tracer.withSpan(span);
    try {
        assertThat(tracer.getCurrentSpan()).isSameAs(span);
    } finally {
        ws.close();
    }
    assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
}
Also used : NonThrowingCloseable(com.google.instrumentation.common.NonThrowingCloseable) Test(org.junit.Test)

Example 7 with NonThrowingCloseable

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

the class ContextUtilsTest method testWithStatsContextUsingWrap.

@Test
public void testWithStatsContextUsingWrap() {
    Runnable runnable;
    NonThrowingCloseable scopedStatsCtx = ContextUtils.withStatsContext(statsContext);
    try {
        assertThat(ContextUtils.getCurrentStatsContext()).isSameAs(statsContext);
        runnable = Context.current().wrap(new Runnable() {

            @Override
            public void run() {
                assertThat(ContextUtils.getCurrentStatsContext()).isSameAs(statsContext);
            }
        });
    } finally {
        scopedStatsCtx.close();
    }
    assertThat(ContextUtils.getCurrentStatsContext()).isNull();
    // When we run the runnable we will have the statsContext in the current Context.
    runnable.run();
}
Also used : NonThrowingCloseable(com.google.instrumentation.common.NonThrowingCloseable) Test(org.junit.Test)

Example 8 with NonThrowingCloseable

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

the class ContextUtilsTest method propagationViaRunnable.

@Test
public void propagationViaRunnable() {
    Runnable runnable = null;
    NonThrowingCloseable ws = ContextUtils.withSpan(span);
    try {
        assertThat(ContextUtils.getCurrentSpan()).isSameAs(span);
        runnable = Context.current().wrap(new Runnable() {

            @Override
            public void run() {
                assertThat(ContextUtils.getCurrentSpan()).isSameAs(span);
            }
        });
    } finally {
        ws.close();
    }
    assertThat(ContextUtils.getCurrentSpan()).isNotSameAs(span);
    // When we run the runnable we will have the span in the current Context.
    runnable.run();
}
Also used : NonThrowingCloseable(com.google.instrumentation.common.NonThrowingCloseable) Test(org.junit.Test)

Example 9 with NonThrowingCloseable

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

the class ContextUtilsTest method withSpan.

@Test
public void withSpan() {
    assertThat(ContextUtils.getCurrentSpan()).isNull();
    NonThrowingCloseable ws = ContextUtils.withSpan(span);
    try {
        assertThat(ContextUtils.getCurrentSpan()).isSameAs(span);
    } finally {
        ws.close();
    }
    assertThat(ContextUtils.getCurrentSpan()).isNull();
    ;
}
Also used : NonThrowingCloseable(com.google.instrumentation.common.NonThrowingCloseable) Test(org.junit.Test)

Example 10 with NonThrowingCloseable

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

the class ScopedSpanHandleTest method initAttachesSpan_CloseDetachesAndEndsSpan.

@Test
public void initAttachesSpan_CloseDetachesAndEndsSpan() {
    assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
    NonThrowingCloseable ss = new ScopedSpanHandle(span);
    try {
        assertThat(tracer.getCurrentSpan()).isSameAs(span);
    } finally {
        ss.close();
    }
    assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
    verify(span).end(same(EndSpanOptions.DEFAULT));
}
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