@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); }); }
public int getId() { return id; }
Task { public int getId() { return id; } }
Task { public int getId() { return id; } Task(final int timeMs); }
Task { public int getId() { return id; } Task(final int timeMs); int getId(); int getTimeMs(); @Override String toString(); }
Task { public int getId() { return id; } Task(final int timeMs); int getId(); int getTimeMs(); @Override String toString();  }