Execute() public method

public Execute ( ) : IEnumerator
return IEnumerator
Esempio n. 1
0
        public void CleanupDoneInlineWithoutArbiter()
        {
            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 dq = new SerialDispatchQueue ();
            dq.exec = false;
            mig.TaskQueue = dq;

            mig.Execute ();

            var rec = ports [0].GetReceivers () [0];
            var rec2 = ports [0].GetReceivers () [1];
            ITask task = null;
            Assert.IsTrue (rec.Evaluate (new PortElement<int> (10), ref task), "#1");
            Assert.IsNotNull (task, "#2");
            Assert.AreEqual (ReceiverTaskState.CleanedUp, mig.State, "#3");
            Assert.AreEqual (ReceiverTaskState.Persistent, rec.State, "#4");
            Assert.AreEqual (ReceiverTaskState.Persistent, rec2.State, "#5");
            Assert.AreEqual (0, dq.count, "#6");
        }
Esempio n. 2
0
        public void CleanupTask()
        {
            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 = 2;
            Handler<ICollection[]> handler = (cols) => { };
            var mig = new MultipleItemGather (types, ports, count, handler);
            var dq = new SerialDispatchQueue ();
            mig.TaskQueue = dq;

            mig.Execute ();

            ITask task = null;
            var rec = ports [0].GetReceivers () [0];
            Assert.IsTrue (rec.Evaluate (new PortElement<int> (10), ref task), "#1");
            Assert.IsNull (task, "#2");
            Assert.IsTrue (rec.Evaluate (new PortElement<int> (20), ref task), "#3");
            Assert.IsNotNull (task, "#4");

            mig.Cleanup (task);

            Assert.AreEqual (2, pa.ItemCount, "#4");
            Assert.AreEqual (0, pb.ItemCount, "#5");

            Assert.AreEqual (10, pa.Test (), "#6");
            Assert.AreEqual (20, pa.Test (), "#7");
        }
Esempio n. 3
0
        public void WhatResultDataHas2()
        {
            Port<int> pa = new Port<int> ();
            Port<string> pb = new Port<string> ();
            ICollection[] res = null;

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

            mig.Execute ();

            pa.Post (10); //result is post order independent
            pb.Post ("hw");

            Assert.IsTrue (res [0] is List<object>, "#1");
            Assert.IsTrue (res [1] is List<object>, "#2");
            var la = res [0] as List<object>;
            var lb = res [1] as List<object>;

            Assert.AreEqual (10, la [0], "#3");
            Assert.AreEqual ("hw", lb [0], "#4");
        }
Esempio n. 4
0
        public void PostToPortsAfterExecute6()
        {
            Port<int> pa = new Port<int> ();
            Port<string> pb = new Port<string> ();
            int resA = 0;
            int resB = 0;

            Type[] types = new Type[] { typeof (int), typeof (string) };
            IPortReceive[] ports = new IPortReceive[] { pa, pb };
            int count = 2;
            Handler<ICollection[]> handler = (cols) => { resA += cols[0].Count ; resB += cols[1].Count; };
            var mig = new MultipleItemGather (types, ports, count, handler);
            var dq = new SerialDispatchQueue ();
            mig.TaskQueue = dq;

            mig.Execute ();

            pb.Post ("hw");
            pa.Post (10);

            Assert.AreEqual (1, resA, "#1");
            Assert.AreEqual (1, resB, "#2");
            Assert.AreEqual (1, dq.count, "#3");
            Assert.AreEqual (ReceiverTaskState.CleanedUp, mig.State, "#4");
        }
Esempio n. 5
0
        public void Execute2()
        {
            Type[] types = new Type[] { typeof (int), typeof (string) };
            IPortReceive[] ports = new IPortReceive[] { new Port<int>(), new Port<string> () };
            int count = 2;
            Handler<ICollection[]> handler = (cols) => {};
            var mig = new MultipleItemGather (types, ports, count, handler);
            var dq = new SerialDispatchQueue ();
            mig.TaskQueue = dq;

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

            mig.Execute ();

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

            Assert.AreEqual (ReceiverTaskState.Persistent, ports [0].GetReceivers ()[0].State, "#5");
            Assert.AreEqual (ReceiverTaskState.Persistent, ports [0].GetReceivers ()[1].State, "#6");
            Assert.AreEqual (ReceiverTaskState.Persistent, ports [1].GetReceivers ()[0].State, "#7");
            Assert.AreEqual (ReceiverTaskState.Persistent, ports [1].GetReceivers ()[1].State, "#8");

            Assert.AreEqual (0, dq.count, "#9");
        }