GlobalTracer implements Tracer { @Deprecated public static void register(final Tracer tracer) { if (!registerIfAbsent(provide(tracer)) && !tracer.equals(GlobalTracer.tracer) && !(tracer instanceof GlobalTracer)) { throw new IllegalStateException("There is already a current global Tracer registered."); } } private  GlobalTracer(); static Tracer get(); static boolean isRegistered(); static synchronized boolean registerIfAbsent(final Callable<Tracer> provider); static synchronized boolean registerIfAbsent(final Tracer tracer); @Deprecated static void register(final Tracer tracer); @Override ScopeManager scopeManager(); @Override SpanBuilder buildSpan(String operationName); @Override void inject(SpanContext spanContext, Format<C> format, C carrier); @Override SpanContext extract(Format<C> format, C carrier); @Override Span activeSpan(); @Override Scope activateSpan(Span span); @Override void close(); @Override String toString();  }
@Test public void testMultipleRegistrations() { GlobalTracer.register(mock(Tracer.class)); try { GlobalTracer.register(mock(Tracer.class)); fail("Duplicate registration exception expected."); } catch (RuntimeException expected) { assertThat("Duplicate registration message", expected.getMessage(), is(notNullValue())); } }
@Test public void testMultipleRegistrations_sameTracer() { Tracer mockTracer = mock(Tracer.class); GlobalTracer.register(mockTracer); GlobalTracer.register(mockTracer); }
@Test(expected = NullPointerException.class) public void testRegisterNull() { GlobalTracer.register(null); }
@Test(expected = NullPointerException.class) public void testRegisterIfAbsentNullSupplier() { this.globalTracerWrapper.register(null); }
@Test(expected = NullPointerException.class) public void testRegisterIfAbsentNullTracer() { this.globalTracerWrapper.register(null); }
@Test public void testRegisterIfAbsent_multipleTracers() { assertThat(this.globalTracerWrapper.register(mock(Tracer.class)), is(true)); assertThat(this.globalTracerWrapper.register((mock(Tracer.class))), is(false)); assertThat(this.globalTracerWrapper.register((mock(Tracer.class))), is(false)); }
@Test public void testRegisterIfAbsent_multiple_sameTracer() { final Tracer mockTracer = mock(Tracer.class); assertThat(this.globalTracerWrapper.register(mockTracer), is(true)); assertThat(this.globalTracerWrapper.register(mockTracer), is(false)); }