### Question:
EthScheduler { public <T> CompletableFuture<T> timeout(final EthTask<T> task) { return timeout(task, defaultTimeout); } 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 timeout_resultCompletesWhenScheduledTaskCompletes() { final MockEthTask task = new MockEthTask(); final CompletableFuture<Object> result = ethScheduler.timeout(task, Duration.ofSeconds(2)); assertThat(task.hasBeenStarted()).isTrue(); assertThat(task.isDone()).isFalse(); assertThat(result.isDone()).isFalse(); task.complete(); assertThat(result.isDone()).isTrue(); assertThat(result.isCompletedExceptionally()).isFalse(); assertThat(result.isCancelled()).isFalse(); }
@Test public void timeout_resultCompletesWhenScheduledTaskFails() { final MockEthTask task = new MockEthTask(); final CompletableFuture<Object> result = ethScheduler.timeout(task, Duration.ofSeconds(2)); assertThat(task.hasBeenStarted()).isTrue(); assertThat(task.isDone()).isFalse(); assertThat(result.isDone()).isFalse(); task.fail(); assertThat(result.isDone()).isTrue(); assertThat(result.isCompletedExceptionally()).isTrue(); assertThat(result.isCancelled()).isFalse(); }
@Test public void timeout_resultCompletesOnTimeout() { shouldTimeout.set(true); final MockEthTask task = new MockEthTask(); final CompletableFuture<Object> result = ethScheduler.timeout(task, Duration.ofSeconds(2)); assertThat(task.hasBeenStarted()).isTrue(); assertThat(task.isDone()).isTrue(); assertThat(result.isDone()).isTrue(); assertThat(result.isCompletedExceptionally()).isTrue(); assertThatThrownBy(result::get).hasCauseInstanceOf(TimeoutException.class); assertThat(result.isCancelled()).isFalse(); }
@Test public void timeout_cancelsTaskWhenResultIsCancelled() { final MockEthTask task = new MockEthTask(); final CompletableFuture<Object> result = ethScheduler.timeout(task, Duration.ofSeconds(2)); assertThat(task.hasBeenStarted()).isTrue(); assertThat(task.isDone()).isFalse(); assertThat(result.isDone()).isFalse(); result.cancel(false); assertThat(task.isDone()).isTrue(); assertThat(task.isFailed()).isTrue(); assertThat(task.isCancelled()).isTrue(); }