@Test
public void testPushCurrentBatchRunnable() throws Exception {

  long DELAY_TIME = 50L;
  BatchingSettings settings =
      batchingSettings.toBuilder().setDelayThreshold(Duration.ofMillis(DELAY_TIME)).build();
  BatcherImpl<Integer, Integer, LabeledIntList, List<Integer>> batcher =
      new BatcherImpl<>(
          SQUARER_BATCHING_DESC_V2, callLabeledIntSquarer, labeledIntList, settings, EXECUTOR);
  BatcherImpl.PushCurrentBatchRunnable<Integer, Integer, LabeledIntList, List<Integer>>
      pushBatchRunnable = new BatcherImpl.PushCurrentBatchRunnable<>(batcher);
  ScheduledFuture<?> onGoingRunnable =
      EXECUTOR.scheduleWithFixedDelay(
          pushBatchRunnable, DELAY_TIME, DELAY_TIME, TimeUnit.MILLISECONDS);
  pushBatchRunnable.setScheduledFuture(onGoingRunnable);
  boolean isExecutorCancelled = pushBatchRunnable.isCancelled();
  // ScheduledFuture should be not isCancelled yet.
  assertThat(isExecutorCancelled).isFalse();
  // Batcher present inside runnable should be GCed after following loop.
  batcher.close();
  batcher = null;
  for (int retry = 0; retry < 3; retry++) {
    System.gc();
    System.runFinalization();
    isExecutorCancelled = pushBatchRunnable.isCancelled();
    if (isExecutorCancelled) {
      break;
    }
    Thread.sleep(DELAY_TIME * (1L << retry));
  }
  // ScheduledFuture should be isCancelled now.
  assertThat(pushBatchRunnable.isCancelled()).isTrue();
}