TracedExecutorService implements ExecutorService { @Override public <T> Future<T> submit(Callable<T> task) { return delegate.submit(new SofaTracerCallable<T>(task, traceContext)); } TracedExecutorService(ExecutorService delegate);  TracedExecutorService(ExecutorService delegate, SofaTraceContext traceContext); @Override void shutdown(); @Override List<Runnable> shutdownNow(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override Future<T> submit(Callable<T> task); @Override Future<T> submit(Runnable task, T result); @Override Future<?> submit(Runnable task); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout,
                                         TimeUnit unit); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit); @Override void execute(final java.lang.Runnable command);  }
@Test public void testSubmitCallableOfT() { Callable<Span> wrappedCallable = mock(Callable.class); tracedExecutorService.submit(wrappedCallable); verify(traceContext, times(1)).isEmpty(); verify(traceContext, times(1)).getCurrentSpan(); verify(wrappedExecutorService, times(1)).submit(any(Callable.class)); verifyNoMoreInteractions(wrappedExecutorService, wrappedCallable, traceContext); }
@Test public void testSubmitRunnable() { Runnable wrappedRunnable = mock(Runnable.class); tracedExecutorService.submit(wrappedRunnable); verify(traceContext, times(1)).isEmpty(); verify(traceContext, times(1)).getCurrentSpan(); verify(wrappedExecutorService).submit(any(Runnable.class)); verifyNoMoreInteractions(wrappedExecutorService, wrappedRunnable, traceContext); }