Пример #1
0
 public void TestWorkflowErrorHandling()
 {
     using (ILogger logger = new TraceLogger(true))
     {
         IWorkContext context    = new WorkContext(logger, null, "UnitTest");
         const int    routerPort = 9991;
         using (var router = new GridSeqStep())
         {
             router.Initialise(context);
             router.EnableGrid(GridLevel.Router, Guid.NewGuid(), routerPort, null);
             using (var worker = new GridSeqStep())
             {
                 worker.Initialise(context);
                 worker.EnableGrid(GridLevel.Worker, Guid.NewGuid(), routerPort, null);
                 // succeeds
                 {
                     WorkflowOutput <GridData2> output = worker.Execute(new GridData1 {
                         S = "1.0"
                     });
                     Assert.IsNotNull(output.Errors);
                     Assert.AreEqual(0, output.Errors.Length);
                     Assert.AreEqual(1.0, output.Result.D);
                 }
                 // fails in 1st substep
                 {
                     WorkflowOutput <GridData2> output = worker.Execute(new GridData1 {
                         S = "not_a_number"
                     });
                     Assert.IsNotNull(output.Errors);
                     Assert.AreEqual(1, output.Errors.Length);
                     Assert.AreEqual(typeof(FormatException).FullName, output.Errors[0].FullName);
                     Assert.AreEqual(default, output.Result);
Пример #2
0
 public void TestSelfHostedGrid()
 {
     using (ILogger logger = new TraceLogger(true))
     {
         IWorkContext context = new WorkContext(logger, null, "UnitTest");
         // defines and executes a basic sequential workflow on a private 2-worker grid
         const int routerPort = 9992;
         // create nodes
         using (var router = new GridSeqStep())
             using (var worker1 = new GridSeqStep())
                 using (var worker2 = new GridSeqStep())
                     using (var client = new GridSeqStep())
                     {
                         // start nodes
                         router.Initialise(context);
                         router.EnableGrid(GridLevel.Router, Guid.NewGuid(), routerPort, null);
                         worker1.Initialise(context);
                         worker1.EnableGrid(GridLevel.Worker, Guid.NewGuid(), routerPort, null);
                         worker2.Initialise(context);
                         worker2.EnableGrid(GridLevel.Worker, Guid.NewGuid(), routerPort, null);
                         client.Initialise(context);
                         client.EnableGrid(GridLevel.Client, Guid.NewGuid(), routerPort, null);
                         // execute
                         {
                             WorkflowOutput <GridData2> output = client.Execute(new GridData1 {
                                 S = "4.0"
                             });
                             // should return sqrt(1/4.0) = 0.5
                             Assert.AreEqual(0.5, output.Result.D);
                             Assert.IsNotNull(output.Errors);
                             Assert.AreEqual(0, output.Errors.Length);
                         }
                         // and again
                         {
                             WorkflowOutput <GridData2> output = client.Execute(new GridData1 {
                                 S = "16.0"
                             });
                             // should return sqrt(1/16.0) = 0.25
                             Assert.AreEqual(0.25, output.Result.D);
                             Assert.IsNotNull(output.Errors);
                             Assert.AreEqual(0, output.Errors.Length);
                         }
                     }
     }
 }