Beispiel #1
0
        public void ThreeStepWithInputPoint()
        {
            List <string>          results = new List <string>();
            InputPoint <int>       s       = new InputPoint <int>();
            TaskNode <int, string> filter  = Helpers.GetFilter();

            EndPoint <string> n = Helpers.GetEndpoint(results);

            Flow flow = Helpers.ConnectStartFilterEnd(s, filter, n);

            flow.Start();
            s.Send(1, 2, 3, 4, 5, 6, 7, 8);
            s.Send(new int[] { 9, 10, 11, 12, 13, 14, 15 });
            flow.RunToCompletion();
            Assert.AreEqual(4, results.Count);
            Assert.AreEqual(15, filter.ItemsProcessed);
            Assert.AreEqual(RunStatus.Running, n.Status);

            s.CloseEntrance();
            flow.RunToCompletion();
            // at this point, the flow and some nodes may still be running or stopping,
            // the data items have left the flow, but the nodes can still be in the process of stopping
            Assert.Contains(n.Status, new List <RunStatus>()
            {
                RunStatus.Running, RunStatus.Stopping, RunStatus.Stopped
            });

            // after a small wait, everything should be in the Stopped status
            Thread.Sleep(100);
            Assert.AreEqual(RunStatus.Stopped, n.Status);
        }
Beispiel #2
0
        public void ThreeStepWithInputAndOutputPoints()
        {
            List <string>          results = new List <string>();
            InputPoint <int>       s       = new InputPoint <int>();
            TaskNode <int, string> filter  = Helpers.GetFilter();

            OutputPoint <string> outpoint = new OutputPoint <string>();

            Flow flow = Helpers.ConnectStartFilterEnd(s, filter, outpoint);

            flow.Start();
            s.Send(1, 2, 3, 4, 5, 6, 7, 8);
            s.Send(new int[] { 9, 10, 11, 12, 13, 14, 15 });
            string firstResult = outpoint.Output.Receive();

            Assert.AreEqual("3.00", firstResult);
        }
Beispiel #3
0
        public void StopRightInTheMiddle()
        {
            InputPoint <int>    inp     = new InputPoint <int>();
            TaskNode <int, int> process = new TaskNode <int, int>(
                (input, output) => output.Send(input)
                );

            process.ThreadNumber = 2;
            process.KeepOrder    = true;
            Collector <int> coll = new Collector <int>();

            Flow flow = Flow.FromAsciiArt("a->b->c",
                                          inp,
                                          process,
                                          coll
                                          );

            coll.ItemProcessed += (o, a) =>
            {
                if ((int)a.Item == 0)
                {
                    flow.Stop();
                }
                var state = flow.GetStateSnapshot();
                Console.WriteLine(state.ToStringAsciiArt());
            };

            flow.Start();
            for (int i = 1; i < 100; i++)
            {
                inp.Send(i);
            }
            inp.Send(0);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            //for (int i = 1; i < 1000; i++)
            //{
            //    inp.Send(i);
            //}
            flow.RunToCompletion();
            Assert.AreEqual(coll.Items.Count, 100);
        }
Beispiel #4
0
        public void StopRightInTheMiddle()
        {
            InputPoint<int> inp = new InputPoint<int>();
            TaskNode<int,int> process = new TaskNode<int, int>(
                    (input, output) => output.Send(input)
                        );
            process.ThreadNumber = 2;
            process.KeepOrder = true;
            Collector<int> coll = new Collector<int>();

            Flow flow = Flow.FromAsciiArt("a->b->c",
                inp,
                process,
                coll
                );
            coll.ItemProcessed += (o,a) =>
                {
                    if ((int)a.Item == 0)
                    {
                        flow.Stop();
                    }
                    var state = flow.GetStateSnapshot();
                    Console.WriteLine(state.ToStringAsciiArt());
                };

            flow.Start();
            for (int i = 1; i < 100; i++)
            {
                inp.Send(i);
            }
            inp.Send(0);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            inp.Send(1);
            //for (int i = 1; i < 1000; i++)
            //{
            //    inp.Send(i);
            //}
            flow.RunToCompletion();
            Assert.AreEqual(coll.Items.Count,100);
        }
Beispiel #5
0
        public void SortingValues()
        {
            InputPoint <int>    entry   = new InputPoint <int>();
            TaskNode <int, int> sorter  = StandardTasks.GetSortingFilter <int>();
            Collector <int>     collect = new Collector <int>();

            sorter.ItemProcessed += new EventHandler <TaskNode.ItemEventArgs>(sorter_ItemProcessed);

            Flow f = Flow.FromAsciiArt("a-->b-->c", entry, sorter, collect);

            f.Start();

            entry.Send(3, 7, 1, 9, 123, 2, 5, 3);
            entry.CloseEntrance();
            f.RunToCompletion();
            //Thread.Sleep(1000);
            Console.WriteLine("Last:" + f.GetStateSnapshot());
            Assert.AreEqual(8, collect.Items.Count);
            Assert.AreEqual(1, collect.Items[0]);
            Assert.AreEqual(3, collect.Items[3]);
        }
Beispiel #6
0
        public void ThreeStepWithInputAndOutputPoints()
        {
            List<string> results = new List<string>();
            InputPoint<int> s = new InputPoint<int>();
            TaskNode<int, string> filter = Helpers.GetFilter();

            OutputPoint<string> outpoint = new OutputPoint<string>();

            Flow flow = Helpers.ConnectStartFilterEnd(s, filter, outpoint);

            flow.Start();
            s.Send(1, 2, 3, 4, 5, 6, 7, 8);
            s.Send(new int[] { 9, 10, 11, 12, 13, 14, 15 });
            string firstResult = outpoint.Output.Receive();
            Assert.AreEqual("3.00", firstResult);
        }
Beispiel #7
0
        public void ThreeStepWithInputPoint()
        {
            List<string> results = new List<string>();
            InputPoint<int> s = new InputPoint<int>();
            TaskNode<int, string> filter = Helpers.GetFilter();

            EndPoint<string> n = Helpers.GetEndpoint(results);

            Flow flow = Helpers.ConnectStartFilterEnd(s, filter, n);

            flow.Start();
            s.Send(1,2,3,4,5,6,7,8);
            s.Send(new int[]{9,10,11,12,13,14,15});
            flow.RunToCompletion();
            Assert.AreEqual(4, results.Count);
            Assert.AreEqual(15, filter.ItemsProcessed);
            Assert.AreEqual(RunStatus.Running, n.Status);

            s.CloseEntrance();
            flow.RunToCompletion();
            // at this point, the flow and some nodes may still be running or stopping,
            // the data items have left the flow, but the nodes can still be in the process of stopping
            Assert.Contains(n.Status, new List<RunStatus>(){RunStatus.Running , RunStatus.Stopping, RunStatus.Stopped});

            // after a small wait, everything should be in the Stopped status
            Thread.Sleep(100);
            Assert.AreEqual(RunStatus.Stopped, n.Status);
        }