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); }
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()); }
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); }
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()); }