Search in sources :

Example 1 with ScopeManager

use of io.opentracing.ScopeManager in project jaeger-client-java by jaegertracing.

the class TracingRequestInterceptorTest method testProcessNullScope.

@Test
public void testProcessNullScope() throws Exception {
    ScopeManager mockScopeManager = Mockito.mock(ScopeManager.class);
    when(mockScopeManager.active()).thenReturn(null);
    Tracer mockTracer = Mockito.mock(Tracer.class);
    when(mockTracer.scopeManager()).thenReturn(mockScopeManager);
    HttpRequestInterceptor interceptor = new TracingRequestInterceptor(mockTracer);
    PowerMockito.spy(interceptor);
    HttpRequest mockRequest = Mockito.mock(HttpRequest.class);
    HttpContext mockContext = Mockito.mock(HttpContext.class);
    interceptor.process(mockRequest, mockContext);
    PowerMockito.verifyPrivate(interceptor, times(0)).invoke("onSpanStarted", any(Span.class), mockRequest, mockContext);
}
Also used : HttpRequest(org.apache.http.HttpRequest) ScopeManager(io.opentracing.ScopeManager) Tracer(io.opentracing.Tracer) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) HttpContext(org.apache.http.protocol.HttpContext) Span(io.opentracing.Span) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ScopeManager

use of io.opentracing.ScopeManager in project jaeger-client-java by jaegertracing.

the class PropagationTest method testCustomScopeManager.

@Test
public void testCustomScopeManager() {
    Scope scope = mock(Scope.class);
    Tracer tracer = new Tracer.Builder("test", new InMemoryReporter(), new ConstSampler(true)).withScopeManager(new ScopeManager() {

        @Override
        public Scope activate(io.opentracing.Span span, boolean finishSpanOnClose) {
            return scope;
        }

        @Override
        public Scope active() {
            return scope;
        }
    }).build();
    assertEquals(scope, tracer.scopeManager().active());
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) ScopeManager(io.opentracing.ScopeManager) Scope(io.opentracing.Scope) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Test(org.junit.Test)

Aggregations

ScopeManager (io.opentracing.ScopeManager)2 Test (org.junit.Test)2 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)1 ConstSampler (com.uber.jaeger.samplers.ConstSampler)1 Scope (io.opentracing.Scope)1 Span (io.opentracing.Span)1 Tracer (io.opentracing.Tracer)1 HttpRequest (org.apache.http.HttpRequest)1 HttpRequestInterceptor (org.apache.http.HttpRequestInterceptor)1 HttpContext (org.apache.http.protocol.HttpContext)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1