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]); }
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); }
public void ThreeRowsSimpleRun() { 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 => { 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("AAA2BBBCCC", result.Item); }
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); }
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(); }
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); }