public async Task Decision_pipeline_one_input_different_outputs() { var result = string.Empty; var head = new HeadBlock <string>(); var positive = new HeadBlock <string>(); var negative = new HeadBlock <string>(); head.Process((ct, str, md) => Task.FromResult(str + "A")) .Decision((ct, str, md) => Task.FromResult(str == "AA"), positive, negative); positive .Process((ct, str, md) => Task.FromResult(str + "B")) .Action((ct, str, md) => Task.FromResult(result = str)); negative .Process((ct, str, md) => Task.FromResult(str + "C")) .Action((ct, str, md) => Task.FromResult(result = str)); var cts = new CancellationTokenSource(); await head.PushAsync(cts.Token, "A", new PipelineMetadata()).ConfigureAwait(false); result.Should().Be("AAB"); await head.PushAsync(cts.Token, "B", new PipelineMetadata()).ConfigureAwait(false); result.Should().Be("BAC"); }
public async Task Batch_pipeline_one_input_accumulate_to_one_output() { var result = new List <string>(); var head = new HeadBlock <string>(); head.Process((ct, str, md) => Task.FromResult(str + "A")) .Batch(3) .Process((ct, str, md) => Task.FromResult(string.Join(",", str))) .Action((ct, str, md) => { result.Add(str); return(Task.CompletedTask); }); var cts = new CancellationTokenSource(); await head.PushAsync(cts.Token, "C", new PipelineMetadata()).ConfigureAwait(false); await head.PushAsync(cts.Token, "C", new PipelineMetadata()).ConfigureAwait(false); await head.PushAsync(cts.Token, "C", new PipelineMetadata()).ConfigureAwait(false); // this one will be lost because of the batching await head.PushAsync(cts.Token, "C", new PipelineMetadata()).ConfigureAwait(false); await head.FlushAsync(cts.Token).ConfigureAwait(false); result.Count.Should().Be(2); result[0].Should().Be("CA,CA,CA"); result[1].Should().Be("CA"); }
public async Task Distribute_pipeline_one_input_two_outputs() { var result1 = string.Empty; var result2 = string.Empty; var head = new HeadBlock <string>(); var branch1 = new HeadBlock <string>(); var branch2 = new HeadBlock <string>(); head.Process((ct, str, md) => Task.FromResult(str + "A")) .Process((ct, str, md) => Task.FromResult(str + "-")) .Distribute(branch1, branch2); branch1 .Process((ct, str, md) => Task.FromResult(str + "B")) .Action((ct, str, md) => Task.FromResult(result1 = str)); branch2 .Process((ct, str, md) => Task.FromResult(str + "C")) .Action((ct, str, md) => Task.FromResult(result2 = str)); var cts = new CancellationTokenSource(); await head.PushAsync(cts.Token, string.Empty, new PipelineMetadata()).ConfigureAwait(false); result1.Should().Be("A-B"); result2.Should().Be("A-C"); }
public async Task Head_with_only_pipeline_should_execute_all_blocks() { var result = string.Empty; var head = new HeadBlock <string>(); head.Process((ct, str, md) => Task.FromResult(str + "A")) .Process((ct, str, md) => Task.FromResult(str + "B")) .Process((ct, str, md) => Task.FromResult(str + "C")) .Action((ct, str, md) => Task.FromResult(result = str)); var cts = new CancellationTokenSource().Token; await head.PushAsync(cts, string.Empty, new PipelineMetadata()).ConfigureAwait(false); result.Should().Be("ABC"); }
public async Task Decision_pipeline_has_only_negative_branch() { var result = string.Empty; var head = new HeadBlock <string>(); var negative = new HeadBlock <string>(); head.Process((ct, str, md) => Task.FromResult(str + "A")) .Decision((ct, str, md) => Task.FromResult(str == "A-"), null, negative); negative .Process((ct, str, md) => Task.FromResult(str + "B")) .Action((ct, str, md) => Task.FromResult(result = str)); var cts = new CancellationTokenSource(); await head.PushAsync(cts.Token, "A", new PipelineMetadata()); result.Should().Be("AAB"); }