コード例 #1
0
        public void PropagatesExceptions()
        {
            AFnImpl fn = new AFnImpl();

            fn._fn0 = () => { throw new Exception("future exception"); };

            Future f = new Future(fn);

            try
            {
                f.deref();
                Assert.Fail("expected future exception");
            }
            catch (Exception ex)
            {
                Expect(ex.Message, EqualTo("Future has an error"));
                Expect(ex.InnerException, Is.Not.Null);
                Expect(ex.InnerException.Message, EqualTo("future exception"));
            }

            // Same result for subsequent derefs.
            try
            {
                f.deref();
                Assert.Fail("expected future exception");
            }
            catch (Exception ex)
            {
                Expect(ex.Message, EqualTo("Future has an error"));
                Expect(ex.InnerException, Is.Not.Null);
                Expect(ex.InnerException.Message, EqualTo("future exception"));
            }
        }
コード例 #2
0
        public static IFn CreateForReduce()
        {
            AFnImpl fn = new AFnImpl();

            fn._fn2 = (object x, object y) => { return(Numbers.addP(x, y)); };
            return(fn);
        }
コード例 #3
0
        public static IFn CreateForReduce()
        {
            AFnImpl fn = new AFnImpl();

            fn._fn2 = (object x, object y) => { return(((int)x) + ((int)y)); };
            return(fn);
        }
コード例 #4
0
        internal static IFn CreateForMetaAlter(IPersistentMap meta)
        {
            AFnImpl fn = new AFnImpl();

            fn._fn0 = () => { return(meta); };
            fn._fn1 = (object x) => { return(meta); };
            return(fn);
        }
コード例 #5
0
        public void SecondCancelReturnsFalse()
        {
            AFnImpl fn = new AFnImpl();
            fn._fn0 = () => { while (true); };

            Future f = new Future(fn);
            Expect(f.cancel(true)).To.Equal(true));
            Expect(f.cancel(true)).To.Equal(false));
        }
コード例 #6
0
        public void DerefThrowsAfterCancellation()
        {
            AFnImpl fn = new AFnImpl();
            fn._fn0 = () => { while (true); };

            Future f = new Future(fn);
            f.cancel(true);
            f.deref();
        }
コード例 #7
0
        public void CancelAbortsTheTask()
        {
            AFnImpl fn = new AFnImpl();
            fn._fn0 = () => { while (true); };

            Future f = new Future(fn);
            Expect(f.isCancelled()).To.Equal(false));
            Expect(f.cancel(true)).To.Equal(true));
            Expect(f.isCancelled()).To.Equal(true));
        }
コード例 #8
0
        public void CancelFailsAfterSuccessfulCompletion()
        {
            AFnImpl fn = new AFnImpl();
            fn._fn0 = () => { return 42; };

            Future f = new Future(fn);
            Expect(f.deref()).To.Equal(42);
            Expect(f.cancel(true)).To.Equal(false);
            Expect(f.isCancelled()).To.Equal(false);
        }
コード例 #9
0
        public void CachesResultForSubsequentCalls()
        {
            int i = 0;
            AFnImpl fn = new AFnImpl();
            fn._fn0 = () => Interlocked.Increment(ref i);

            Future f = new Future(fn);
            Expect(f.deref()).To.Equal(1);
            Expect(f.deref()).To.Equal(1);
            Expect(i).To.Equal(1);
        }
コード例 #10
0
        public void ComputesTheValueOnAnotherThread()
        {
            int workerID = Thread.CurrentThread.ManagedThreadId;
            AFnImpl fn = new AFnImpl();
            fn._fn0 = () =>
                {
                    workerID = Thread.CurrentThread.ManagedThreadId;
                    return 42;
                };

            Future f = new Future(fn);
            Expect(f.deref()).To.Equal(42);
            Expect(workerID).To.Not.Equal(Thread.CurrentThread.ManagedThreadId);
        }