Search in sources :

Example 1 with MockContext

use of io.opentracing.mock.MockSpan.MockContext in project batfish by batfish.

the class WorkItemTest method testInjectExtract.

@Test
public void testInjectExtract() {
    MockContext sourceContext;
    try (ActiveSpan activeSpan = _mockTracer.buildSpan("test span").startActive()) {
        SpanContext sourceContextTmp = activeSpan.context();
        assertThat(sourceContextTmp, instanceOf(MockContext.class));
        sourceContext = (MockContext) sourceContextTmp;
        _workItem.setSourceSpan(activeSpan, _mockTracer);
    }
    SpanContext extractedContextTmp = _workItem.getSourceSpan(_mockTracer);
    assertThat(extractedContextTmp, notNullValue());
    assertThat(extractedContextTmp, instanceOf(MockContext.class));
    MockContext extractedContext = (MockContext) extractedContextTmp;
    // test that injected and extracted spans have same span context data
    assertThat(extractedContext.traceId(), equalTo(sourceContext.traceId()));
    assertThat(extractedContext.spanId(), equalTo(sourceContext.spanId()));
}
Also used : MockContext(io.opentracing.mock.MockSpan.MockContext) SpanContext(io.opentracing.SpanContext) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) ActiveSpan(io.opentracing.ActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) Test(org.junit.Test)

Aggregations

ActiveSpan (io.opentracing.ActiveSpan)1 NoopActiveSpan (io.opentracing.NoopActiveSpanSource.NoopActiveSpan)1 SpanContext (io.opentracing.SpanContext)1 MockContext (io.opentracing.mock.MockSpan.MockContext)1 ThreadLocalActiveSpan (io.opentracing.util.ThreadLocalActiveSpan)1 Test (org.junit.Test)1