示例#1
0
        public void reporter_creates_and_fills_execution_reports()
        {
            // Arrange
            var task = new TaskDefinition(
                BasicTaskStep.Empty("Basic"),
                new PipelineTaskStep <int>(
                    "Pipeline1",
                    new[] { 1 },
                    new List <PipelineBlock <int> >()),
                new PipelineTaskStep <int>(
                    "Pipeline2",
                    new[] { 1 },
                    new List <PipelineBlock <int> >()));

            var loggerEvents   = TaskExecutionLogger.CreateEvents();
            var reporterEvents = TaskExecutionReporter.CreateEvents();

            // Act
            task.Execute(events: loggerEvents.Concat(reporterEvents).ToArray());

            // Assert
            var reports = task.GetExecutionReports();

            reports.Should().NotBeNull().And.NotBeEmpty();
            reports.Should().Contain(x => x.Name == "charts.html");
            reports.Should().Contain(x => x.Name == "Pipeline1_charts.html");
            reports.Should().Contain(x => x.Name == "Pipeline2_charts.html");
            reports.Should().OnlyContain(x => x.Content.StartsWith("<html>"));
        }
示例#2
0
        public void step_ignored___report_still_generated()
        {
            // Arrange
            var task = new TaskDefinition(
                BasicTaskStep.Empty("Basic"),
                new BasicTaskStep(
                    "Ignored",
                    () => { },
                    x => false));

            var loggerEvents   = TaskExecutionLogger.CreateEvents();
            var reporterEvents = TaskExecutionReporter.CreateEvents();

            // Act
            task.Execute(events: loggerEvents.Concat(reporterEvents).ToArray());

            // Assert
            var reports = task.GetExecutionReports();

            reports.Should().NotBeNull().And.NotBeEmpty();
        }
示例#3
0
        //[InlineData(ResolverType.Sequential, @"c:\temp\Navvy_tests")]
        public void test(ResolverType resolverType, string reportsFolderPath = null)
        {
            // Arrange
            var initialized = false;
            var sum         = 0;
            var completed   = false;

            var executor = new TaskExecutorBuilder()
                           .RegisterPipelineExecution(resolverType)
                           .UseTaskExecutionLogger()
                           .UseTaskExecutionReporter(
                reportsFolderPath != null
                        ? x => reportsFolderPath
                        : (Func <TaskDefinition, string>)null)
                           .RegisterProgressHandler(x => _output.WriteLine($"{x.Step.Name}: {x.Progress * 100f}%"))
                           .Build();

            var task = new TaskDefinition(
                "TestTask",
                TaskStepBuilder.Build.Basic(
                    "Initialize",
                    () => { initialized = true; }),
                TaskStepBuilder.Build.Pipeline <int>(
                    "Pipeline")
                .WithInput(new[] { 1, 2, 3, 4, 5, 6 })
                .WithBlock("Sum", x => sum += x)
                .WithBlock("Log", x => _output.WriteLine(x.ToString()))
                .Build(),
                TaskStepBuilder.Build.Basic(
                    "Complete",
                    () => { completed = true; }));

            task.Extras.Set("Id", 1);

            var cancellationSource = new CancellationTokenSource();

            var events = new IExecutionEvents[]
            {
                new TaskExecutionEvents(
                    taskStarted: x => _output.WriteLine($"Task '{x.Task.Name}' (id: {x.Task.Extras.Get<int>("Id")}) started."),
                    taskEnded: x => _output.WriteLine($"Task ended after {x.Duration.Ticks} ticks."),
                    stepStarted: x => _output.WriteLine($"Step '{x.Step.Name}' started."),
                    stepEnded: x => _output.WriteLine($"Step '{x.Step.Name}' ended after {x.Duration.Ticks} ticks.")),
                new PipelineExecutionEvents(
                    itemMaterialized: x => _output.WriteLine($"Item {x.ItemNumber} of step '{x.Step.Name}' materialized."),
                    itemEnded: x => _output.WriteLine($"Item {x.ItemNumber} of step '{x.Step.Name}' ended after {x.Duration.Ticks} ticks."),
                    blockStarted: x => _output.WriteLine($"Block '{x.Block.Name}' of step '{x.Step.Name}' started processing item {x.ItemNumber}."),
                    blockEnded: x => _output.WriteLine($"Block '{x.Block.Name}' of step '{x.Step.Name}' ended processing item {x.ItemNumber} after {x.Duration.Ticks} ticks."))
            };

            // Act
            var result = executor.Execute(task, cancellationSource.Token, events);

            // Assert
            result.Outcome.Should().Be(TaskOutcome.Successful);
            initialized.Should().Be(true);
            sum.Should().Be(21);
            completed.Should().Be(true);
            task.GetExecutionLog().Should().NotBeNull();
            task.GetExecutionReports().Should().NotBeNull().And.NotBeEmpty();
        }