Inheritance: Microsoft.Ccr.Core.Arbiters.ReceiverTask
Esempio n. 1
0
        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");
        }
Esempio n. 2
0
 public MultipleItemHelperReceiver(IPortReceive port, MultipleItemReceiver parent) : base(false, port, null)
 {
     _parent = parent;
 }
Esempio n. 3
0
        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");
        }
Esempio n. 4
0
        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");
        }
Esempio n. 5
0
        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");
        }
Esempio n. 6
0
        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");
        }
Esempio n. 7
0
        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");
        }
Esempio n. 8
0
        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) {}
        }
Esempio n. 9
0
        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) {}
        }
Esempio n. 10
0
 internal ReceiverSurrogate(IPortReceive port, MultipleItemReceiver receiver, int number)
     : base(port, null)
 {
     this.receiver = receiver;
     this.number = number;
 }