@Test(timeout = 10000)
public void testIdGeneration() throws Exception {

  final ExecutorService service = Executors.newFixedThreadPool(THREAD_COUNT);
  final List<Callable<Integer>> tasks = new ArrayList<>();
  for (int i = 0; i < TASK_COUNT; i++) {
    tasks.add(() -> factory.apply(1).getId());
  }
  final List<Integer> ids = service.invokeAll(tasks)
      .stream()
      .map(TaskTest::get)
      .filter(Objects::nonNull)
      .collect(Collectors.toList());
  service.shutdownNow();
  final long uniqueIdCount = ids.stream()
      .distinct()
      .count();
  assertEquals(TASK_COUNT, ids.size());
  assertEquals(TASK_COUNT, uniqueIdCount);
}