Example #1
0
        public void ExceptionsFromTasks()
        {
            StartPoint <int> start = StandardTasks.GetRangeEnumerator(1, 10);
            int            i       = 0;
            EndPoint <int> end     = new EndPoint <int>(
                (int input) =>
            {
                i++;
                throw new InvalidTimeZoneException();
            }
                );

            end.Retries = 3;
            Flow f = Flow.FromAsciiArt("b<--a", start, end);

            f.Start();
            try
            {
                f.RunToCompletion();
                Assert.Fail("RunToCompletion should throw any stopping exceptions from tasks");
            }
            catch (InvalidTimeZoneException)
            { }
            Console.WriteLine("Exceptions thown : {0}", i);
            Console.WriteLine("Status of flow after error: \n{0}", f.GetStateSnapshot());
            Assert.AreEqual(RunStatus.Error, end.Status);
            Assert.AreEqual(0, end.ItemsProcessed);
        }
Example #2
0
        public void EventsAndStatePresentation()
        {
            StartPoint <int>       start  = StandardTasks.GetRangeEnumerator(1, 100);
            TaskNode <int, string> filter = Helpers.GetFilter();

            filter.ThreadNumber = 2;
            Collector <string> end = new Collector <string>();

            filter.ItemProcessed += new EventHandler <TaskNode.ItemEventArgs>(EndItemProcessed);
            Flow f = Flow.FromAsciiArt("a-->b->z", start, filter, end);

            f.Start();
            f.RunToCompletion();
            // all items have left the flow, but some threads may still be running. The status of the tasks
            // could still be Stopping, or even Running
            Thread.Sleep(10);
            // Now everything should have status Stopped
            Assert.AreEqual(RunStatus.Stopped, f.Status);
            Console.WriteLine("last: {0}\n\n", f.GetStateSnapshot());
        }
Example #3
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]);
        }
Example #4
0
        public void JoinedStreams2()
        {
            StartPoint <int> r1 = StandardTasks.GetRangeEnumerator(21, 50);
            StartPoint <int> r2 = StandardTasks.GetRangeEnumerator(41, 90);
            StartPoint <int> r3 = StandardTasks.GetRangeEnumerator(-9, 10);
            Collector <int>  c  = new Collector <int>();
            Flow             f  = Flow.FromAsciiArt(@"
             a  b  c
             |  |  |
             +->#<-+
                |
                V
                d
 ", new Dictionary <char, TaskNode>()
            {
                { 'a', r1 }, { 'b', r2 }, { 'c', r3 }, { 'd', c }
            });

            f.Start();
            f.RunToCompletion();
            Assert.AreEqual(100, c.Items.Count);
        }
Example #5
0
        public void HandledExceptionsFromTasks()
        {
            StartPoint <int> start = StandardTasks.GetRangeEnumerator(1, 2);
            int            i       = 0;
            EndPoint <int> end     = new EndPoint <int>(
                (int input) =>
            {
                i++;
                throw new InvalidTimeZoneException();
            }
                );

            end.Retries = 3;
            Flow f = Flow.FromAsciiArt("b<--a", start, end);

            f.Error += new EventHandler <Flow.ErrorEventArgs>(f_Error);
            f.Start();
            f.RunToCompletion();
            //Assert.AreEqual(RunStatus.Stopped, end.Status); //check doesn't hold, as the separate tasks may still be shutting down when the last data item leaves the system
            Assert.AreEqual(0, end.ItemsProcessed); // nothing successfully
            Console.WriteLine("Status of flow: \n{0}", f.GetStateSnapshot());
        }