@Test public void testJobTermination() { ScheduledFuture<?> future = Mockito.mock(ScheduledFuture.class); when(scheduledExecutor.schedule(isA(Runnable.class), anyLong(), any())).then((invoc) -> { ((Runnable) invoc.getArgument(0)).run(); return future; }); Duration startDelay = Duration.ofMillis(10); Duration interBatchDelay = Duration.ofMillis(5); AtomicLong counter = new AtomicLong(0); batchExecutor.startJob((batchSize) -> { assertThat(batchSize).isEqualTo(42); if (counter.incrementAndGet() == 3) { return true; } else { return false; } }, 42, startDelay, interBatchDelay); verify(scheduledExecutor, times(1)).schedule(isA(Runnable.class), eq(startDelay.toNanos()), eq(TimeUnit.NANOSECONDS)); verify(scheduledExecutor, times(2)).schedule(isA(Runnable.class), eq(interBatchDelay.toNanos()), eq(TimeUnit.NANOSECONDS)); }
public <T> BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay) { BatchJob<T> job = new BatchJob<>(task, batchSizes, interBatchDelay); job.scheduleNextBatch(startDelay); return job; }
BatchJobExecutorService { public <T> BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay) { BatchJob<T> job = new BatchJob<>(task, batchSizes, interBatchDelay); job.scheduleNextBatch(startDelay); return job; } }
BatchJobExecutorService { public <T> BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay) { BatchJob<T> job = new BatchJob<>(task, batchSizes, interBatchDelay); job.scheduleNextBatch(startDelay); return job; }  }
BatchJobExecutorService { public <T> BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay) { BatchJob<T> job = new BatchJob<>(task, batchSizes, interBatchDelay); job.scheduleNextBatch(startDelay); return job; }  BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay); BatchJob<T> startJob(Consumer<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay); }
BatchJobExecutorService { public <T> BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay) { BatchJob<T> job = new BatchJob<>(task, batchSizes, interBatchDelay); job.scheduleNextBatch(startDelay); return job; }  BatchJob<T> startJob(BatchProcessor<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay); BatchJob<T> startJob(Consumer<T> task, T batchSizes, Duration startDelay, Duration interBatchDelay);  }