Beispiel #1
0
        public void ActorOperationsInOrder()
        {
            var actor = new ActorB();
            var tasks = new List <Task>(100000);

            for (var j = 0; j < 100000; j++)
            {
                tasks.Add(actor.Add(1));
                tasks.Add(actor.Verify(j));
            }
            Task.WaitAll(tasks.ToArray());
            var t = actor.GetCounter();

            t.Wait(5000);
            Assert.AreEqual(100000, t.Result);
        }
Beispiel #2
0
        public void ActorOperationsInOrderFast()
        {
            var actor = new ActorB();

            for (var j = 0; j < 100000; j++)
            {
                actor.AddFast(1);
                actor.VerifyFast(j);
            }

            var counter = actor.GetCounter();

            actor.Complete();
            var completionTask = actor.Completion;

            completionTask.Wait(5000);
            Assert.AreEqual(100000, counter.Result);
            AssertException(typeof(InvalidOperationException), null, () => actor.AddFast(1));
        }
Beispiel #3
0
        public void CancellationTest()
        {
            var cancelationToken = new CancellationTokenSource();
            var actor            = new ActorB(cancelationToken.Token);
            var tasks            = new List <Task>(100000);

            for (var j = 0; j < 100000; j++)
            {
                tasks.Add(actor.Add(1));
                tasks.Add(actor.Verify(j));
            }
            cancelationToken.Cancel();
            AssertException(typeof(AggregateException), typeof(InvalidOperationException), () => actor.GetCounter());
            AssertException(typeof(AggregateException), typeof(TaskCanceledException), () => Task.WaitAll(tasks.ToArray()));
        }