Exemple #1
0
        public void ReceiverForIteratorWithArbiter()
        {
            Task<int> task = new Task<int> ((i)=>{});
            Port<int> port = new Port<int> ();
            var arbiter = new NakedArbiter (task);
            arbiter.TaskQueue = new VoidDispatcherQueue ();

            var receiver = port.Receive ();
            receiver.Arbiter = arbiter;

            ITask res = null;
            Assert.IsFalse (receiver.Evaluate (new PortElement<int>(10), ref res), "#1");
            Assert.AreEqual (task, res, "#2");
            Assert.IsNotNull (arbiter.taskPassed, "#3");
        }
        public void ExecuteWithArbiter2()
        {
            Port<int> pa = new Port<int> ();
            Port<string> pb = new Port<string> ();

            Type[] types = new Type[] { typeof (int), typeof (string) };
            IPortReceive[] ports = new IPortReceive[] { pa, pb };
            int count = 1;
            Handler<ICollection[]> handler = (cols) => { };
            var mig = new MultipleItemGather (types, ports, count, handler);

            var arbiter = new NakedArbiter (false);
            var dq = new SerialDispatchQueue ();
            arbiter.TaskQueue = dq;
            mig.Arbiter = arbiter;

            var rec = ports [0].GetReceivers () [0];
            ITask task = null;
            Assert.IsFalse (rec.Evaluate (new PortElement<int> (10), ref task), "#1");
            Assert.AreEqual (1, arbiter.calls, "#2");
            Assert.IsNotNull (task, "#3");
            Assert.AreEqual (ReceiverTaskState.Onetime, mig.State, "#4");
            Assert.AreEqual (ReceiverTaskState.Persistent, rec.State, "#5");
        }
        public void ExecuteWithArbiter1()
        {
            Port<int> pa = new Port<int> ();
            Port<string> pb = new Port<string> ();
            bool handler_called = false;

            Type[] types = new Type[] { typeof (int), typeof (string) };
            IPortReceive[] ports = new IPortReceive[] { pa, pb };
            int count = 2;
            Handler<ICollection[]> handler = (cols) => { handler_called = true; };
            var mig = new MultipleItemGather (types, ports, count, handler);

            var arbiter = new NakedArbiter (false);
            var dq = new SerialDispatchQueue ();
            arbiter.TaskQueue = dq;
            mig.Arbiter = arbiter;

            Assert.AreEqual (1, ports [0].GetReceivers ().Length, "#1");
            Assert.AreEqual (1, ports [1].GetReceivers ().Length, "#2");

            pa.Post (10);

            Assert.AreEqual (1, ports [0].GetReceivers ().Length, "#4");
            Assert.AreEqual (1, ports [1].GetReceivers ().Length, "#3");

            Assert.AreEqual (0, dq.count, "#4");
            Assert.AreEqual (0, arbiter.calls, "#5");
            Assert.AreEqual (ReceiverTaskState.Onetime, mig.State, "#6");
            Assert.IsFalse (handler_called, "#13");
            pa.Post (10);

            Assert.AreEqual (1, ports [0].GetReceivers ().Length, "#7");
            Assert.AreEqual (1, ports [1].GetReceivers ().Length, "#8");

            Assert.AreEqual (1, dq.count, "#9");
            Assert.AreEqual (1, arbiter.calls, "#10");
            Assert.AreEqual (ReceiverTaskState.Onetime, mig.State, "#11");
            Assert.IsTrue (handler_called, "#14");
        }