/** * @throws Exception If failed. */ @Test public void testCompleteOnReducer() throws Exception { GridCompoundFuture<Boolean, Boolean> fut = new GridCompoundFuture<>(CU.boolReducer()); List<GridFutureAdapter<Boolean>> futs = new ArrayList<>(5); for (int i = 0; i < 5; i++) { GridFutureAdapter<Boolean> part = new GridFutureAdapter<>(); fut.add(part); futs.add(part); } fut.markInitialized(); assertFalse(fut.isDone()); assertFalse(fut.isCancelled()); for (int i = 0; i < 3; i++) { futs.get(i).onDone(true); assertFalse(fut.isDone()); } futs.get(3).onDone(false); assertTrue(fut.isDone()); }
/** * @throws Exception If failed. */ @Test public void testCompleteOnException() throws Exception { GridCompoundFuture<Boolean, Boolean> fut = new GridCompoundFuture<>(CU.boolReducer()); List<GridFutureAdapter<Boolean>> futs = new ArrayList<>(5); for (int i = 0; i < 5; i++) { GridFutureAdapter<Boolean> part = new GridFutureAdapter<>(); fut.add(part); futs.add(part); } fut.markInitialized(); assertFalse(fut.isDone()); assertFalse(fut.isCancelled()); for (int i = 0; i < 3; i++) { futs.get(i).onDone(true); assertFalse(fut.isDone()); } futs.get(3).onDone(new IgniteCheckedException("Test message")); assertTrue(fut.isDone()); }
/** * @throws Exception If failed. */ @Test public void testConcurrentCompletion() throws Exception { GridCompoundFuture<Boolean, Boolean> fut = new GridCompoundFuture<>(CU.boolReducer()); final ConcurrentLinkedDeque<GridFutureAdapter<Boolean>> futs = new ConcurrentLinkedDeque<>(); for (int i = 0; i < 1000; i++) { GridFutureAdapter<Boolean> part = new GridFutureAdapter<>(); fut.add(part); futs.add(part); } fut.markInitialized(); IgniteInternalFuture<?> complete = multithreadedAsync(new Runnable() { @Override public void run() { GridFutureAdapter<Boolean> part; while ((part = futs.poll()) != null) part.onDone(true); } }, 20); complete.get(); assertTrue(fut.isDone()); }
/** * @throws Exception If failed. */ @Test public void testMarkInitialized() throws Exception { GridCompoundFuture<Boolean, Boolean> fut = new GridCompoundFuture<>(); for (int i = 0; i < 5; i++) { IgniteInternalFuture<Boolean> part = new GridFinishedFuture<>(true); fut.add(part); } assertFalse(fut.isDone()); assertFalse(fut.isCancelled()); fut.markInitialized(); assertTrue(fut.isDone()); }
assertTrue(fut.isDone());