### Question:
ContainerRequestContextHolder implements ContainerRequestFilter, ContainerResponseFilter { public static Runnable transferRequestContext(Runnable runnable) { Map<String, String> contextMap = MDC.getCopyOfContextMap(); ContainerRequestContext requestContext = currentRequestContext().orElse(null); return new TracedRunnable( () -> { ContainerRequestContextHolder containerRequestContextHolder = new ContainerRequestContextHolder(); try { if (contextMap != null) { MDC.setContextMap(contextMap); } containerRequestContextHolder.filter(requestContext); runnable.run(); } finally { MDC.clear(); containerRequestContextHolder.filter(requestContext, null); } }, GlobalTracer.get()); }  @Override void filter(ContainerRequestContext requestContext); @Override void filter(
      ContainerRequestContext requestContext, ContainerResponseContext responseContext); static Runnable transferRequestContext(Runnable runnable); static Callable<V> transferRequestContext(Callable<V> callable);  }### Answer:
@Test public void shouldTransferRequestContextToThreadForRunnable() throws InterruptedException, ExecutionException { initializeContext(); ExecutorService executorService = Executors.newFixedThreadPool(1); executorService .submit( transferRequestContext( () -> { assertThat(MDC.get("Trace-Token")).isEqualTo("a-trace-token"); assertThat(new AuthHeaderClientFilter().getHeaderValue().orElse(null)) .isEqualTo("an-access-token"); })) .get(); executorService.shutdown(); }
@Test public void shouldTransferRequestContextToThreadForCallable() throws ExecutionException, InterruptedException { initializeContext(); ExecutorService executorService = Executors.newFixedThreadPool(1); int result = executorService .submit( transferRequestContext( () -> { assertThat(MDC.get("Trace-Token")).isEqualTo("a-trace-token"); assertThat(new AuthHeaderClientFilter().getHeaderValue().orElse(null)) .isEqualTo("an-access-token"); return 42; })) .get(); assertThat(result).isEqualTo(42); executorService.shutdown(); }
@Test public void shouldCleanupAfterTransferRequestContextToThreadForRunnable() throws InterruptedException, ExecutionException { initializeContext(); ExecutorService executorService = Executors.newFixedThreadPool(1); executorService.submit(transferRequestContext(() -> {})).get(); executorService .submit( () -> { assertThat(MDC.get("Trace-Token")).isNull(); assertThat(new AuthHeaderClientFilter().getHeaderValue().isPresent()).isFalse(); }) .get(); executorService.shutdown(); }
@Test public void shouldCleanupAfterTransferRequestContextToThreadForCallable() throws ExecutionException, InterruptedException { initializeContext(); ExecutorService executorService = Executors.newFixedThreadPool(1); executorService.submit(transferRequestContext(() -> {})).get(); executorService .submit( () -> { assertThat(MDC.get("Trace-Token")).isNull(); assertThat(new AuthHeaderClientFilter().getHeaderValue().isPresent()).isFalse(); return 42; }) .get(); executorService.shutdown(); }