Inheritance: Microsoft.Ccr.Core.Arbiters.ReceiverTask
        public void CleanupTask()
        {
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            ITask task = new Task<int, string> ((i, s) => { });
            var mr = new MultipleItemReceiver (task, pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;

            mr.Execute ();
            ((Port<int>)pa).Post (10);
            Assert.AreEqual (0, pa.ItemCount, "#1");
            mr.Cleanup (task);

            Assert.AreEqual (1, pa.ItemCount, "#2");
            Assert.AreEqual (0, pb.ItemCount, "#3");
        }
Exemple #2
0
 public MultipleItemHelperReceiver(IPortReceive port, MultipleItemReceiver parent) : base(false, port, null)
 {
     _parent = parent;
 }
        public void ConstructorSideEffects()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            var mr = new MultipleItemReceiver (Arbiter.FromHandler (() => { ++cnt; }), pa, pb);

            Assert.AreEqual (0, pa.GetReceivers ().Length, "#1");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#2");
            Assert.AreEqual (0, cnt, "#3");
        }
        public void ExecutePersistent()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            var mr = new MultipleItemReceiver (Arbiter.FromHandler (() => { ++cnt; }), pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;
            mr.State = ReceiverTaskState.Persistent;

            Assert.AreEqual (0, pa.GetReceivers ().Length, "#1");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#2");

            mr.Execute ();

            Assert.AreEqual (1, pa.GetReceivers ().Length, "#3");
            Assert.AreEqual (1, pb.GetReceivers ().Length, "#4");

            Assert.AreEqual (ReceiverTaskState.Onetime, pa.GetReceivers ()[0].State, "#5");
        }
        public void PostToPortSetUserTaskItem()
        {
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            ITask task = new Task<int, string> ((i, s) => { });
            var mr = new MultipleItemReceiver (task, pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;

            mr.Execute ();
            ((Port<int>)pa).Post (10);

            Assert.AreEqual (10, task [0].Item, "#1");
        }
        public void Execute3()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            ITask task = new Task<int, string> ( (i, s) => { cnt += i + s.Length; });
            var mr = new MultipleItemReceiver (task, pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;

            mr.Execute ();

            var a = (Port<int>)pa;
            var b = (Port<string>)pb;

            b.Post ("hello");
            Assert.AreEqual (0, cnt, "#1");
            a.Post (10);

            Assert.AreEqual (15, cnt, "#2");
        }
        public void Execute2()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            ITask task = new Task<int, string> ( (i, s) => { cnt += i + s.Length; });
            var mr = new MultipleItemReceiver (task, pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;

            mr.Execute ();

            var a = (Port<int>)pa;
            var b = (Port<string>)pb;

            a.Post (10);
            Assert.AreEqual (0, pa.ItemCount, "#1");
            Assert.AreEqual (0, cnt, "#2");

            b.Post ("hello");
            Assert.AreEqual (15, cnt, "#3");

            //it's a one time thing
            Assert.AreEqual (0, pa.GetReceivers ().Length, "#4");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#5");

            a.Post (1);
            Assert.AreEqual (15, cnt, "#6");
            b.Post ("x");
            Assert.AreEqual (15, cnt, "#7");
        }
        public void Evaluate()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            var mr = new MultipleItemReceiver (Arbiter.FromHandler (() => { ++cnt; }), pa, pb);

            try {
                ITask res = null;
                mr.Evaluate (new PortElement<int> (10), ref res);
                Assert.Fail ("#1");
            } catch (NotImplementedException) {}
        }
        public void Consume()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            var mr = new MultipleItemReceiver (Arbiter.FromHandler (() => { ++cnt; }), pa, pb);

            try {
                mr.Consume (new PortElement<int> (10));
                Assert.Fail ("#1");
            } catch (NotImplementedException) {}
        }
Exemple #10
0
 internal ReceiverSurrogate(IPortReceive port, MultipleItemReceiver receiver, int number)
     : base(port, null)
 {
     this.receiver = receiver;
     this.number = number;
 }