public void IdleTimeoutBidi_must_be_able_to_signal_timeout_once_no_traffic_on_either_sides() { this.AssertAllStagesStopped(() => { var upWrite = this.CreatePublisherProbe <string>(); var upRead = this.CreateSubscriberProbe <int>(); var downWrite = this.CreatePublisherProbe <int>(); var downRead = this.CreateSubscriberProbe <string>(); RunnableGraph.FromGraph(GraphDsl.Create(b => { var timeoutStage = b.Add(BidiFlow.BidirectionalIdleTimeout <string, int>(TimeSpan.FromSeconds(2))); b.From(Source.FromPublisher(upWrite)).To(timeoutStage.Inlet1); b.From(timeoutStage.Outlet1).To(Sink.FromSubscriber(downRead)); b.From(timeoutStage.Outlet2).To(Sink.FromSubscriber(upRead)); b.From(Source.FromPublisher(downWrite)).To(timeoutStage.Inlet2); return(ClosedShape.Instance); })).Run(Materializer); // Request enough for the whole test upRead.Request(100); downRead.Request(100); upWrite.SendNext("DATA1"); downRead.ExpectNext("DATA1"); Thread.Sleep(1500); downWrite.SendNext(1); upRead.ExpectNext(1); Thread.Sleep(1500); upWrite.SendNext("DATA2"); downRead.ExpectNext("DATA2"); Thread.Sleep(1000); downWrite.SendNext(2); upRead.ExpectNext(2); upRead.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); var error1 = upRead.ExpectError(); var error2 = downRead.ExpectError(); error1.Should().BeOfType <TimeoutException>(); error1.Message.Should().Be($"No elements passed in the last {TimeSpan.FromSeconds(2)}."); error2.ShouldBeEquivalentTo(error1); upWrite.ExpectCancellation(); downWrite.ExpectCancellation(); }, Materializer); }
public void ActorPublisher_should_work_in_a_GraphDsl() { var materializer = Sys.Materializer(); var probe1 = CreateTestProbe(); var probe2 = CreateTestProbe(); var senderRef1 = ActorOf(Sender.Props); var source1 = Source.FromPublisher(ActorPublisher.Create <int>(senderRef1)) .MapMaterializedValue(_ => senderRef1); var sink1 = Sink.FromSubscriber(ActorSubscriber.Create <string>(ActorOf(Receiver.Props(probe1.Ref)))) .MapMaterializedValue(_ => probe1.Ref); var sink2 = Sink.ActorSubscriber <string>(Receiver.Props(probe2.Ref)) .MapMaterializedValue(_ => probe2.Ref); var senderRef2 = RunnableGraph.FromGraph(GraphDsl.Create( Source.ActorPublisher <int>(Sender.Props), (builder, source2) => { var merge = builder.Add(new Merge <int, int>(2)); var bcast = builder.Add(new Broadcast <string>(2)); builder.From(source1).To(merge.In(0)); builder.From(source2.Outlet).To(merge.In(1)); builder.From(merge.Out).Via(Flow.Create <int>().Select(i => i.ToString())).To(bcast.In); builder.From(bcast.Out(0)).Via(Flow.Create <string>().Select(s => s + "mark")).To(sink1); builder.From(bcast.Out(1)).To(sink2); return(ClosedShape.Instance); })).Run(materializer); // the scala test is wrong const int noOfMessages = 10; for (var i = 0; i < noOfMessages; i++) { senderRef1.Tell(i); senderRef2.Tell(i + noOfMessages); } var probe1Messages = new List <string>(noOfMessages * 2); var probe2Messages = new List <string>(noOfMessages * 2); for (var i = 0; i < noOfMessages * 2; i++) { probe1Messages.Add(probe1.ExpectMsg <string>()); probe2Messages.Add(probe2.ExpectMsg <string>()); } probe1Messages.Should().BeEquivalentTo(Enumerable.Range(0, noOfMessages * 2).Select(i => i + "mark")); probe2Messages.Should().BeEquivalentTo(Enumerable.Range(0, noOfMessages * 2).Select(i => i.ToString())); }
public void A_Graph_should_build_broadcast_merge() { RunnableGraph.FromGraph(GraphDsl.Create(b => { var merge = b.Add(new Merge <string>(2)); var broadcast = b.Add(new Broadcast <string>(2)); b.From(In1).Via(F1).Via(broadcast).Via(F2).Via(merge).Via(F3).To(Out1); b.From(broadcast).Via(F4).To(merge); return(ClosedShape.Instance); })).Run(Materializer); }
public void A_RunnableGraph_must_suitably_override_attribute_handling_methods() { var r = RunnableGraph.FromGraph(Source.Empty <int>().To(Sink.Ignore <int>())) .Async() .AddAttributes(Attributes.None) .Named("useless"); r.Module.Attributes.GetFirstAttribute <Attributes.Name>().Value.Should().Be("useless"); r.Module.Attributes.GetFirstAttribute <Attributes.AsyncBoundary>() .Should() .Be(Attributes.AsyncBoundary.Instance); }
public void Reverse_Arrows_in_the_GraphDsl_must_work_towards_FlowShape() { var task = RunnableGraph.FromGraph(GraphDsl.Create(Sink, (b, s) => { var f = b.Add(Flow.Create <int>()); b.To(s).From(f); b.From(Source).To(f); return(ClosedShape.Instance); })).Run(Materializer); task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue(); task.Result.ShouldAllBeEquivalentTo(new[] { 1, 2, 3 }); }
public void A_Graph_should_make_it_optional_to_specify_flows() { RunnableGraph.FromGraph(GraphDsl.Create(b => { var merge = b.Add(new Merge <string>(2)); var broadcast = b.Add(new Broadcast <string>(2)); b.From(In1).Via(merge).Via(broadcast).To(Out1); b.From(In2).To(merge); b.From(broadcast).To(Out2); return(ClosedShape.Instance); })).Run(Materializer); }
private void GenerateReportAsync(OpenLogFileViewModel viewModel) { logFileRptGeneratorService.InitializeReport(); viewModel.OverallProgress = 0; viewModel.IsGeneratingReport = true; //var sourceQueue = Source.Queue<LogRptDto>(int.MaxValue, OverflowStrategy.Fail) // .SelectAsyncUnordered(int.MaxValue, l => logFileRptGeneratorService.GetCheckInforInUseOuts(l, viewModel.LogFiles)) // .To(Sink.ActorRef<Tuple<bool, LogRptDto>>(logFilesExcelProviderActor, logFileRptGeneratorService.GetReportRows())) // .Run(Context.Materializer()); var g = RunnableGraph.FromGraph(GraphDsl.Create(b => { var source = Source.From(viewModel.LogFiles); var sink = Sink.ActorRef <Tuple <bool, LogRptDto> >(logFilesExcelProviderActor, logFileRptGeneratorService.GetReportRows()); var parsing = Flow.Create <LogFile>() .Select(x => { viewModel.OverallProgress++; var parseTask = logFilesParsingService.ParseLogFileEventsAsync(x); parseTask.ContinueWith(t => denialsRptGeneratorService.Aggregate(t.Result)); return(parseTask.Result); }).WatchTermination((_, o) => { o.ContinueWith(t => getCheckInsActor.Tell(viewModel)); return(_); }); //.WatchTermination((_,u)=>u.PipeTo(getCheckInsActor)); //TODO: create new actor to run getCheckIns ===^ //Akka.Done //Akka.Actor.Status.Failure; var reportGen = Flow.Create <LogFile>() .SelectAsyncUnordered(int.MaxValue, logFileRptGeneratorService.GenerateReport) .Recover(exception => { throw exception; }) .SelectMany(x => x); //var getCheckIns = Flow.Create<LogRptDto>() // .SelectAsyncUnordered(int.MaxValue, x => getCheckInsActor.Tell(x)) //var getCheckIns = Flow.Create<LogRptDto>() // .SelectAsyncUnordered(int.MaxValue, l => logFileRptGeneratorService.GetCheckInforInUseOuts(l, viewModel.LogFiles)); b.From(source).Via(parsing).Via(reportGen).To(Sink.ForEach <LogRptDto>(l => getCheckInsActor.Tell(l)));//.Via(getCheckIns).To(sink); return(ClosedShape.Instance); })); g.Run(Context.Materializer()); }
public void Reverse_Arrows_in_the_GraphDsl_must_work_towards_UniformFanOutShape() { var task = RunnableGraph.FromGraph(GraphDsl.Create(Sink, (b, s) => { var f = b.Add(new Broadcast <int>(2)); b.To(s).From(f); b.To(Streams.Dsl.Sink.Ignore <int>().MapMaterializedValue(_ => MaterializedValue)).From(f); b.From(Source).To(f); return(ClosedShape.Instance); })).Run(Materializer); task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue(); task.Result.ShouldAllBeEquivalentTo(new[] { 1, 2, 3 }); }
private static void Example2(ActorMaterializer materializer) { var graph = RunnableGraph.FromGraph(GraphDsl.Create(b => { var source = b.Add(Source.Single(new Uri("http://getakka.net/"))); var sink = b.Add(Sink.ForEach <Uri>(Console.WriteLine)); var crawlerFlow = b.Add(WebCrawler()); b.From(source).Via(crawlerFlow).To(sink); return(ClosedShape.Instance); })); graph.Run(materializer); }
private static void Main(string[] args) { var source0 = Source.ActorPublisher <User>(ApiActorPublisher <User> .Props(@"http://*****:*****@"http://localhost:5000/api/properties")) .Select(x => new UserTuple(null, x, null)); var source2 = Source.ActorPublisher <UserAuthTypes>( ApiActorPublisher <UserAuthTypes> .Props(@"http://localhost:5000/api/auth")) .Select(x => new UserTuple(null, null, x)); var graph = RunnableGraph.FromGraph(GraphDsl.Create(b => { var merge = b.Add(new Merge <UserTuple>(3)); var s0 = b.Add(source0); var s1 = b.Add(source1); var s2 = b.Add(source2); var throttling = Flow.Create <Account>() .Throttle(1, TimeSpan.FromMilliseconds(500), 1, ThrottleMode.Shaping); var acc = Flow.Create <UserTuple>() .Via(new KeyAccumulator <UserTuple, int?, Account>( keySelector: x => x.Id(), flushWhen: buffer => buffer.IsReady(), mapper: buffer => buffer.Map())); var sink = b.Add(Sink.ForEach <Account>(Console.WriteLine)); b.From(s0).To(merge.In(0)); b.From(s1).To(merge.In(1)); b.From(s2).To(merge.In(2)); b.From(merge.Out).Via(acc).Via(throttling).To(sink); return(ClosedShape.Instance); })); using (var system = ActorSystem.Create("system")) using (var materializer = system.Materializer()) { graph.Run(materializer); Console.ReadLine(); } }
protected override TestSubscriber.Probe <TOutputs> Setup(IPublisher <int> p1, IPublisher <int> p2) { var subscriber = this.CreateSubscriberProbe <TOutputs>(); RunnableGraph.FromGraph(GraphDsl.Create(b => { var f = CreateFixture(b); b.From(Source.FromPublisher(p1)).To(f.Left); b.From(Source.FromPublisher(p2)).To(f.Right); b.From(f.Out).To(Sink.FromSubscriber(subscriber)); return(ClosedShape.Instance); })).Run(Materializer); return(subscriber); }
private IRunnableGraph <Tuple <NotUsed, NotUsed, NotUsed> > ThreeSourceMerge <T>(Source <T, NotUsed> source1, Source <T, NotUsed> source2, Source <T, NotUsed> source3, List <int> priorities, TestSubscriber.ManualProbe <T> probe) { return(RunnableGraph.FromGraph(GraphDsl.Create(source1, source2, source3, Tuple.Create, (builder, s1, s2, s3) => { var merge = builder.Add(new MergePrioritized <T>(priorities)); builder.From(s1.Outlet).To(merge.In(0)); builder.From(s2.Outlet).To(merge.In(1)); builder.From(s3.Outlet).To(merge.In(2)); builder.From(merge.Out).To(Sink.FromSubscriber(probe)); return ClosedShape.Instance; }))); }
public void Reverse_Arrows_in_the_GraphDsl_must_work_from_Sink() { var sub = this.CreateManualSubscriberProbe <int>(); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.To(Streams.Dsl.Sink.FromSubscriber(sub)) .From(Streams.Dsl.Source.From(Enumerable.Range(1, 3))); return(ClosedShape.Instance); })).Run(Materializer); sub.ExpectSubscription().Request(10); sub.ExpectNext(1, 2, 3); sub.ExpectComplete(); }
public static IRunnableGraph <NotUsed> GraphWithImportedFlowBuilder(int numberOfFlows) { return(RunnableGraph.FromGraph(GraphDsl.Create(Source.Single(NotUsed.Instance), (b, s) => { var flow = Flow.Create <NotUsed>().Select(x => x); var outlet = s.Outlet; for (var i = 0; i < numberOfFlows; i++) { var flowShape = b.Add(flow); b.From(outlet).To(flowShape); outlet = flowShape.Outlet; } b.From(outlet).To(Sink.Ignore <NotUsed>().MapMaterializedValue(_ => NotUsed.Instance)); return ClosedShape.Instance; }))); }
public void ExactSampleFiveStreamMerge() { using (var mat = Sys.Materializer()) { var probe = CreateTestProbe(); var graph = RunnableGraph.FromGraph( GraphDsl.Create(builder => { var sources = Enumerable.Range(0, 5).Select(x => Source.From( Enumerable.Range(0, 100) .Select(y => Mock.Of <ISyncData>(m => m.TimeStamp == 100 * y && m.SampleIndex == y )))).ToArray(); var merger = builder.Add(new MergeClosestN <ISyncData>(5)); var sink = Sink.ActorRef <IImmutableList <ISyncData> >(probe, "completed"); for (int i = 0; i < 5; i++) { builder.From(sources[i]).To(merger.In(i)); } builder.From(merger.Out).To(sink); return(ClosedShape.Instance); })); graph.Run(mat); var msgs = probe.ReceiveN(99, TimeSpan.FromSeconds(Debugger.IsAttached ? 300 : 3)); msgs.Should().AllBeAssignableTo(typeof(IImmutableList <ISyncData>)); var arrays = msgs.Cast <IImmutableList <ISyncData> >().ToList(); var timestamps = arrays.Select(x => x.Select(y => y.TimeStamp).ToArray()).ToList(); timestamps.Should().BeEquivalentTo( Enumerable.Range(0, 99).Select(x => Enumerable.Range(0, 5).Select(y => x * 100).ToArray())); var sampleIndices = arrays.Select(x => x.Select(y => y.SampleIndex).ToArray()).ToList(); sampleIndices.Should().BeEquivalentTo( Enumerable.Range(0, 99).Select(x => Enumerable.Range(0, 5).Select(y => x).ToArray())); } }
public void Conflate_must_restart_when_seed_throws_and_a_RestartDescider_is_used() { var sourceProbe = this.CreatePublisherProbe <int>(); var sinkProbe = this.CreateManualSubscriberProbe <int>(); var exceptionlath = new TestLatch(); var graph = Source.FromPublisher(sourceProbe).ConflateWithSeed(i => { if (i % 2 == 0) { exceptionlath.Open(); throw new TestException("I hate even seed numbers"); } return(i); }, (sum, i) => sum + i) .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider)) .To(Sink.FromSubscriber(sinkProbe)) .WithAttributes(Attributes.CreateInputBuffer(1, 1)); RunnableGraph.FromGraph(graph).Run(Materializer); var sub = sourceProbe.ExpectSubscription(); var sinkSub = sinkProbe.ExpectSubscription(); // push the first value sub.ExpectRequest(1); sub.SendNext(1); // and consume it, so that the next element // will trigger seed sinkSub.Request(1); sinkProbe.ExpectNext(1); sub.ExpectRequest(1); sub.SendNext(2); // make sure the seed exception happened // before going any further exceptionlath.Ready(TimeSpan.FromSeconds(3)); sub.ExpectRequest(1); sub.SendNext(3); // now we should have lost the 2 and the accumulated state sinkSub.Request(1); sinkProbe.ExpectNext(3); }
public void PrimaryTwiceRateOfSecondary() { using (var mat = Sys.Materializer()) { var probe = CreateTestProbe(); var graph = RunnableGraph.FromGraph( GraphDsl.Create(builder => { var primary = Source.From( Enumerable.Range(0, 200) .Select(y => Mock.Of <ISyncData>(x => x.TimeStamp == 50 * y && x.SampleIndex == y ))); var secondary = Source.From( Enumerable.Range(0, 100) .Select(y => Mock.Of <ISyncData>(x => x.TimeStamp == 100 * y && x.SampleIndex == y ))); var merger = builder.Add(new MergeClosestN <ISyncData>(2)); var sink = Sink.ActorRef <IImmutableList <ISyncData> >(probe, "completed"); builder.From(primary).To(merger.In(0)); builder.From(secondary).To(merger.In(1)); builder.From(merger.Out).To(sink); return(ClosedShape.Instance); })); graph.Run(mat); var msgs = probe.ReceiveN(97, TimeSpan.FromSeconds(Debugger.IsAttached ? 300 : 3)); msgs.Should().AllBeAssignableTo(typeof(IImmutableList <ISyncData>)); var arrays = msgs.Cast <IImmutableList <ISyncData> >().ToList(); var timestamps = arrays.Select(x => x.Select(y => y.TimeStamp).ToArray()).ToList(); timestamps.Should().BeEquivalentTo(Enumerable.Range(0, 97).Select(x => new[] { x * 100, x * 100 })); var sampleIndices = arrays.Select(x => x.Select(y => y.SampleIndex).ToArray()).ToList(); sampleIndices.Should().BeEquivalentTo(Enumerable.Range(0, 97).Select(x => new[] { 2 * x, x })); } }
public void A_Unzip_must_unzip_to_two_subscribers() { this.AssertAllStagesStopped(() => { var c1 = this.CreateManualSubscriberProbe <int>(); var c2 = this.CreateManualSubscriberProbe <string>(); RunnableGraph.FromGraph(GraphDsl.Create(b => { var unzip = b.Add(new UnZip <int, string>()); var source = Source.From(new[] { new KeyValuePair <int, string>(1, "a"), new KeyValuePair <int, string>(2, "b"), new KeyValuePair <int, string>(3, "c") }); b.From(source).To(unzip.In); b.From(unzip.Out0) .Via(Flow.Create <int>().Buffer(16, OverflowStrategy.Backpressure).Select(x => x * 2)) .To(Sink.FromSubscriber(c1)); b.From(unzip.Out1) .Via(Flow.Create <string>().Buffer(16, OverflowStrategy.Backpressure)) .To(Sink.FromSubscriber(c2)); return(ClosedShape.Instance); })).Run(Materializer); var sub1 = c1.ExpectSubscription(); var sub2 = c2.ExpectSubscription(); sub1.Request(1); sub2.Request(2); c1.ExpectNext(1 * 2); c1.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); c2.ExpectNext("a", "b"); c2.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); sub1.Request(3); c1.ExpectNext(2 * 2, 3 * 2); c1.ExpectComplete(); sub2.Request(3); c2.ExpectNext("c"); c2.ExpectComplete(); }, Materializer); }
public void GraphDSLs_must_be_able_to_run_plain_flow() { var p = Source.From(Enumerable.Range(1, 3)).RunWith(Sink.AsPublisher <int>(false), Materializer); var s = this.CreateManualSubscriberProbe <int>(); var flow = Flow.Create <int>().Select(x => x * 2); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(Source.FromPublisher(p)).Via(flow).To(Sink.FromSubscriber(s)); return(ClosedShape.Instance); })).Run(Materializer); var sub = s.ExpectSubscription(); sub.Request(10); s.ExpectNext(1 * 2, 2 * 2, 3 * 2).ExpectComplete(); }
public void A_Balance_must_support_waiting_for_demand_from_all_non_cancelled_downstream_subscriptions() { this.AssertAllStagesStopped(() => { var s1 = this.CreateManualSubscriberProbe <int>(); var t = RunnableGraph.FromGraph(GraphDsl.Create(Sink.AsPublisher <int>(false), Sink.AsPublisher <int>(false), Keep.Both, (b, p2Sink, p3Sink) => { var balance = b.Add(new Balance <int>(3, true)); var source = Source.From(Enumerable.Range(1, 3)) .MapMaterializedValue <Tuple <IPublisher <int>, IPublisher <int> > >(_ => null); b.From(source).To(balance.In); b.From(balance.Out(0)) .To( Sink.FromSubscriber(s1) .MapMaterializedValue <Tuple <IPublisher <int>, IPublisher <int> > >(_ => null)); b.From(balance.Out(1)).To(p2Sink); b.From(balance.Out(2)).To(p3Sink); return(ClosedShape.Instance); })).Run(Materializer); var p2 = t.Item1; var p3 = t.Item2; var sub1 = s1.ExpectSubscription(); sub1.Request(1); var s2 = this.CreateManualSubscriberProbe <int>(); p2.Subscribe(s2); var sub2 = s2.ExpectSubscription(); var s3 = this.CreateManualSubscriberProbe <int>(); p3.Subscribe(s3); var sub3 = s3.ExpectSubscription(); sub2.Request(2); s1.ExpectNoMsg(TimeSpan.FromMilliseconds(200)); sub3.Cancel(); s1.ExpectNext(1); s2.ExpectNext(2, 3); s1.ExpectComplete(); s2.ExpectComplete(); }, Materializer); }
public static IRunnableGraph <NotUsed> GraphWithNestedImportsBuilder(int numberOfNestedGraphs) { var flow = Flow.Create <NotUsed>().Select(x => x); for (var i = 0; i < numberOfNestedGraphs; i++) { flow = Flow.FromGraph(GraphDsl.Create(flow, (b, f) => new FlowShape <NotUsed, NotUsed>(f.Inlet, f.Outlet))); } return(RunnableGraph.FromGraph(GraphDsl.Create(flow, (b, f) => { b.From(Source.Single(NotUsed.Instance)) .Via(f) .To(Sink.Ignore <NotUsed>().MapMaterializedValue(_ => NotUsed.Instance)); return ClosedShape.Instance; }))); }
public void FlowGraphs_when_turned_into_flows_should_be_reusable_multiple_times() { var probe = TestSubscriber.CreateManualProbe <int>(this); var flow = Flow.FromGraph(GraphDsl.Create(Flow.Create <int>().Select(x => x * 2), (b, importFlow) => new FlowShape <int, int>(importFlow.Inlet, importFlow.Outlet))); RunnableGraph.FromGraph(GraphDsl.Create(b => { var source = Source.From(Enumerable.Range(1, 5)); b.From(source).Via(flow).Via(flow).To(Sink.FromSubscriber(probe)); return(ClosedShape.Instance); })).Run(Materializer); ValidateProbe(probe, 5, new[] { 4, 8, 12, 16, 20 }); }
private Tuple <TestSubscriber.ManualProbe <int>, TestSubscriber.ManualProbe <string> > Setup(IPublisher <int> p) { var leftSubscriber = this.CreateManualSubscriberProbe <int>(); var rightSubscriber = this.CreateManualSubscriberProbe <string>(); RunnableGraph.FromGraph(GraphDsl.Create(b => { var f = new UnzipWithFixture(b); b.From(Source.FromPublisher(p)).To(f.In); b.From(f.Left).To(Sink.FromSubscriber(leftSubscriber)); b.From(f.Right).To(Sink.FromSubscriber(rightSubscriber)); return(ClosedShape.Instance); })).Run(Materializer); return(Tuple.Create(leftSubscriber, rightSubscriber)); }
public void UnzipWith_must_work_in_the_sad_case() { this.AssertAllStagesStopped(() => { var leftProbe = this.CreateManualSubscriberProbe <int>(); var rightProbe = this.CreateManualSubscriberProbe <string>(); RunnableGraph.FromGraph(GraphDsl.Create(b => { var unzip = b.Add(new UnzipWith <int, int, string>(i => Tuple.Create(1 / i, 1 + "/" + i))); var source = Source.From(Enumerable.Range(-2, 5)); b.From(source).To(unzip.In); b.From(unzip.Out0).To(Sink.FromSubscriber(leftProbe)); b.From(unzip.Out1).To(Sink.FromSubscriber(rightProbe)); return(ClosedShape.Instance); })).Run(Materializer); var leftSubscription = leftProbe.ExpectSubscription(); var rightSubscription = rightProbe.ExpectSubscription(); Action requestFromBoth = () => { leftSubscription.Request(1); rightSubscription.Request(1); }; requestFromBoth(); leftProbe.ExpectNext(1 / -2); rightProbe.ExpectNext("1/-2"); requestFromBoth(); leftProbe.ExpectNext(1 / -1); rightProbe.ExpectNext("1/-1"); EventFilter.Exception <DivideByZeroException>().ExpectOne(requestFromBoth); leftProbe.ExpectError().Should().BeOfType <DivideByZeroException>(); rightProbe.ExpectError().Should().BeOfType <DivideByZeroException>(); leftProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); rightProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); }, Materializer); }
public void A_Graph_should_build_with_variance() { RunnableGraph.FromGraph(GraphDsl.Create(b => { var merge = b.Add(new Merge <IFruit>(2)); var s1 = Source.FromEnumerator <IFruit>(Apples); var s2 = Source.FromEnumerator <Apple>(Apples); b.From(s1).Via(Flow.Create <IFruit>()).To(merge.In(0)); //b.From(s2).Via(Flow.Create<Apple>()).To(merge.In(1)); b.From(merge.Out) .Via(Flow.Create <IFruit>().Select(x => x)) .To(Sink.FromSubscriber(TestSubscriber.CreateManualProbe <IFruit>(this))); return(ClosedShape.Instance); })).Run(Materializer); }
public static IRunnableGraph <NotUsed> GraphWithJunctionsBuilder(int numberOfJunctions) { return(RunnableGraph.FromGraph(GraphDsl.Create(b => { var broadcast = b.Add(new Broadcast <NotUsed>(numberOfJunctions)); var outlet = broadcast.Out(0); for (var i = 1; i < numberOfJunctions; i++) { var merge = b.Add(new Merge <NotUsed>(2)); b.From(outlet).To(merge); b.From(broadcast.Out(i)).To(merge); outlet = merge.Out; } b.From(Source.Single(NotUsed.Instance)).To(broadcast); b.From(outlet).To(Sink.Ignore <NotUsed>().MapMaterializedValue(_ => NotUsed.Instance)); return ClosedShape.Instance; }))); }
public void A_Graph_should_build_with_plain_flow_without_junctions() { RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1).Via(F1).To(Out1); return(ClosedShape.Instance); })).Run(Materializer); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1).Via(F1).Via(F2).To(Out1); return(ClosedShape.Instance); })).Run(Materializer); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1.Via(F1)).Via(F2).To(Out1); return(ClosedShape.Instance); })).Run(Materializer); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1).To(Out1); return(ClosedShape.Instance); })).Run(Materializer); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1).To(F1.To(Out1)); return(ClosedShape.Instance); })).Run(Materializer); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1.Via(F1)).To(Out1); return(ClosedShape.Instance); })).Run(Materializer); RunnableGraph.FromGraph(GraphDsl.Create(b => { b.From(In1.Via(F1)).To(F2.To(Out1)); return(ClosedShape.Instance); })).Run(Materializer); }
public void A_Graph_should_distinguish_between_input_and_output_ports() { Action action = () => { RunnableGraph.FromGraph(GraphDsl.Create(builder => { var zip = builder.Add(new Zip <int, string>()); var unzip = builder.Add(new UnZip <int, string>()); var wrongOut = Sink.AsPublisher <Tuple <int, int> >(false).MapMaterializedValue(_ => NotUsed.Instance); var whatever = Sink.AsPublisher <object>(false).MapMaterializedValue(_ => NotUsed.Instance); builder.Invoking( b => ((dynamic)b).From(Source.From(new[] { 1, 2, 3 })).Via(((dynamic)zip).Left).To(wrongOut)) .ShouldThrow <RuntimeBinderException>(); builder.Invoking( b => ((dynamic)b).From(Source.From(new[] { "a", "b", "c" })).To(((dynamic)zip).Left)) .ShouldThrow <RuntimeBinderException>(); builder.Invoking( b => ((dynamic)b).From(Source.From(new[] { "a", "b", "c" })).To(zip.Out)) .ShouldThrow <RuntimeBinderException>(); builder.Invoking( b => ((dynamic)b).From(((dynamic)zip).Left).To(((dynamic)zip).Right)) .ShouldThrow <RuntimeBinderException>(); var source = Source.From(new[] { new KeyValuePair <int, string>(1, "a"), new KeyValuePair <int, string>(2, "b"), new KeyValuePair <int, string>(3, "c") }); builder.Invoking( b => ((dynamic)b).From(source).Via(unzip.In).To(whatever)) .ShouldThrow <RuntimeBinderException>(); return(ClosedShape.Instance); })); }; action.ShouldThrow <ArgumentException>(); }
public void A_Graph_should_express_complex_topologies_in_a_readable_way() { RunnableGraph.FromGraph(GraphDsl.Create(b => { var merge = b.Add(new Merge <string>(2)); var broadcast1 = b.Add(new Broadcast <string>(2)); var broadcast2 = b.Add(new Broadcast <string>(2)); var feedbackLoopBffer = Flow.Create <string>().Buffer(10, OverflowStrategy.DropBuffer); var i1 = b.Add(In1); var o1 = b.Add(Out1); var o2 = b.Add(Out2); b.From(i1).Via(F2).Via(merge).Via(F2).Via(broadcast1).Via(F3).To(o1); b.From(broadcast1).Via(feedbackLoopBffer).Via(broadcast2).Via(F5).To(merge); b.From(broadcast2).Via(F6).To(o2); return(ClosedShape.Instance); })).Run(Materializer); }
public void A_Graph_should_detect_cycle_in() { RunnableGraph.FromGraph(GraphDsl.Create(b => { var merge = b.Add(new Merge <string>(2)); var broadcast1 = b.Add(new Broadcast <string>(2)); var broadcast2 = b.Add(new Broadcast <string>(2)); var feedbackLoopBffer = Flow.Create <string>().Buffer(10, OverflowStrategy.DropBuffer); b.From(In1).Via(F1).To(merge.In(0)); b.From(merge).Via(F2).To(broadcast1); b.From(broadcast1.Out(0)).Via(F3).To(Out1); b.From(broadcast1.Out(1)).Via(feedbackLoopBffer).To(broadcast2); b.From(broadcast2.Out(0)).Via(F5).To(merge.In(1)); // cycle b.From(broadcast2.Out(1)).Via(F6).To(Out2); return(ClosedShape.Instance); })).Run(Materializer); }