示例#1
0
        public void testListeningCallable()
        {
            CloseableExecutorService service    = new CloseableExecutorService(executorService);
            CountdownEvent           startLatch = new CountdownEvent(QTY);
            List <IFuture <object> > futures    = new List <IFuture <object> >();

            for (int i = 0; i < QTY; ++i)
            {
                IFuture <object> future = submitJoinRunnable(service, startLatch);
                futures.Add(future);
            }

            Assert.True(startLatch.Wait(TimeSpan.FromSeconds(15)));
            foreach (IFuture <object> future in futures)
            {
                future.cancel();
            }
            Thread.Sleep(TimeSpan.FromSeconds(5));
            Assert.AreEqual(0, service.size());
        }
示例#2
0
        public void testPartialRunnable()
        {
            CountdownEvent outsideLatch = new CountdownEvent(1);

            executorService.submit
            (
                new FutureTask <object>(CallableUtils.FromFunc <object>(() =>
            {
                try
                {
                    Thread.CurrentThread.Join();
                }
                finally
                {
                    outsideLatch.Signal();
                }
                return(null);
            }))
            );

            CloseableExecutorService service    = new CloseableExecutorService(executorService);
            CountdownEvent           startLatch = new CountdownEvent(QTY);
            CountdownEvent           latch      = new CountdownEvent(QTY);

            for (int i = 0; i < QTY; ++i)
            {
                submitRunnable(service, startLatch, latch);
            }

            while (service.size() < QTY)
            {
                Thread.Sleep(100);
            }

            Assert.True(startLatch.Wait(TimeSpan.FromSeconds(15)));
            service.Dispose();
            Assert.True(latch.Wait(TimeSpan.FromSeconds(15)));
            Assert.AreEqual(1, outsideLatch.CurrentCount);
        }
        public void testListeningCallable()
        {
            CloseableExecutorService service = new CloseableExecutorService(executorService);
            CountdownEvent startLatch = new CountdownEvent(QTY);
            List<IFuture<object>> futures = new List<IFuture<object>>();
            for ( int i = 0; i<QTY; ++i )
            {
                IFuture<object> future = submitJoinRunnable(service, startLatch);
                futures.Add(future);
            }

            Assert.True(startLatch.Wait(TimeSpan.FromSeconds(15)));
            foreach ( IFuture<object> future in futures )
            {
                future.cancel();
            }
            Thread.Sleep(TimeSpan.FromSeconds(5));
            Assert.AreEqual(0, service.size());
        }
        public void testPartialRunnable()
        {
            CountdownEvent outsideLatch = new CountdownEvent(1);
            executorService.submit
            (
                new FutureTask<object>(CallableUtils.FromFunc<object>(() =>
                {
                    try
                    {
                        Thread.CurrentThread.Join();
                    }
                    finally
                    {
                        outsideLatch.Signal();
                    }
                    return null;
                }))
            );

            CloseableExecutorService service = new CloseableExecutorService(executorService);
            CountdownEvent startLatch = new CountdownEvent(QTY);
            CountdownEvent latch = new CountdownEvent(QTY);
            for ( int i = 0; i<QTY; ++i )
            {
                submitRunnable(service, startLatch, latch);
            }

            while ( service.size() < QTY )
            {
                Thread.Sleep(100);
            }

            Assert.True(startLatch.Wait(TimeSpan.FromSeconds(15)));
            service.Dispose();
            Assert.True(latch.Wait(TimeSpan.FromSeconds(15)));
            Assert.AreEqual(1, outsideLatch.CurrentCount);
        }