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 JoinReceiver(bool persist, ITask task, params IPortReceive[] ports) : base(task)
        {
            if (ports == null)
            {
                throw new ArgumentNullException("ports");
            }
            if (persist)
            {
                _state = ReceiverTaskState.Persistent;
            }
            if (ports == null || ports.Length == 0)
            {
                throw new ArgumentOutOfRangeException("aP", Resource1.JoinsMustHaveOnePortMinimumException);
            }
            _ports = new Receiver[ports.Length];
            int[] array = new int[ports.Length];
            int   num   = 0;

            for (int i = 0; i < ports.Length; i++)
            {
                IPortReceive portReceive = ports[i];
                int          hashCode    = portReceive.GetHashCode();
                Receiver     receiver    = new Receiver(portReceive);
                _ports[num]             = receiver;
                array[num]              = hashCode;
                receiver.ArbiterContext = num;
                num++;
            }
            Array.Sort <int, Receiver>(array, _ports);
        }
Esempio n. 4
0
 public Receiver(bool persist, IPortReceive port, ITask task) : base(task)
 {
     if (persist)
     {
         _state = ReceiverTaskState.Persistent;
     }
     _port = port;
 }
Esempio n. 5
0
 public JoinSinglePortReceiver(bool persist, ITask task, IPortReceive port, int count) : base(task)
 {
     if (persist)
     {
         _state = ReceiverTaskState.Persistent;
     }
     if (count <= 0)
     {
         throw new ArgumentException(Resource1.JoinSinglePortReceiverAtLeastOneItemMessage, "count");
     }
     _port  = port;
     _count = count;
 }
Esempio n. 6
0
        private void Register()
        {
            int num = 0;

            _receivers = new Receiver[_ports.Length];
            IPortReceive[] ports = _ports;
            for (int i = 0; i < ports.Length; i++)
            {
                IPortReceive portReceive = ports[i];
                Receiver     receiver    = new GatherPrivateReceiver(portReceive, this);
                _receivers[num++]  = receiver;
                receiver.TaskQueue = base.TaskQueue;
                portReceive.RegisterReceiver(receiver);
                if (_pendingItemCount <= 0)
                {
                    return;
                }
            }
        }
Esempio n. 7
0
        private void Register()
        {
            int num = 0;

            IPortReceive[] ports = _ports;
            for (int i = 0; i < ports.Length; i++)
            {
                IPortReceive port     = ports[i];
                Receiver     receiver = new MultipleItemHelperReceiver(port, this);
                receiver._arbiterContext = num;
                _receivers[num++]        = receiver;
                receiver.TaskQueue       = base.TaskQueue;
            }
            num = 0;
            IPortReceive[] ports2 = _ports;
            for (int j = 0; j < ports2.Length; j++)
            {
                IPortReceive portReceive = ports2[j];
                portReceive.RegisterReceiver(_receivers[num++]);
            }
        }
Esempio n. 8
0
        //FIXME what's the use of the types array?
        public MultipleItemGather(Type[] types, IPortReceive[] ports, int itemCount, Handler<ICollection[]> handler)
        {
            if (types == null)
                throw new ArgumentNullException("types");
            if (ports == null)
                throw new ArgumentNullException("ports");
            if (handler == null)
                throw new ArgumentNullException("handler");
            if (types.Length == 0)
                throw new ArgumentOutOfRangeException ("types");
            if (ports.Length == 0)
                throw new ArgumentOutOfRangeException ("ports");
            if (types.Length != ports.Length)
                throw new ArgumentOutOfRangeException ("types");

            this.types = types;
            this.ports = ports;
            this.itemCount = itemCount;
            this.handler = handler;
            this.results = new List<object>[ports.Length];
            for (int i = 0; i < ports.Length; ++i)
                this.results [i] = new List<object> ();
        }
Esempio n. 9
0
        public void CtorBadArgs()
        {
            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) => {};
            new MultipleItemGather (types, ports, count, handler);
            try {
                new MultipleItemGather (null, ports, count, handler);
                Assert.Fail ("#1");
            } catch (ArgumentNullException) {}

            try {
                new MultipleItemGather (types, null, count, handler);
                Assert.Fail ("#2");
            } catch (ArgumentNullException) {}

            try {
                new MultipleItemGather (types, ports, count, null);
                Assert.Fail ("#3");
            } catch (ArgumentNullException) {}

            try {
                new MultipleItemGather (new Type[0], ports, count, handler);
                Assert.Fail ("#4");
            } catch (ArgumentOutOfRangeException) {}

            try {
                new MultipleItemGather (types, new IPortReceive [0], count, handler);
                Assert.Fail ("#5");
            } catch (ArgumentOutOfRangeException) {}

            try {
                new MultipleItemGather (new Type [0], new IPortReceive [0], count, handler);
                Assert.Fail ("#6");
            } catch (ArgumentOutOfRangeException) {}

            try {
                new MultipleItemGather (new Type[] { typeof (int) }, ports, count, handler);
                Assert.Fail ("#7");
            } catch (ArgumentOutOfRangeException) {}
        }
Esempio n. 10
0
 public MultipleItemHelperReceiver(IPortReceive port, MultipleItemReceiver parent) : base(false, port, null)
 {
     _parent = parent;
 }
Esempio n. 11
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. 12
0
 internal MultiItemReceiverSurrogate(IPortReceive port, MultipleItemGather receiver, int number)
     : base(port, null)
 {
     this.receiver = receiver;
     this.number = number;
 }
Esempio n. 13
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. 14
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");
        }
Esempio n. 15
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");
        }
Esempio n. 16
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");
        }
Esempio n. 17
0
 public GatherPrivateReceiver(IPortReceive port, MultipleItemGather parent) : base(true, port, null)
 {
     _parent = parent;
 }
Esempio n. 18
0
 internal NakedReceiver(IPortReceive p, ITask task)
     : base(p, task)
 {
 }
Esempio n. 19
0
 public Receiver(IPortReceive port, ITask task) : this(false, port, task)
 {
 }
Esempio n. 20
0
 internal Receiver(IPortReceive port)
 {
     _port = port;
 }
Esempio n. 21
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) {}
        }
Esempio n. 22
0
 internal WeirdReceiver(IPortReceive port)
     : base(port, null)
 {
     this.port = port;
     port.RegisterReceiver (this);
 }