Ejemplo n.º 1
0
        public virtual void test_combineFuturesAsList_exception()
        {
            CompletableFuture <string> future1 = new CompletableFuture <string>();

            future1.complete("A");
            System.Threading.CountdownEvent latch   = new System.Threading.CountdownEvent(1);
            CompletableFuture <string>      future2 = CompletableFuture.supplyAsync(() =>
            {
                try
                {
                    latch.await();
                }
                catch (InterruptedException)
                {
                }
                throw new System.InvalidOperationException("Oops");
            });
            IList <CompletableFuture <string> > input = ImmutableList.of(future1, future2);

            CompletableFuture <IList <string> > test = Guavate.combineFuturesAsList(input);

            assertEquals(test.Done, false);
            latch.Signal();
            assertThrows(typeof(CompletionException), () => test.join());
            assertEquals(test.Done, true);
            assertEquals(test.CompletedExceptionally, true);
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void test_combineFuturesAsList()
        {
            CompletableFuture <string> future1 = new CompletableFuture <string>();

            future1.complete("A");
            System.Threading.CountdownEvent latch   = new System.Threading.CountdownEvent(1);
            CompletableFuture <string>      future2 = CompletableFuture.supplyAsync(() =>
            {
                try
                {
                    latch.await();
                }
                catch (InterruptedException)
                {
                }
                return("B");
            });
            IList <CompletableFuture <string> > input = ImmutableList.of(future1, future2);

            CompletableFuture <IList <string> > test = Guavate.combineFuturesAsList(input);

            assertEquals(test.Done, false);
            latch.Signal();
            IList <string> combined = test.join();

            assertEquals(test.Done, true);
            assertEquals(combined.Count, 2);
            assertEquals(combined[0], "A");
            assertEquals(combined[1], "B");
        }