@Test public void testAllListInvokeable() throws InterruptedException { final AtomicInteger thenCalled = new AtomicInteger(); final List<Promise<String>> promiseList = new ArrayList<>(); for (int index = 0; index < 100; index++) { promiseList.add(invokeMe()); } final Promise<Void> promise = reactor.all(promiseList); promise.then(s -> { thenCalled.incrementAndGet(); }).catchError(Throwable::printStackTrace); assertFalse(promise.asHandler().complete()); reactor.process(); assertFalse(promise.asHandler().complete()); process(); promiseList.stream().forEach(Promise::invoke); for (int index = 0; index < 1000; index++) { Thread.sleep(50); if (promise.asHandler().complete()) break; } /** You can see the results but the events wont fire until reactor plays the replay promises. */ assertTrue(promise.asHandler().complete()); assertTrue(promise.asHandler().success()); Thread.sleep(50); /** Now we see the event. */ assertEquals(1, thenCalled.get()); }
@Test public void testAllList2() throws InterruptedException { final AtomicInteger thenCalled = new AtomicInteger(); final List<Promise<String>> promiseList = new ArrayList<>(); for (int index = 0; index < 100; index++) { promiseList.add(Promises.promiseString()); } final Promise<Void> promise = reactor.all(promiseList).catchError(Throwable::printStackTrace); promise.then(s -> thenCalled.incrementAndGet()); assertFalse(promise.asHandler().complete()); reactor.process(); assertFalse(promise.asHandler().complete()); process(); for (Promise<String> stringPromise : promiseList) { new Thread(() -> { stringPromise.asHandler().resolve("DONE"); }).start(); } for (int index = 0; index < 100; index++) { Thread.sleep(50); if (promise.asHandler().complete()) break; } /** You can see the results but the events wont fire until reactor plays the replay promises. */ assertTrue(promise.asHandler().complete()); assertTrue(promise.asHandler().success()); /** Now we see the event. */ assertEquals(1, thenCalled.get()); }
@Test public void testAll2() throws InterruptedException { final AtomicInteger thenCalled = new AtomicInteger(); final Promise<String> promise1 = Promises.promise(); final Promise<String> promise2 = Promises.promise(); final Promise<Void> promise = reactor.all(promise1, promise2).catchError(Throwable::printStackTrace); promise.then(s -> thenCalled.incrementAndGet()); assertFalse(promise.asHandler().complete()); reactor.process(); assertFalse(promise.asHandler().complete()); process(); new Thread(() -> { promise1.asHandler().resolve("DONE"); }).start(); new Thread(() -> { promise2.asHandler().resolve("DONE"); }).start(); for (int index = 0; index < 100; index++) { Thread.sleep(50); if (promise.asHandler().complete()) break; } /** You can see the results but the events wont fire until reactor plays the replay promises. */ assertTrue(promise.asHandler().complete()); assertTrue(promise.asHandler().success()); /** Now we see the event. */ assertEquals(1, thenCalled.get()); }
@Test public void testAllList() { AtomicBoolean thenCalled = new AtomicBoolean(); Promise<String> promise1 = reactor.promise(); Promise<String> promise2 = reactor.promise(); final Promise<Void> promise = reactor.all(Arrays.asList(promise1, promise2)); promise.then(s -> thenCalled.set(true)); assertFalse(promise.asHandler().complete()); reactor.process(); assertFalse(promise.asHandler().complete()); /** Invoke the callback. */ promise1.asHandler().resolve("DONE"); promise2.asHandler().resolve("DONE"); reactor.process(); //play it /** You can see the results but the events wont fire until reactor plays the replay promises. */ assertTrue(promise.asHandler().complete()); assertTrue(promise.asHandler().success()); /** Now we see the event. */ assertTrue(thenCalled.get()); }
@Test public void testAll() { AtomicInteger thenCalled = new AtomicInteger(); Promise<String> promise1 = reactor.promise(); Promise<String> promise2 = reactor.promise(); final Promise<Void> promise = reactor.all(promise1, promise2); promise.then(s -> thenCalled.incrementAndGet()); assertFalse(promise.asHandler().complete()); reactor.process(); assertFalse(promise.asHandler().complete()); /** Invoke the callback. */ promise1.asHandler().resolve("DONE"); promise2.asHandler().resolve("DONE"); reactor.process(); //play it /** You can see the results but the events wont fire until reactor plays the replay promises. */ assertTrue(promise.asHandler().complete()); assertTrue(promise.asHandler().success()); /** Now we see the event. */ assertEquals(1, thenCalled.get()); }