TraceTokenCopyingExecutor extends WrappingExecutorService { private TraceTokenCopyingExecutor(ExecutorService executor) { super(executor); } private  TraceTokenCopyingExecutor(ExecutorService executor); static ExecutorService traceTokenCopyingExecutor(ExecutorService executor);  }
@Test public void testCallableTraceTokenCopied() throws InterruptedException, ExecutionException { AtomicReference<TraceToken> actualToken = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); ExecutorService innerExecutor = newSingleThreadExecutor(); Object expectedReturn = new Object(); try { createAndRegisterNewRequestToken("somekey", "somevalue"); TraceToken token = getCurrentTraceToken(); Future<Object> future = traceTokenCopyingExecutor(innerExecutor).submit(() -> { actualToken.set(getCurrentTraceToken()); latch.countDown(); return expectedReturn; }); assertTrue(latch.await(10, SECONDS)); assertEquals(actualToken.get(), token); assertEquals(future.get(), expectedReturn); } finally { innerExecutor.shutdown(); } }
@Test public void testRunnableTraceTokenCopied() throws InterruptedException { AtomicReference<TraceToken> actualToken = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); ExecutorService innerExecutor = newSingleThreadExecutor(); try { createAndRegisterNewRequestToken("somekey", "somevalue"); TraceToken token = getCurrentTraceToken(); traceTokenCopyingExecutor(innerExecutor).execute(() -> { actualToken.set(getCurrentTraceToken()); latch.countDown(); }); assertTrue(latch.await(10, SECONDS)); assertEquals(actualToken.get(), token); } finally { innerExecutor.shutdown(); } }