Beispiel #1
0
        public void StepByStepFirstAndLastCallIsSingle()
        {
            var provider = new NodeDefinitionProvider();

            provider.Register("FirstCall");
            provider.Register("ManyCalls", "FirstCall");
            provider.Register("LastCall", "ManyCalls");
            provider.SetRoot("LastCall");
            var node = provider.GetByName("LastCall");

            node.SingleCall = true;
            node            = provider.GetByName("FirstCall");
            node.SingleCall = true;
            List <string> messages     = new List <string>();
            var           nodeRegistry = new NodeRegistry <string>();

            nodeRegistry.Register("FirstCall", new BaseNode <string>(new FirstCallDataDriver(messages), provider.GetByName("FirstCall")));
            nodeRegistry.Register("ManyCalls", new BaseNode <string>(new ManyCallsDataDriver(messages), provider.GetByName("ManyCalls")));
            nodeRegistry.Register("LastCall", new BaseNode <string>(new LastCallDataDriver(messages), provider.GetByName("LastCall")));

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            Assert.AreEqual("FirstCall", messages[0]);
            Assert.AreEqual("Data0", messages[1]);
            Assert.AreEqual("LastCall", messages[2]);
            Assert.AreEqual("Data1", messages[3]);
            Assert.AreEqual("Data2", messages[4]);
        }
Beispiel #2
0
        public void ThreeRowsSimple()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{counterWrapper.Counter++}";
                }
                else
                {
                    p.Stop();
                }
            }), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner  = new DataNodeRunner <string>(provider, nodeRegistry);
            var wrapper = new DataItemWrapper <string>();

            runner.Step(wrapper);
            Assert.AreEqual("AAA0BBBCCC", wrapper.Item);
            runner.Step(wrapper);
            Assert.AreEqual("AAA1BBBCCC", wrapper.Item);
            runner.Step(wrapper);
            Assert.AreEqual("AAA2BBBCCC", wrapper.Item);
        }
Beispiel #3
0
        public void ThreeRowsSimpleRunAllNodesMustBeDisposed()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();
            var a = new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{counterWrapper.Counter++}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            });
            var b = new TestActionProcess(p => { p.Item = p.Item += "BBB"; });
            var c = new TestActionProcess(p => { p.Item = p.Item += "CCC"; });

            nodeRegistry.Register("A", new BaseNode <string>(a, definitionA));
            nodeRegistry.Register("B", new BaseNode <string>(b, definitionB));
            nodeRegistry.Register("C", new BaseNode <string>(c, definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            runner.Dispose();
            Assert.IsTrue(a.IsDisposed);
            Assert.IsTrue(b.IsDisposed);
            Assert.IsTrue(c.IsDisposed);
        }
Beispiel #4
0
        public void CommitThrowsTest()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var nodeRegistry = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{p.Number}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            }, () => throw new Exception("Houston we have a problem")), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            var current = runner.Current;

            Assert.AreEqual(1, current.CommitExceptions.Count);
        }
Beispiel #5
0
        public void Run()
        {
            var provider = new NodeDefinitionProvider("FileWriter");

            provider.Register("FileReader", new NodeDefinition()
            {
                Name = "FileReader"
            });
            provider.Register("FileWriter", new NodeDefinition()
            {
                Name      = "FileWriter",
                DependsOn = new List <string>()
                {
                    "ErrorWriter"
                }
            });
            provider.Register("ErrorWriter", new NodeDefinition()
            {
                Name      = "ErrorWriter",
                DependsOn = new List <string>()
                {
                    "FileReader"
                }
            });
            var input  = @"C:\Temp\My\1.txt";
            var output = @"C:\Temp\My\2.txt";
            var error  = @"C:\Temp\My\errors.txt";

            using (StreamWriter sw = new StreamWriter(input))
            {
                for (int i = 0; i < 100000; i++)
                {
                    if (i % 3000 == 0)
                    {
                        sw.WriteLine($"POOP{i}");
                    }
                    else
                    {
                        sw.WriteLine(i);
                    }
                }
            }
            var nodeRegistry = new NodeRegistry <FileMoverData>();

            nodeRegistry.Register("FileReader", new BaseNode <FileMoverData>(new FileReader(input), provider.GetByName("FileReader")));
            nodeRegistry.Register("FileWriter", new BaseNode <FileMoverData>(new FileWriter(output), provider.GetByName("FileWriter")));
            nodeRegistry.Register("ErrorWriter", new BaseNode <FileMoverData>(new ErrorWriter(error), provider.GetByName("ErrorWriter")));


            var runner = new DataNodeRunner <FileMoverData>(provider, nodeRegistry);

            runner.Run();
            runner.Dispose();
        }
Beispiel #6
0
        public void CommitTest()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var nodeRegistry = new NodeRegistry <string>();
            var flag         = new TestFlag();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{p.Number}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            }, () => { flag.Flag = true; }), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            Assert.IsTrue(flag.Flag);
        }
Beispiel #7
0
        public void ABBCSimpleWhenANodeShouldntBeCalledTwice()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B",
                    "A"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var nodeRegistry = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p => { p.Item = "AAA"; }), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner  = new DataNodeRunner <string>(provider, nodeRegistry);
            var wrapper = new DataItemWrapper <string>();

            runner.Step(wrapper);
            Assert.AreEqual("AAABBBCCC", wrapper.Item);
        }
 static NodeDefinitionProvider()
 {
     Instance = new NodeDefinitionProvider();
 }
Beispiel #9
0
        public void ThreeRowsTheSecondSkip()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    if (p.Item == null)
                    {
                        p.Item = "";
                    }
                    p.Item = p.Item + $"AAA{counterWrapper.Counter++}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            }), definitionA));
            nodeRegistry.Register("B", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number == 1)
                {
                    p.Skip();
                }
                else
                {
                    p.Item = p.Item += "BBB";
                }
            }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            var result = runner.Current;

            Assert.AreEqual("AAA0BBBCCCAAA1AAA2BBBCCC", result.Item);
        }
Beispiel #10
0
        public void ThreeRowsAndBThrowsErrorOnTheSecond()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{counterWrapper.Counter++}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            }), definitionA));
            nodeRegistry.Register("B", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number == 1)
                {
                    throw new Exception("Houston we have a problem");
                }
                p.Item += "BBB";
            }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            var result = runner.Current;

            Assert.AreEqual("AAA2BBBCCC", result.Item);
        }