예제 #1
0
        public void IsDoneIsTrueWhenTaskCompletes()
        {
            FutureTask <T> task = new FutureTask <T>(_noOpCall);

            task.Run();
            Assert.IsTrue(task.IsDone);
            Assert.IsFalse(task.IsCancelled);
        }
예제 #2
0
        public void CancelFailsOnCompletedTask([Values(true, false)] bool mayInterruptIfRunning)
        {
            FutureTask <T> task = new FutureTask <T>(_noOpCall);

            task.Run();
            Assert.IsFalse(task.Cancel(mayInterruptIfRunning));
            Assert.IsTrue(task.IsDone);
            Assert.IsFalse(task.IsCancelled);
        }
예제 #3
0
        public void CancelSecceedsBeforeRun([Values(true, false)] bool mayInterruptIfRunning)
        {
            FutureTask <T> task = new FutureTask <T>(_noOpCall);

            Assert.IsTrue(task.Cancel(mayInterruptIfRunning));
            task.Run();
            Assert.IsTrue(task.IsDone);
            Assert.IsTrue(task.IsCancelled);
        }
예제 #4
0
        public void TimedGetResultRetrievesValueSetFromAnotherThread()
        {
            T result          = TestData <T> .One;
            FutureTask <T> ft = new FutureTask <T>(() => result);

            Assert.IsFalse(ft.IsDone);
            Assert.IsFalse(ft.IsCancelled);
            ThreadManager.StartAndAssertRegistered(
                "T1",
                delegate
            {
                Assert.That(ft.GetResult(Delays.Medium), Is.EqualTo(result));
            });
            ft.Run();
            ThreadManager.JoinAndVerify();
            Assert.IsTrue(ft.IsDone);
            Assert.IsFalse(ft.IsCancelled);
        }
예제 #5
0
        public void GetChokesWhenTaskChokes([Values(true, false)] bool isTimed)
        {
            FutureTask <T> ft = new FutureTask <T>(
                delegate
            {
                int z = 0;
                return(TestData <T> .MakeData(5 / z));
            });

            ft.Run();
            Assert.Throws <ExecutionException>(
                delegate
            {
                if (isTimed)
                {
                    ft.GetResult(Delays.Medium);
                }
                else
                {
                    ft.GetResult();
                }
            });
        }