public void testParallelWait() throws InterruptedException { final ExecutorAllCompletionService service = createService(2); for (int i = 0; i < 300; ++i) { service.submit(new WaitRunnable(10), null); } List<Thread> threads = new ArrayList<>(10); for (int i = 0; i < 10; ++i) { Thread t = new Thread(() -> { service.waitUntilAllCompleted(); assertTrue(service.isAllCompleted()); assertFalse(service.isExceptionThrown()); }); threads.add(t); t.start(); } for (Thread t : threads) { t.join(); } assertTrue(service.isAllCompleted()); assertFalse(service.isExceptionThrown()); }
public void testParallelException() throws InterruptedException { final ExecutorAllCompletionService service = createService(2); for (int i = 0; i < 150; ++i) { service.submit(new WaitRunnable(10), null); } service.submit(new ExceptionRunnable("foobar"), null); for (int i = 0; i < 150; ++i) { service.submit(new WaitRunnable(10), null); } List<Thread> threads = new ArrayList<>(10); for (int i = 0; i < 10; ++i) { Thread t = new Thread(() -> { service.waitUntilAllCompleted(); assertTrue(service.isAllCompleted()); assertTrue(service.isExceptionThrown()); }); threads.add(t); t.start(); } for (Thread t : threads) { t.join(); } assertTrue(service.isAllCompleted()); assertTrue(service.isExceptionThrown()); }
public void testWaitForAll() { ExecutorAllCompletionService service = createService(1); long before = System.currentTimeMillis(); service.submit(new WaitRunnable(500), null); service.submit(new WaitRunnable(500), null); service.waitUntilAllCompleted(); long after = System.currentTimeMillis(); assertTrue(after - before >= 1000); assertTrue(service.isAllCompleted()); assertFalse(service.isExceptionThrown()); }
public void testExceptions() { ExecutorAllCompletionService service = createService(1); service.submit(new WaitRunnable(1), null); service.submit(new ExceptionRunnable("second"), null); service.submit(new WaitRunnable(1), null); service.submit(new ExceptionRunnable("third"), null); service.waitUntilAllCompleted(); assertTrue(service.isAllCompleted()); assertTrue(service.isExceptionThrown()); assertEquals("second", findCause(service.getFirstException()).getMessage()); }