public void item_start_and_end_is_reported(ResolverType resolverType) { // Arrange ItemStartedEvent?startedEvent = null; ItemEndedEvent? endedEvent = null; var events = new PipelineExecutionEvents(); events.ItemStarted += x => startedEvent = x; events.ItemEnded += x => endedEvent = x; var item = 1; var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { item }, new List <PipelineBlock <int> >())); // Act task.Execute(resolverType, events: events); // Assert startedEvent.Should().NotBeNull(); startedEvent.Value.ItemNumber.Should().Be(1); startedEvent.Value.Item.Should().Be(item); startedEvent.Value.MaterializationDuration.Should().BePositive(); endedEvent.Should().NotBeNull(); endedEvent.Value.ItemNumber.Should().Be(1); endedEvent.Value.Item.Should().Be(item); endedEvent.Value.Duration.Should().BePositive(); }
public void block_start_and_end_is_reported(ResolverType resolverType) { // Arrange BlockStartedEvent?startedEvent = null; BlockEndedEvent? endedEvent = null; var events = new PipelineExecutionEvents(); events.BlockStarted += x => startedEvent = x; events.BlockEnded += x => endedEvent = x; var block = new PipelineBlock <int>( "Block", x => { }); var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { 0 }, new List <PipelineBlock <int> > { block })); // Act task.Execute(resolverType, events: events); // Assert startedEvent.Should().NotBeNull(); startedEvent.Value.Block.Should().BeSameAs(block); endedEvent.Should().NotBeNull(); endedEvent.Value.Block.Should().BeSameAs(block); endedEvent.Value.Duration.Should().BePositive(); }
public void test(ResolverType resolverType) { // Arrange var initialized = false; var sum = 0; var completed = false; var task = new TaskDefinition( new BasicTaskStep( "Initialize", () => { initialized = true; }), PipelineTaskStep .Builder <int>("Pipeline") .WithInput(new[] { 1, 2, 3, 4, 5, 6 }) .WithBlock("Sum", x => sum += x) .WithBlock("Log", x => _output.WriteLine(x.ToString())) .Build(), new BasicTaskStep( "Complete", () => { completed = true; })); var progress = new SynchronousProgress <TaskProgress>(x => _output.WriteLine($"{x.StepName}: {x.ProgressPercentage}%")); var cancellationSource = new CancellationTokenSource(); var taskEvents = new TaskExecutionEvents( taskStarted: x => _output.WriteLine("Task 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.")); var pipelineEvents = new PipelineExecutionEvents( itemStarted: x => _output.WriteLine($"Item {x.ItemNumber} of step '{x.Step.Name}' started."), 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 = task.Execute(resolverType, progress, cancellationSource, taskEvents, pipelineEvents); // Assert result.Outcome.Should().Be(TaskOutcome.Successful); initialized.Should().Be(true); sum.Should().Be(21); completed.Should().Be(true); }
public void pipeline_end_is_reported(ResolverType resolverType) { // Arrange PipelineEndedEvent?endedEvent = null; var events = new PipelineExecutionEvents(); events.PipelineEnded += x => endedEvent = x; var block1 = new PipelineBlock <int>( "Block1", x => { }); var block2 = new PipelineBlock <int>( "Block1", x => { }); var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { 0 }, 1, new List <PipelineBlock <int> > { block1, block2 })); // Act task.Execute(resolverType, events: events); // Assert endedEvent.Should().NotBeNull(); endedEvent.Value.Step.Should().BeSameAs(task.Steps[0]); endedEvent.Value.TotalInputMaterializationDuration.Should().BePositive(); endedEvent.Value.TotalBlockDurations.Should().NotBeNull(); var totalBlockDurations = endedEvent.Value.TotalBlockDurations.ToDictionary(x => x.Key, x => x.Value); totalBlockDurations.Should().ContainKey(block1.Name).WhichValue.Should().BePositive(); totalBlockDurations.Should().ContainKey(block2.Name).WhichValue.Should().BePositive(); }