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

static private GetEndpoint ( List output ) : EndPoint
output List
Результат EndPoint
Пример #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);
        }
Пример #2
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");
        }
Пример #3
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]);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        public void ThreeStepWithMultilineAsciiArt()
        {
            List <string> results1 = new List <string>();
            List <string> results2 = new List <string>();

            StartPoint <int> s = Helpers.GetStartpointCounter(1, 50);
            TaskNode <int, string, string> splitter =
                new TaskNode <int, string, string>(
                    (int i, IWritableQueue <string> o1, IWritableQueue <string> o2) =>
            {
                if (i % 3 == 0 || i % 4 == 0 || i % 5 == 0)
                {
                    // divisible by 3, 4 or 5, go to stream 1
                    o1.Send(i.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    // if not, send i and i+1 to stream 2
                    o2.Send(i.ToString());
                    o2.Send((i + 1).ToString(CultureInfo.InvariantCulture));
                }
            }
                    );
            EndPoint <string> end1 = Helpers.GetEndpoint(results1);
            EndPoint <string> end2 = Helpers.GetEndpoint(results2);

            Flow flow = Flow.FromAsciiArt(@"
s--+
   |
   V
   t0->n
   1
   | 
   +---->m
",
                                          new Dictionary <char, TaskNode>()
            {
                { 's', s },
                { 't', splitter },
                { 'n', end1 },
                { 'm', end2 }
            }
                                          );

            flow.Start();
            flow.RunToCompletion();
            Assert.AreEqual(29, results1.Count);
            Assert.AreEqual("50", results1[28]);
            Assert.AreEqual(42, 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 ConnectingWrongTypesThrows()
        {
            List <string>     results = new List <string>();
            StartPoint <int>  s       = Helpers.GetStartpointCounter(1, 15);
            EndPoint <string> n       = Helpers.GetEndpoint(results);

            Flow flow = new Flow();

            flow.AddNode(s);
            flow.AddNode(n);
            try
            {
                flow.ConnectNodes(s, n, 0);
                Assert.Fail("Connecting nodes of different types should throw invalid operation exception");
            }
            catch (InvalidOperationException)
            { }
        }
Пример #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 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]);
        }
Пример #11
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());
        }