public void ExceptionShouldBeProcessedWithErrorProcessor() { // GIVEN var injectionProvider = new IoCContainer(); var step = new TestIntSource(new List <int> { 101 }); injectionProvider.RegisterSingle(step); JustConveyor.Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); // WHEN TransferingContext tctx = new TransferingContext(); new Pipeline(PipelineBlueprint.CreateBlueprint <int>("WithExceptionBlueprint") .Split <TestIntSource>() .Collect()) .Process(tctx, 1).Wait(); //// THAN tctx.Exception.Should().NotBeNull(); step.ExceptionMessage.Should().Be("More than 100."); tctx.FinalUnitContext.Should().BeNull(); }
public void SingleTaskWithActionsShouldWorksWell() { // GIVEN mLogs.Logs.Clear(); var injectionProvider = new IoCContainer(); injectionProvider.Register <TestMultiplicatorStep>(); Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "SingleApply"); PipelineBlueprint blueprintOther = PipelineBlueprint.CreateBlueprint(typeof(int), "DoubleApply"); // WHEN TransferingContext tctx = new TransferingContext(new Headers { { "factor", 10 } }.Dict); new Pipeline(blueprint .Apply <TestMultiplicatorStep>("multiplyby2") .Apply <TestMultiplicatorStep>("sync_mbf")) .Process(tctx, 1).Wait(); TransferingContext otherTctx = new TransferingContext(new Headers { { "factor", 10 } }.Dict); new Pipeline(blueprintOther .Apply <TestMultiplicatorStep>("sync_mbf") .Apply <TestMultiplicatorStep>("multiplyby2") .Apply <TestMultiplicatorStep>("sync_mbf")) .Process(otherTctx, 1).Wait(); // THAN tctx.GetResult <int>().Should().Be(20); otherTctx.GetResult <int>().Should().Be(200); }
public void SplitShouldWorksWell() { // GIVEN mLogs.Logs.Clear(); var intSource = new List <int> { 2, 4, 6 }; var injectionProvider = new IoCContainer(); injectionProvider.RegisterSingle(intSource); JustConveyor.Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider); var blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "IntMultiplicatorBlueprint") .Split <TestIntSource>() .Apply <TestMultiplicatorStep>("multiplybyfactor") .Collect() .Apply((List <UnitContext> unit) => unit.Select(el => el.GetUnit <int>()).ToList()); // WHEN Pipeline pipeline = new Pipeline(blueprint); TransferingContext tctx = new TransferingContext(new Headers { { "factor", 10 } }.Dict); pipeline.Process(tctx, 1).Wait(); List <int> result = tctx.GetResult <List <int> >(); // THAN result.ShouldBeEquivalentTo(new List <int> { 20, 40, 60 }); }
public PipelineDescriptor CreateIntMultPipeline() { var blueprint = PipelineBlueprint .CreateBlueprint <int>("TestIntMultPipeline") .Apply <TestMultiplicatorStep>("multiplyby2"); return(new PipelineDescriptor { Blueprint = blueprint, ConcurrentLinesNumber = 10 }); }
public PipelineDescriptor CurrenciesAnalyzerBlueprint() { var blueprint = PipelineBlueprint.CreateBlueprint <DatesDiapason>("AnalyzeCurrenciesRatesByDiapason") .Split <CurrenciesAnalizer>("generate-dates") .Apply <FixerIOCurrenciesFetcher>("date-rate") .CollectAndCast <double?>() .Apply <CurrenciesAnalizer>("analyze") .Apply <Finalizer>(); return(new PipelineDescriptor { Blueprint = blueprint, ConcurrentLinesNumber = 1, ForType = true }); }
public PipelineDescriptor CreatePipelineWithCallOfAnother() { var blueprint = PipelineBlueprint .CreateBlueprint <int>("TestPipelineWithCallOfAnother") .Split <TestIntSource>() .CallPipeline("TestIntMultPipeline") .Collect() .Apply((IList <UnitContext> ctx) => ctx.Select(el => el.GetUnit <int>()).ToList()) .Apply <ListCollector>(); return(new PipelineDescriptor { Blueprint = blueprint, ConcurrentLinesNumber = 70 }); }
public void IncorrectNumberOfSplitsAndCollectorsShouldThrowException() { // GIVEN mLogs.Logs.Clear(); var injectionProvider = new IoCContainer(); injectionProvider.RegisterSingle(new List <int>()); injectionProvider.Register <TestIntSource>(); Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); PipelineBlueprint blueprintNormal = PipelineBlueprint.CreateBlueprint(typeof(int), "Normal"); PipelineBlueprint blueprintOnlyCollect = PipelineBlueprint.CreateBlueprint(typeof(int), "OnlyCollect"); PipelineBlueprint blueprintOnlySplit = PipelineBlueprint.CreateBlueprint(typeof(int), "OnlySplit"); PipelineBlueprint blueprintSplitsMoreThanCollects = PipelineBlueprint.CreateBlueprint(typeof(int), "SplitsMoreThanCollects"); PipelineBlueprint blueprintCollectsMoreThanSplits = PipelineBlueprint.CreateBlueprint(typeof(int), "CollectsMoreThanSplits"); // WHEN Action createNormal = () => new Pipeline(blueprintNormal .Split <TestIntSource>() .Collect()); Action createOnlySplit = () => new Pipeline(blueprintOnlySplit .Split <TestIntSource>()); Action createOnlyCollect = () => new Pipeline(blueprintOnlyCollect .Collect()); Action createSplitsMoreThanCollects = () => new Pipeline(blueprintSplitsMoreThanCollects .Split <TestIntSource>() .Split <TestIntSource>() .Collect()); Action createCollectsMoreThanSplits = () => new Pipeline(blueprintCollectsMoreThanSplits .Split <TestIntSource>() .Collect() .Collect()); // THAN createNormal.ShouldNotThrow(); createOnlySplit.ShouldThrow <InvalidSplitCollectException>(); createOnlyCollect.ShouldThrow <InvalidSplitCollectException>(); createSplitsMoreThanCollects.ShouldThrow <InvalidSplitCollectException>(); createCollectsMoreThanSplits.ShouldThrow <InvalidSplitCollectException>(); }
public PipelineDescriptor CreateIntPipeline() { var blueprint = PipelineBlueprint .CreateBlueprint <int>("TestPipeline") .Split <TestIntSource>() .Apply <TestMultiplicatorStep>("multiplyby2") .Collect() .Apply((IList <UnitContext> ctx) => ctx.Select(el => el.GetUnit <int>()).ToList()) .Apply <ListCollector>(); return(new PipelineDescriptor { Blueprint = blueprint, ConcurrentLinesNumber = 70, ForType = true }); }
public void SingleTaskShouldWorksWell() { // GIVEN mLogs.Logs.Clear(); var injectionProvider = new IoCContainer(); injectionProvider.Register <TestMultiplicatorStep>(); Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "SingleApply"); // WHEN TransferingContext tctx = new TransferingContext(); new Pipeline(blueprint.Apply <TestMultiplicatorStep>("multiplyby2")) .Process(tctx, 1).Wait(); // THAN tctx.GetResult <int>().Should().Be(2); }
public void OnIncorrectParameterTypeExceptionShouldReturns() { // GIVEN mLogs.Logs.Clear(); var injectionProvider = new IoCContainer(); injectionProvider.Register <TestMultiplicatorStep>(); Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "SingleApply"); // WHEN TransferingContext tctx = new TransferingContext(); new Pipeline(blueprint .Apply((string str) => str)) .Process(tctx, 1).Wait(); // THAN tctx.Exception.Should().NotBeNull(); tctx.Exception.InnerException.Should().NotBeNull(); tctx.Exception.InnerException.GetType().Should().Be(typeof(ParameterTypeMissmatchException)); }
public void SyncSpitCollectShouldWorksWell() { // GIVEN mLogs.Logs.Clear(); var ints = new List <int> { 1, 2, 3 }; var injectionProvider = new IoCContainer(); injectionProvider.RegisterSingle(ints); injectionProvider.Register <TestIntSource>(); injectionProvider.Register <TestMultiplicatorStep>(); Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "SyncSplitCollect"); // WHEN var result = blueprint .Split <TestIntSource>() .Apply((int el) => el * 10) .Collect() .Apply((IList <UnitContext> octx) => octx.Select(el => el.GetUnit <int>())); TransferingContext tctx = new TransferingContext(); new Pipeline(result) .Process(tctx, 1) .Wait(); // THAN tctx.Exception.Should().BeNull(); tctx.GetResult <IEnumerable <int> >().ShouldBeEquivalentTo(new List <int> { 10, 20, 30 }); }
public PipelineDescriptor CreateIntMultPipeline() { var blueprint = PipelineBlueprint .CreateBlueprint <int>("TestIntMultPipeline") // Create bluprint with given name (name just for metrics display) .Apply((utx, tctx) => { tctx.Meta.Add("PROCESSING INT", utx.Unit.ToString()); return(utx.Unit); }, "SetMeta") .Apply <IntegersProcessor>("multiplyby2") .Apply((utx, tctx) => // Just for longer process time duration { Task.Delay(TimeSpan.FromSeconds(10)).Wait(); return(utx.Unit); }, name: "JustWaiting") .Apply <IntegersProcessor>("accumulate"); // Accumulate result in "collector" return(new PipelineDescriptor { Blueprint = blueprint, ConcurrentLinesNumber = 10, ForType = true }); }
public void AsyncSpitCollectShouldWorksWell() { // GIVEN mLogs.Logs.Clear(); var ints = new List <int> { 1, 2, 3 }; var injectionProvider = new IoCContainer(); injectionProvider.RegisterSingle(ints); injectionProvider.Register <TestIntSource>(); injectionProvider.Register <TestMultiplicatorStep>(); Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false); PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "AsyncSplitCollect"); PipelineBlueprint blueprintOther = PipelineBlueprint.CreateBlueprint(typeof(int), "OtherAsyncSplitCollect"); PipelineBlueprint blueprintOneOther = PipelineBlueprint.CreateBlueprint(typeof(int), "OneOtherAsyncSplitCollect"); // WHEN TransferingContext tctx = new TransferingContext(new Headers { { "factor", 10 } }.Dict); new Pipeline(blueprint .Split <TestIntSource>() .Apply <TestMultiplicatorStep>("multiplybyfactor") .Collect() .Apply((IList <UnitContext> octx) => octx.Select(el => el.GetUnit <int>()).ToList())) .Process(tctx, 1) .Wait(); TransferingContext otherTctx = new TransferingContext(new Headers { { "factor", 10 } }.Dict); new Pipeline(blueprintOther .Split <TestIntSource>() .Apply <TestMultiplicatorStep>("multiplybyfactor") .Collect() .Apply <TestMultiplicatorStep>("strip")) .Process(otherTctx, 1) .Wait(); TransferingContext oneAnotherTctx = new TransferingContext(new Headers { { "factor", 10 } }.Dict); new Pipeline(blueprintOneOther .Apply <TestMultiplicatorStep>("multiplybyfactor") .Split <TestIntSource>() .Apply <TestMultiplicatorStep>("multiplybyfactor") .Collect() .Apply <TestMultiplicatorStep>("strip")) .Process(oneAnotherTctx, 1) .Wait(); // THAN tctx.Exception?.InnerException.Should().BeNull(); tctx.GetResult <List <int> >().ShouldBeEquivalentTo(new List <int> { 10, 20, 30 }); otherTctx.Exception?.InnerException.Should().BeNull(); otherTctx.GetResult <List <int> >().ShouldBeEquivalentTo(new List <int> { 10, 20, 30 }); oneAnotherTctx.Exception?.InnerException.Should().BeNull(); oneAnotherTctx.GetResult <List <int> >().ShouldBeEquivalentTo(new List <int> { 10, 20, 30 }); }