예제 #1
0
        public void ReserveFaultConsumeBroadcast()
        {
            var scheduler = new TestScheduler();
            var source    = new BroadcastBlock <int> (null,
                                                      new DataflowBlockOptions {
                TaskScheduler = scheduler
            });
            var target = new TestTargetBlock <int> {
                Postpone = true
            };

            Assert.IsNotNull(source.LinkTo(target));

            Assert.IsTrue(source.Post(42));
            scheduler.ExecuteAll();
            Assert.IsTrue(target.HasPostponed);

            Assert.IsTrue(target.ReservePostponed());

            ((IDataflowBlock)source).Fault(new Exception());

            scheduler.ExecuteAll();
            Thread.Sleep(100);

            int value;

            Assert.IsTrue(target.RetryPostponed(out value));
        }
예제 #2
0
        public void ReserveChangedTest()
        {
            var scheduler = new TestScheduler();
            var broadcast = new BroadcastBlock <int> (null,
                                                      new DataflowBlockOptions {
                TaskScheduler = scheduler
            });
            var target = new TestTargetBlock <int> {
                Postpone = true
            };

            broadcast.LinkTo(target);

            Assert.IsFalse(target.HasPostponed);

            Assert.IsTrue(broadcast.Post(1));

            scheduler.ExecuteAll();

            Assert.IsTrue(target.HasPostponed);

            Assert.IsTrue(broadcast.Post(2));

            scheduler.ExecuteAll();

            Assert.IsTrue(target.ReservePostponed());

            int value;

            Assert.IsTrue(target.RetryPostponed(out value));
            Assert.AreEqual(2, value);
        }
예제 #3
0
        public void ReserveTest()
        {
            var scheduler = new TestScheduler();
            var source    =
                new BufferBlock <int> (new DataflowBlockOptions {
                TaskScheduler = scheduler
            });
            var target = new TestTargetBlock <int> {
                Postpone = true
            };

            Assert.IsNotNull(source.LinkTo(target));
            Assert.IsFalse(target.HasPostponed);

            Assert.IsTrue(source.Post(42));
            Assert.IsTrue(source.Post(43));
            scheduler.ExecuteAll();
            Assert.IsTrue(target.HasPostponed);

            Assert.IsTrue(target.ReservePostponed());
            int i;

            Assert.IsFalse(source.TryReceive(null, out i));
            Assert.AreEqual(default(int), i);
            IList <int> items;

            Assert.IsFalse(source.TryReceiveAll(out items));
            Assert.AreEqual(default(IList <int>), items);

            Assert.IsTrue(target.RetryPostponed(out i));
            Assert.AreEqual(42, i);

            Assert.IsTrue(source.TryReceive(null, out i));
            Assert.AreEqual(43, i);
        }