public void ActorBackpressureSink_should_work_with_one_element_buffer() { this.AssertAllStagesStopped(() => { var fw = CreateActor <Fw2>(); var publisher = RunnableGraph.FromGraph( this.SourceProbe <int>() .To(Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage)) .WithAttributes(Attributes.CreateInputBuffer(1, 1))).Run(Materializer); ExpectMsg(InitMessage); fw.Tell(TriggerAckMessage.Instance); publisher.SendNext(1); ExpectMsg(1); fw.Tell(TriggerAckMessage.Instance); ExpectNoMsg(); // Ack received but buffer empty publisher.SendNext(2); // Buffer this value fw.Tell(TriggerAckMessage.Instance); ExpectMsg(2); publisher.SendComplete(); ExpectMsg(CompleteMessage); }, Materializer); }
public void ActorBackpressureSink_should_send_message_only_when_backpressure_received() { this.AssertAllStagesStopped(() => { var fw = CreateActor <Fw2>(); var publisher = this.SourceProbe <int>() .To(Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage)) .Run(Materializer); ExpectMsg(InitMessage); publisher.SendNext(1); ExpectNoMsg(); fw.Tell(TriggerAckMessage.Instance); ExpectMsg(1); publisher.SendNext(2); publisher.SendNext(3); publisher.SendComplete(); fw.Tell(TriggerAckMessage.Instance); ExpectMsg(2); fw.Tell(TriggerAckMessage.Instance); ExpectMsg(3); ExpectMsg(CompleteMessage); }, Materializer); }
public void ActorBackpressureSink_should_keep_on_sending_even_after_the_buffer_has_been_full() { this.AssertAllStagesStopped(() => { var bufferSize = 16; var streamElementCount = bufferSize + 4; var fw = CreateActor <Fw2>(); var sink = Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage) .WithAttributes(Attributes.CreateInputBuffer(bufferSize, bufferSize)); var probe = Source.From(Enumerable.Range(1, streamElementCount)) .AlsoToMaterialized( Flow.Create <int>().Take(bufferSize).WatchTermination(Keep.Right).To(Sink.Ignore <int>()), Keep.Right) .To(sink) .Run(Materializer); probe.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); probe.IsCompleted.Should().BeTrue(); ExpectMsg(InitMessage); fw.Tell(TriggerAckMessage.Instance); for (var i = 1; i <= streamElementCount; i++) { ExpectMsg(i); fw.Tell(TriggerAckMessage.Instance); } ExpectMsg(CompleteMessage); }, Materializer); }
public void ActorBackpressurSink_should_fail_to_materialize_with_zero_sized_input_buffer() { var fw = CreateActor <Fw>(); var badSink = Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage) .WithAttributes(Attributes.CreateInputBuffer(0, 0)); Source.Single(1).Invoking(s => s.RunWith(badSink, Materializer)).ShouldThrow <ArgumentException>(); }
public static Sink <SequencedFunctionTotalUsage, NotUsed> Create(IActorRefFactory system, string eventName) { var actorRef = system.ActorOf(Props.Create <FunctionsTotalUsageProjector>(eventName), nameof(FunctionsTotalUsageProjector)); return(Sink.ActorRefWithAck <SequencedFunctionTotalUsage>( actorRef, ProjectorActorProtocol.Start.Instance, ProjectorActorProtocol.Next.Instance, ProjectorActorProtocol.ProjectionDone.Instance)); }
public static Sink <FunctionAdded, NotUsed> Create(IActorRefFactory system, string eventName) { var actorRef = system.ActorOf(Props.Create <KnownFunctionsProjector>(eventName), nameof(KnownFunctionsProjector)); return(Sink.ActorRefWithAck <FunctionAdded>( actorRef, ProjectorActorProtocol.Start.Instance, ProjectorActorProtocol.Next.Instance, ProjectorActorProtocol.ProjectionDone.Instance)); }
public static Sink <Sequenced <CalculatorActor.CalculationPerformed>, NotUsed> Create(IActorRefFactory system, string eventName) { var actorRef = system.ActorOf(Props.Create <FunctionsUsageProjector>(eventName, null), nameof(FunctionsUsageProjector)); return(Sink.ActorRefWithAck <Sequenced <CalculatorActor.CalculationPerformed> >( actorRef, ProjectorActorProtocol.Start.Instance, ProjectorActorProtocol.Next.Instance, ProjectorActorProtocol.ProjectionDone.Instance)); }
public void ActorBackpressurSink_should_signal_failure_on_abrupt_termination() { var materializer = ActorMaterializer.Create(Sys); var probe = CreateTestProbe(); var sink = Sink.ActorRefWithAck <string>(probe.Ref, InitMessage, AckMessage, CompleteMessage) .WithAttributes(Attributes.CreateInputBuffer(1, 1)); Source.Maybe <string>().To(sink).Run(materializer); probe.ExpectMsg(InitMessage); materializer.Shutdown(); probe.ExpectMsg <Status.Failure>(); }
public void ActorBackpressureSink_should_send_the_elements_to_the_ActorRef() { this.AssertAllStagesStopped(() => { var fw = CreateActor <Fw>(); Source.From(Enumerable.Range(1, 3)) .RunWith(Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage), Materializer); ExpectMsg("start"); ExpectMsg(1); ExpectMsg(2); ExpectMsg(3); ExpectMsg(CompleteMessage); }, Materializer); }
public void ActorBackpressureSink_should_cancel_stream_when_actor_terminates() { this.AssertAllStagesStopped(() => { var fw = CreateActor <Fw>(); var publisher = this.SourceProbe <int>() .To(Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage)) .Run(Materializer); publisher.SendNext(1); ExpectMsg(InitMessage); ExpectMsg(1); Sys.Stop(fw); publisher.ExpectCancellation(); }, Materializer); }
public void ActorBackpressureSink_should_send_the_elements_to_the_ActorRef2() { this.AssertAllStagesStopped(() => { var fw = CreateActor <Fw>(); var probe = this.SourceProbe <int>() .To(Sink.ActorRefWithAck <int>(fw, InitMessage, AckMessage, CompleteMessage)) .Run(Materializer); probe.SendNext(1); ExpectMsg("start"); ExpectMsg(1); probe.SendNext(2); ExpectMsg(2); probe.SendNext(3); ExpectMsg(3); probe.SendComplete(); ExpectMsg(CompleteMessage); }, Materializer); }
public async Task RunnableGraphMadeOfBackpressuredQueueAndActorRefWithAckWorksAsExpected() { const int MAX = 4; Source <int, ISourceQueueWithComplete <int> > source = Source.Queue <int>(MAX, OverflowStrategy.Backpressure); TestProbe probe = CreateTestProbe(); Sink <IEnumerable <int>, NotUsed> sink = Sink.ActorRefWithAck <IEnumerable <int> >(probe.Ref, "init", "ack", "complete"); RunnableGraph <ISourceQueueWithComplete <int> > rg = RunnableGraph.FromGraph(GraphDsl.Create(source, sink, Keep.Left, (builder, source_, sink_) => { UniformFanOutShape <int, int> broadcaster = builder.Add(new Broadcast <int>(2)); UniformFanInShape <IEnumerable <int>, IEnumerable <int> > merger = builder.Add(new Merge <IEnumerable <int> >(2)); var f1 = Flow.Create <int>().Aggregate(new List <int>(), (agg, curr) => { agg.Add(curr); return(agg); }).Select(list => list.AsEnumerable()); var f2 = Flow.Create <int>().Aggregate(new List <int>(), (agg, curr) => { agg.Add(curr); return(agg); }).Select(list => list.AsEnumerable()); builder.From(source_).To(broadcaster.In); builder.From(broadcaster.Out(0)).Via(f1).To(merger.In(0)); builder.From(broadcaster.Out(1)).Via(f2).To(merger.In(1)); builder.From(merger.Out).To(sink_); return(ClosedShape.Instance); })); ISourceQueueWithComplete <int> q = rg.Run(_materializer); probe.ExpectMsg <string>((msg, sender) => { if (msg != "init") { throw new InvalidOperationException($"Expected: init. Found: {msg}"); } sender.Tell("ack"); }); await q.OfferAsync(2); await q.OfferAsync(4); await q.OfferAsync(8); await q.OfferAsync(16); q.Complete(); await q.WatchCompletionAsync(); probe.ExpectMsg <IEnumerable <int> >((msg, sender) => { Assert.Equal(new[] { 2, 4, 8, 16 }.AsEnumerable(), msg); sender.Tell("ack"); }); probe.ExpectMsg <IEnumerable <int> >((msg, sender) => { Assert.Equal(new[] { 2, 4, 8, 16 }.AsEnumerable(), msg); sender.Tell("ack"); }); probe.ExpectMsg("complete"); probe.ExpectNoMsg(); }