Ejemplo n.º 1
0
        public void TestFutureCleanupBefore()
        {
            object monitor = new object();

            for (int i = 0; i < NUM_ITERATIONS; ++i)
            {
                bool cleaned    = false;
                int  cleanupSum = 0;

                Action <List <int> > cleanup = intList => {
                    lock (monitor) {
                        cleaned     = true;
                        cleanupSum += intList[0];
                        Monitor.PulseAll(monitor);
                    }
                };

                // Close f before the computation finishes

                var f = new MyFuture(FunctionSuccess, cleanup);
                f.Close();

                lock (monitor) {
                    while (!cleaned)
                    {
                        Assert.IsTrue(Monitor.Wait(monitor, SLEEP_TIME * 3), "Future not cleaning");
                    }
                }

                Assert.IsTrue(f.IsDone);
                Assert.AreEqual(3, cleanupSum);
            }
        }
Ejemplo n.º 2
0
        public void TestFutureDisposalException()
        {
            var f = new MyFuture(FunctionSuccess);

            f.Close();
            Assert.Throws <ObjectDisposedException>(() => {
                f.TryGetResult(out _);
            });
        }
Ejemplo n.º 3
0
        public void TestFutureCleanupAfter()
        {
            for (int i = 0; i < NUM_ITERATIONS; ++i)
            {
                int cleanupSum = 0;

                // Close f after the computation finishes

                Action <List <int> > cleanup = intList => {
                    cleanupSum += intList[0];
                };

                var f = new MyFuture(FunctionSuccess, cleanup);
                Force(f);
                Assert.IsTrue(f.IsDone);

                f.Close();
                Assert.AreEqual(3, cleanupSum);
            }
        }
Ejemplo n.º 4
0
        public void TestFutureFailure()
        {
            var f = new MyFuture(FunctionFailure);

            Assert.Throws <FutureFailed>(() => Force(f));
        }
Ejemplo n.º 5
0
        public void TestFutureSuccess()
        {
            var f = new MyFuture(FunctionSuccess);

            Assert.AreEqual(Force(f)[0], 3);
        }