Inheritance: IArbiterTask, ITask
Exemple #1
0
        public void CtorSideEffects()
        {
            int count = 0;
            var pa = new Port<int> ();
            var pb = new Port<string> ();

            var ra = Arbiter.Receive (false, pa, (i) => count += i);
            var rb = Arbiter.Receive (false, pb, (s) => count += s.Length);

            var c = new Choice (ra, rb);

            IPortReceive pra = pa;
            IPortReceive prb = pb;

            Assert.AreEqual (ArbiterTaskState.Created, c.ArbiterState, "#1");
            Assert.AreEqual (0, c.PortElementCount, "#2");
            Assert.AreEqual (0, pra.GetReceivers ().Length, "#3");
            Assert.AreEqual (0, prb.GetReceivers ().Length, "#4");
            Assert.IsNull (ra.Arbiter, "#5");
            Assert.IsNull (rb.Arbiter, "#6");
            Assert.IsNull (ra.ArbiterContext, "#7");
            Assert.IsNull (rb.ArbiterContext, "#8");
            Assert.IsNull (ra.ArbiterCleanupHandler, "#9");
            Assert.IsNull (rb.ArbiterCleanupHandler, "#10");
        }
Exemple #2
0
        public void ItemProperty()
        {
            var pa = new Port<int> ();
            var pb = new Port<string> ();

            var ra = Arbiter.Receive (false, pa, (i) => {});
            var rb = Arbiter.Receive (false, pb, (s) => {});

            var c = new Choice (ra, rb);

            try {
                c [0] = new PortElement<int> (10);
                Assert.Fail ("#1");
            } catch (NotSupportedException) {}

            try {
                var x = c [1];
                Assert.Fail ("#2");
            } catch (NotSupportedException) {}
        }
Exemple #3
0
        public void Execute()
        {
            var pa = new Port<int> ();
            var pb = new Port<string> ();

            var ra = Arbiter.Receive (false, pa, (i) => {});
            var rb = new NakedReceiver (pb, new Task<string>((s) => {}));

            var c = new Choice (ra, rb);

            IPortReceive pra = pa;
            IPortReceive prb = pb;

            Assert.IsNull (c.Execute (), "#0");

            Assert.AreEqual (ArbiterTaskState.Active, c.ArbiterState, "#1");
            Assert.AreEqual (0, c.PortElementCount, "#2");
            Assert.AreEqual (1, pra.GetReceivers ().Length, "#3");
            Assert.AreEqual (1, prb.GetReceivers ().Length, "#4");
            Assert.AreEqual (c, ra.Arbiter, "#5");
            Assert.AreEqual (c, rb.Arbiter, "#6");
            Assert.IsNull (ra.ArbiterContext, "#7");
            Assert.IsNull (rb.ArbiterContext, "#8");
            Assert.IsNull (ra.ArbiterCleanupHandler, "#9");
            Assert.IsNull (rb.ArbiterCleanupHandler, "#10");

            Assert.AreEqual (0, rb.execute, "#11");
            Assert.AreEqual (1, rb.set_arbiter, "#12");
        }
Exemple #4
0
        public void ExecutePart2()
        {
            int count = 3;
            var pa = new Port<int> ();
            var pb = new Port<string> ();

            var ra = Arbiter.Receive (false, pa, (i) => count += i);
            var rb = new NakedReceiver (pb, new Task<string>((s) => count += s.Length));
            var dq = new SerialDispatchQueue ();

            var c = new Choice (ra, rb);
            c.TaskQueue = dq;

            IPortReceive pra = pa;
            IPortReceive prb = pb;

            c.Execute ();
            pa.Post (10);

            Assert.AreEqual (ArbiterTaskState.Done, c.ArbiterState, "#1");
            Assert.AreEqual (0, c.PortElementCount, "#2");
            Assert.AreEqual (0, pra.GetReceivers ().Length, "#3");
            Assert.AreEqual (0, prb.GetReceivers ().Length, "#4");
            Assert.AreEqual (c, ra.Arbiter, "#5");
            Assert.AreEqual (c, rb.Arbiter, "#6");
            Assert.IsNull (ra.ArbiterContext, "#7");
            Assert.IsNull (rb.ArbiterContext, "#8");
            Assert.IsNull (ra.ArbiterCleanupHandler, "#9");
            Assert.IsNull (rb.ArbiterCleanupHandler, "#10");
            Assert.AreEqual (0, rb.execute, "#11");
            Assert.AreEqual (1, rb.set_arbiter, "#12");
            Assert.AreEqual (1, rb.cleanup, "#13");
            Assert.AreEqual (0, rb.cleanup_task, "#14");
            Assert.AreEqual (ReceiverTaskState.CleanedUp, ra.State, "#15");
            Assert.AreEqual (ReceiverTaskState.CleanedUp, rb.State, "#16");

            Assert.AreEqual (13, count, "#17");
        }
Exemple #5
0
        public void EvalateOnLooserReturnsNullTask()
        {
            int winner = 0;
            var pa = new Port<int> ();
            var pb = new Port<string> ();

            var ra = Arbiter.Receive (false, pa, (i) => { winner = 1; });
            var rb = Arbiter.Receive (false, pb, (s) => { winner = 2; });
            var dq = new SerialDispatchQueue ();

            var c = new Choice (ra, rb);
            c.TaskQueue = dq;

            IPortReceive pra = pa;
            IPortReceive prb = pb;

            c.Execute ();

            pa.Post (10);

            ITask tk = null;
            Assert.IsFalse (rb.Evaluate (new PortElement<string> (""), ref tk), "#1");
            Assert.IsNull (tk, "#2");
        }