source: class SameExecutorCompletionStageTest {
  
      private static final CallCountingExecutor executorA;
      private static final CallCountingExecutor executorB;
      private CountDownLatch latch1;
      private CountDownLatch latch2;
      private CountDownLatch latch3;
  
      @Test
      public void testRunAfterEither() throws InterruptedException {
  
target:         CompletionStage<Void> firstCompletionStage = Async.supplyAsync(latchSupplier(latch1), executorA);
          latch1.countDown();
          firstCompletionStage.toCompletableFuture().join();
          assertHits(executorA, 1);
          
          CompletionStage<Void> secondCompletionStage = firstCompletionStage.runAfterEither(neverCompleteFuture(), noopRunnable());
          secondCompletionStage.toCompletableFuture().join();
          assertHits(executorA, 1);
          
          CompletionStage<Void> thirdCompletionStage = secondCompletionStage.runAfterEitherAsync(neverCompleteFuture(), latchRunnable(latch2));
          latch2.countDown();
          thirdCompletionStage.toCompletableFuture().join();
          assertHits(executorA, 2);
          
          CompletionStage<Void> fourthCompletionStage = thirdCompletionStage.runAfterEitherAsync(neverCompleteFuture(), latchRunnable(latch3), executorB);
          latch3.countDown();
          fourthCompletionStage.toCompletableFuture().join();
          assertHits(executorA, 2);
          assertHits(executorB, 1);
      }
  
  }