@Override
  public void startScheduling() {
    for (ChainingCallback chainingCallback : chainingCallbacks) {
      ListenableScheduledFuture<CeWorker.Result> future = executorService.schedule(chainingCallback.worker, delayBetweenEnabledTasks, timeUnit);
      addCallback(future, chainingCallback, MoreExecutors.directExecutor());
    }
  }
@Test
  public void when_workerCount_is_more_than_1_as_many_CeWorkerCallable_are_scheduled() throws Exception {
    int workerCount = Math.abs(new Random().nextInt(10)) + 1;
    ceConfiguration.setWorkerThreadCount(workerCount);

    CeWorker[] workers = new CeWorker[workerCount];
    for (int i = 0; i < workerCount; i++) {
      workers[i] = mock(CeWorker.class);
      when(workers[i].call())
        .thenReturn(NO_TASK)
        .thenThrow(ERROR_TO_INTERRUPT_CHAINING);
    }

    ListenableScheduledFuture listenableScheduledFuture = mock(ListenableScheduledFuture.class);
    CeProcessingSchedulerExecutorService processingExecutorService = mock(CeProcessingSchedulerExecutorService.class);
    when(processingExecutorService.schedule(any(CeWorker.class), any(Long.class), any(TimeUnit.class))).thenReturn(listenableScheduledFuture);

    CeWorkerFactory ceWorkerFactory = spy(new TestCeWorkerFactory(workers));
    CeProcessingSchedulerImpl underTest = new CeProcessingSchedulerImpl(ceConfiguration, processingExecutorService, ceWorkerFactory, ceWorkerController);
    when(processingExecutorService.schedule(ceWorker, ceConfiguration.getQueuePollingDelay(), MILLISECONDS))
      .thenReturn(listenableScheduledFuture);

    underTest.startScheduling();
    // No exception from TestCeWorkerFactory must be thrown

    // Verify that schedule has been called on all workers
    for (int i = 0; i < workerCount; i++) {
      verify(processingExecutorService).schedule(workers[i], ceConfiguration.getQueuePollingDelay(), MILLISECONDS);
    }
    verify(listenableScheduledFuture, times(workerCount)).addListener(any(Runnable.class), eq(MoreExecutors.directExecutor()));
    for (int i = 0; i < workerCount; i++) {
      verify(ceWorkerFactory).create(i);
    }
  }