### Question:
EthScheduler { public <T> CompletableFuture<T> scheduleSyncWorkerTask( final Supplier<CompletableFuture<T>> future) { final CompletableFuture<T> promise = new CompletableFuture<>(); final Future<?> workerFuture = syncWorkerExecutor.submit(() -> propagateResult(future, promise)); promise.whenComplete( (r, t) -> { if (t instanceof CancellationException) { workerFuture.cancel(false); } }); return promise; } EthScheduler(
      final int syncWorkerCount,
      final int txWorkerCount,
      final int computationWorkerCount,
      final MetricsSystem metricsSystem);  EthScheduler(
      final int syncWorkerCount,
      final int txWorkerCount,
      final int txWorkerQueueSize,
      final int computationWorkerCount,
      final MetricsSystem metricsSystem); protected  EthScheduler(
      final ExecutorService syncWorkerExecutor,
      final ScheduledExecutorService scheduler,
      final ExecutorService txWorkerExecutor,
      final ExecutorService servicesExecutor,
      final ExecutorService computationExecutor); CompletableFuture<T> scheduleSyncWorkerTask(
      final Supplier<CompletableFuture<T>> future); void scheduleSyncWorkerTask(final Runnable command); CompletableFuture<T> scheduleSyncWorkerTask(final EthTask<T> task); void scheduleTxWorkerTask(final Runnable command); CompletableFuture<T> scheduleServiceTask(final EthTask<T> task); CompletableFuture<Void> startPipeline(final Pipeline<?> pipeline); CompletableFuture<T> scheduleComputationTask(final Supplier<T> computation); CompletableFuture<Void> scheduleFutureTask(
      final Runnable command, final Duration duration); ScheduledFuture<?> scheduleFutureTaskWithFixedDelay(
      final Runnable command, final Duration initialDelay, final Duration duration); CompletableFuture<T> scheduleFutureTask(
      final Supplier<CompletableFuture<T>> future, final Duration duration); CompletableFuture<T> timeout(final EthTask<T> task); CompletableFuture<T> timeout(final EthTask<T> task, final Duration timeout); void stop(); void awaitStop(); void failAfterTimeout(final CompletableFuture<T> promise, final Duration timeout);  }### Answer:
@Test public void scheduleWorkerTask_completesWhenScheduledTaskCompletes() { final CompletableFuture<Object> future = new CompletableFuture<>(); final CompletableFuture<Object> result = ethScheduler.scheduleSyncWorkerTask(() -> future); assertThat(result.isDone()).isFalse(); future.complete("bla"); assertThat(result.isDone()).isTrue(); assertThat(result.isCompletedExceptionally()).isFalse(); assertThat(result.isCancelled()).isFalse(); }
@Test public void scheduleWorkerTask_completesWhenScheduledTaskFails() { final CompletableFuture<Object> future = new CompletableFuture<>(); final CompletableFuture<Object> result = ethScheduler.scheduleSyncWorkerTask(() -> future); assertThat(result.isDone()).isFalse(); future.completeExceptionally(new RuntimeException("whoops")); assertThat(result.isDone()).isTrue(); assertThat(result.isCompletedExceptionally()).isTrue(); assertThat(result.isCancelled()).isFalse(); }
@Test public void scheduleWorkerTask_completesWhenScheduledTaskIsCancelled() { final CompletableFuture<Object> future = new CompletableFuture<>(); final CompletableFuture<Object> result = ethScheduler.scheduleSyncWorkerTask(() -> future); assertThat(result.isDone()).isFalse(); future.cancel(false); assertThat(result.isDone()).isTrue(); assertThat(result.isCompletedExceptionally()).isTrue(); assertThat(result.isCancelled()).isTrue(); }
@Test public void scheduleWorkerTask_cancelsScheduledFutureWhenResultIsCancelled() { final CompletableFuture<Object> result = ethScheduler.scheduleSyncWorkerTask(() -> new CompletableFuture<>()); assertThat(syncWorkerExecutor.getFutures().size()).isEqualTo(1); final Future<?> future = syncWorkerExecutor.getFutures().get(0); verify(future, times(0)).cancel(anyBoolean()); result.cancel(true); verify(future, times(1)).cancel(eq(false)); }