Skip to content

Commit

Permalink
Add Clearable test for OpenTracing propagation
Browse files Browse the repository at this point in the history
Tests must be extended when the following PR is merged:
opentracing/opentracing-java#313
  • Loading branch information
sjoerdtalsma committed Oct 24, 2018
1 parent ee7db9b commit 73ff552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class SpanManager implements ContextManager<Span> {
*/
@Override
public Context<Span> getActiveContext() {
return new ManagedSpan(GlobalTracer.get().activeSpan(), null);
Span activeSpan = GlobalTracer.get().activeSpan();
return activeSpan == null ? null : new ManagedSpan(activeSpan, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.opentracing.util.ThreadLocalScopeManager;
import nl.talsmasoftware.context.Context;
import nl.talsmasoftware.context.ContextManager;
import nl.talsmasoftware.context.ContextManagers;
import nl.talsmasoftware.context.executors.ContextAwareExecutorService;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -215,4 +216,15 @@ public void testDeprecatedClassStillWorks() {
newContext.close();
newContext.close();
}

@Test
public void testClearingAllContexts() {
Span span = mockTracer.buildSpan("test-span").start();
Scope scope = mockTracer.scopeManager().activate(span, false);
assertThat(new SpanManager().getActiveContext().getValue(), is(sameInstance(span)));

ContextManagers.clearActiveContexts();
// TODO Test after this is merged: https://github.com/opentracing/opentracing-java/pull/313
// assertThat(new SpanManager().getActiveContext(), is(nullValue()));
}
}

0 comments on commit 73ff552

Please sign in to comment.