@Test
@Repeat(times = 10000, threads = 4)
public void withMDCExecutor() throws ExecutionException, InterruptedException {

  MDC.put("foo", "bar");
  final CompletableFuture<String> value1 = new CompletableFuture<>();
  final CompletableFuture<String> value2 = new CompletableFuture<>();
  CompletableFuture.runAsync(
      () -> value1.complete(MDC.get("foo")),
      withMDC(EXECUTOR_SERVICE))
      // Later stages should also have the MDC applied
      .thenRun(() -> value2.complete(MDC.get("foo")))
      .get();
  assertThat(value1.getNow(""), is("bar"));
  assertThat(value2.getNow(""), is("bar"));
  // MDC should not leak
  final Map<String, String> mdc = EXECUTOR_SERVICE
      .submit(MDC::getCopyOfContextMap)
      .get();
  assertThat(mdc, is(anyOf(nullValue(), is(emptyMap()))));
}