Inheritance: Microsoft.Ccr.Core.Arbiters.ReceiverTask, ITask
Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #4
0
        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");
        }
Beispiel #5
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");
        }
Beispiel #6
0
        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");
        }
Beispiel #7
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");
        }
Beispiel #8
0
        public void Evaluate()
        {
            Type[] types = new Type[] { typeof (int), typeof (string) };
            IPortReceive[] ports = new IPortReceive[] { new Port<int>(), new Port<string> () };
            int count = 1;
            Handler<ICollection[]> handler = (cols) => {};
            var mig = new MultipleItemGather (types, ports, count, handler);

            try {
                ITask res = null;
                mig.Evaluate (new PortElement<int> (10), ref res);
                Assert.Fail ("#1");
            } catch (InvalidOperationException) {}
        }
Beispiel #9
0
 internal MultiItemReceiverSurrogate(IPortReceive port, MultipleItemGather receiver, int number)
     : base(port, null)
 {
     this.receiver = receiver;
     this.number = number;
 }
 public GatherPrivateReceiver(IPortReceive port, MultipleItemGather parent) : base(true, port, null)
 {
     _parent = parent;
 }