### Question:
Task { public int getId() { return id; } Task(final int timeMs); int getId(); int getTimeMs(); @Override String toString();  }### Answer:
@Test public void testIdGeneration() throws Exception { assertTimeout(ofMillis(10000), () -> { final var service = Executors.newFixedThreadPool(THREAD_COUNT); final var tasks = IntStream.range(0, TASK_COUNT) .<Callable<Integer>>mapToObj(i -> () -> factory.apply(1).getId()) .collect(Collectors.toCollection(ArrayList::new)); final var ids = service.invokeAll(tasks) .stream() .map(TaskTest::get) .filter(Objects::nonNull) .collect(Collectors.toList()); service.shutdownNow(); final var uniqueIdCount = ids.stream() .distinct() .count(); assertEquals(TASK_COUNT, ids.size()); assertEquals(TASK_COUNT, uniqueIdCount); }); }
@Test public void testIdGeneration() throws Exception { assertTimeout(ofMillis(10000), () -> { 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); }); }