GetFilter() статический приватный Метод

static private GetFilter ( ) : string>.TaskNode
Результат string>.TaskNode
Пример #1
0
        public void ThreeStepWithFilter()
        {
            List <string>    results = new List <string>();
            StartPoint <int> s       = Helpers.GetStartpointCounter(1, 100);
            // pass only numbers divisible by three with no 2 in them
            // Output in
            TaskNode <int, string> filter = Helpers.GetFilter();

            filter.ItemProcessed += new EventHandler <TaskNode.ItemEventArgs>(EndItemProcessed);

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

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

            flow.Start();
            flow.RunToCompletion();

            Assert.Contains(flow.Status, new List <RunStatus>()
            {
                RunStatus.Stopped, RunStatus.Stopping
            });

            Assert.AreEqual(27, results.Count);
            Assert.AreEqual(results.Count, n.ItemsProcessed);
            Assert.AreEqual(1, s.ItemsProcessed);
            Console.WriteLine(flow.GetStateSnapshot());
            Assert.Greater(s.TotalSecondsProcessing, 0);
            Assert.Greater(filter.TotalSecondsProcessing, 0);
            Assert.Greater(filter.TotalSecondsBlocked, 0);

            // Each node works with one thread, so order is maintained, so:
            Assert.AreEqual('3', results[0][0]);
        }
Пример #2
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);
        }
Пример #3
0
        public void IllegalAsciiArt1()
        {
            List <string> results = new List <string>();

            StartPoint <int>       s      = Helpers.GetStartpointCounter(1, 15);
            TaskNode <int, string> filter = Helpers.GetFilter();
            EndPoint <string>      n      = Helpers.GetEndpoint(results);

            try
            {
                Flow flow = Flow.FromAsciiArt(@"
   a----->b->c
     <--
",
                                              new Dictionary <char, TaskNode>()
                {
                    { 'a', s },
                    { 'b', filter },
                    { 'c', n }
                }
                                              );
            }
            catch (InvalidOperationException)
            {
                return;
            }
            Assert.Fail("loose arrows should throw exception");
        }
Пример #4
0
        public void StartingAndStopping()
        {
            StartPoint <int> s = Helpers.GetStartpointCounter(1, 15);
            // pass only numbers divisible by three with no 2 in them
            // Output in
            TaskNode <int, string> filter = Helpers.GetFilter();

            filter.ThreadNumber = 2;

            Collector <string> collect = new Collector <string>();

            filter.ItemProcessed += new EventHandler <TaskNode.ItemEventArgs>(StopFlowItemProcessed);
            Flow flow = Flow.FromAsciiArt("c->d--->e", s, filter, collect);

            flow.Start();
            // Flow will be stopped from evnt handler
            // Give it time to do it wrong:
            Thread.Sleep(100);
            Assert.Greater(collect.Items.Count, 0);
            Assert.Less(collect.Items.Count, 4);
            flow.RunToCompletion();
            try
            {
                Console.WriteLine(flow.Status);
                //flow.Start();
                //Assert.Fail("An exception should be thrown when starting a stopped flow");
            }
            catch (InvalidOperationException)
            {
                //noop
            }
        }
Пример #5
0
        public void ThreeStepWithMultilineAsciiArt()
        {
            List <string> results = new List <string>();

            StartPoint <int>       s      = Helpers.GetStartpointCounter(1, 15);
            TaskNode <int, string> filter = Helpers.GetFilter();
            EndPoint <string>      n      = Helpers.GetEndpoint(results);

            Flow flow = Flow.FromAsciiArt(@"
   a
   |
   V 
   b
   |  
   +->c",
                                          new Dictionary <char, TaskNode>()
            {
                { 'a', s },
                { 'b', filter },
                { 'c', n }
            }
                                          );

            flow.Start();
            flow.RunToCompletion();
            Assert.AreEqual(4, results.Count);

            string outputArt = flow.GetStateSnapshot().ToStringAsciiArt();

            Assert.IsFalse(string.IsNullOrEmpty(outputArt));
            Console.WriteLine(outputArt);
        }
Пример #6
0
        public void LegalAsciiArtParallel()
        {
            List <string> results1 = new List <string>();
            List <string> results2 = new List <string>();

            StartPoint <int>       s1      = Helpers.GetStartpointCounter(1, 15);
            StartPoint <int>       s2      = Helpers.GetStartpointCounter(5, 35);
            TaskNode <int, string> filter1 = Helpers.GetFilter();
            TaskNode <int, string> filter2 = Helpers.GetFilter();
            EndPoint <string>      n1      = Helpers.GetEndpoint(results1);
            EndPoint <string>      n2      = Helpers.GetEndpoint(results2);

            n2.ThreadNumber = 3;

            Flow flow = Flow.FromAsciiArt(@"
a-->b->c
d->e--->f
",
                                          new Dictionary <char, TaskNode>()
            {
                { 'a', s1 },
                { 'b', filter1 },
                { 'c', n1 },
                { 'd', s2 },
                { 'e', filter2 },
                { 'f', n2 }
            }
                                          );

            flow.Start();
            flow.RunToCompletion();

            Assert.AreEqual(4, results1.Count);
            Assert.AreEqual(6, results2.Count);
        }
Пример #7
0
        public void ThreeStepWithAsciiArt()
        {
            List <string> results = new List <string>();

            StartPoint <int>       s      = Helpers.GetStartpointCounter(1, 15);
            TaskNode <int, string> filter = Helpers.GetFilter();
            EndPoint <string>      n      = Helpers.GetEndpoint(results);

            Flow flow = Flow.FromAsciiArt(@"a-->b-->c", s, filter, n);

            flow.Start();
            flow.RunToCompletion();
            Assert.AreEqual(4, results.Count);
        }
Пример #8
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);
        }
Пример #9
0
        public void IllegalAsciiArtList()
        {
            List <string> results = new List <string>();

            StartPoint <int>       s      = Helpers.GetStartpointCounter(1, 15);
            TaskNode <int, string> filter = Helpers.GetFilter();
            EndPoint <string>      n      = Helpers.GetEndpoint(results);

            try
            {
                Flow flow = Flow.FromAsciiArt(@"a-->b-->c", s, filter);
                Assert.Fail("Flow should raise an exception when the art uses more or less letters than tasks");
            }
            catch (Exception)
            {
                // noop
            }
        }
Пример #10
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());
        }
Пример #11
0
        public void KeepOrder()
        {
            List <string>    results = new List <string>();
            StartPoint <int> s       = Helpers.GetStartpointCounter(1, 15);
            // pass only numbers divisible by three with no 2 in them
            // Output in
            TaskNode <int, string> filter = Helpers.GetFilter();

            filter.ThreadNumber = 5;
            filter.KeepOrder    = true;

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

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

            flow.Start();
            flow.RunToCompletion();
            Assert.AreEqual(4, results.Count);
            Assert.AreEqual("3.00", results[0]);
        }
Пример #12
0
        public void ThreeStepWithMultilineAsciiArt2()
        {
            List <string> results = new List <string>();

            StartPoint <int>       s      = Helpers.GetStartpointCounter(1, 15);
            TaskNode <int, string> filter = Helpers.GetFilter();
            EndPoint <string>      n      = Helpers.GetEndpoint(results);

            Flow flow = Flow.FromAsciiArt(@"
   +-----+
   |     |
   V     |
   b     a
   |         c
   |         ^
   |         |
   +---#-----+", s, filter, n);

            flow.Start();
            flow.RunToCompletion();
            Assert.AreEqual(4, results.Count);
            Console.WriteLine(flow.GetStateSnapshot().ToStringAsciiArt());
        }