public void Zip_must_complete_if_one_side_complete_before_requested_with_elements_pending_2() { this.AssertAllStagesStopped(() => { var upstream1 = TestPublisher.CreateProbe <int>(this); var upstream2 = TestPublisher.CreateProbe <string>(this); var downstream = TestSubscriber.CreateProbe <Tuple <int, string> >(this); RunnableGraph.FromGraph(GraphDsl.Create(Sink.FromSubscriber(downstream), (b, sink) => { var zip = b.Add(new Zip <int, string>()); var source1 = Source.FromPublisher(upstream1); var source2 = Source.FromPublisher(upstream2); b.From(source1).To(zip.In0); b.From(source2).To(zip.In1); b.From(zip.Out).To(sink); return(ClosedShape.Instance); })).Run(Materializer); downstream.EnsureSubscription(); upstream1.SendNext(1); upstream1.SendComplete(); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); upstream2.SendNext("A"); upstream2.SendComplete(); downstream.RequestNext(Tuple.Create(1, "A")); downstream.ExpectComplete(); }, Materializer); }
public void Batch_must_backpressure_subscriber_when_upstream_is_slower() { var publisher = TestPublisher.CreateProbe <int>(this); var subscriber = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(publisher) .Batch(2, i => i, (sum, i) => sum + i) .To(Sink.FromSubscriber(subscriber)) .Run(Materializer); var sub = subscriber.EnsureSubscription(); sub.Request(1); publisher.SendNext(1); subscriber.ExpectNext(1); sub.Request(1); subscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); publisher.SendNext(2); subscriber.ExpectNext(2); publisher.SendNext(3); publisher.SendNext(4); // The request can be in race with the above onNext(4) so the result would be either 3 or 7. subscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); sub.Request(1); subscriber.ExpectNext(7); sub.Request(1); subscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); sub.Cancel(); }
public void PrefixAndTail_must_signal_error_if_substream_has_been_not_subscribed_in_time() { this.AssertAllStagesStopped(() => { var settings = ActorMaterializerSettings.Create(Sys) .WithSubscriptionTimeoutSettings( new StreamSubscriptionTimeoutSettings( StreamSubscriptionTimeoutTerminationMode.CancelTermination, TimeSpan.FromMilliseconds(500))); var tightTimeoutMaterializer = ActorMaterializer.Create(Sys, settings); var futureSink = NewHeadSink; var fut = Source.From(Enumerable.Range(1, 2)).PrefixAndTail(1).RunWith(futureSink, tightTimeoutMaterializer); fut.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); fut.Result.Item1.ShouldAllBeEquivalentTo(Enumerable.Range(1, 1)); var tail = fut.Result.Item2; var subscriber = TestSubscriber.CreateProbe <int>(this); Thread.Sleep(1000); tail.To(Sink.FromSubscriber(subscriber)).Run(tightTimeoutMaterializer); subscriber.ExpectSubscriptionAndError() .Message.Should() .Be("Substream Source has not been materialized in 00:00:00.5000000"); }, Materializer); }
public void Expand_musst_expand_elements_while_upstream_is_silent() { var publisher = TestPublisher.CreateProbe <int>(this); var subscriber = TestSubscriber.CreateProbe <int>(this); // Simply repeat the last element as an extrapolation step Source.FromPublisher(publisher) .Expand(i => Enumerable.Repeat(i, 200).GetEnumerator()) .To(Sink.FromSubscriber(subscriber)) .Run(Materializer); publisher.SendNext(42); for (var i = 1; i <= 100; i++) { subscriber.RequestNext(42); } publisher.SendNext(-42); // The request below is otherwise in race with the above sendNext subscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); subscriber.RequestNext(-42); subscriber.Cancel(); }
public void Zip_must_complete_even_if_no_pending_demand() { this.AssertAllStagesStopped(() => { var upstream1 = TestPublisher.CreateProbe <int>(this); var upstream2 = TestPublisher.CreateProbe <string>(this); var downstream = TestSubscriber.CreateProbe <Tuple <int, string> >(this); RunnableGraph.FromGraph(GraphDsl.Create(Sink.FromSubscriber(downstream), (b, sink) => { var zip = b.Add(new Zip <int, string>()); var source1 = Source.FromPublisher(upstream1); var source2 = Source.FromPublisher(upstream2); b.From(source1).To(zip.In0); b.From(source2).To(zip.In1); b.From(zip.Out).To(sink); return(ClosedShape.Instance); })).Run(Materializer); downstream.Request(1); upstream1.SendNext(1); upstream2.SendNext("A"); downstream.ExpectNext(Tuple.Create(1, "A")); upstream2.SendComplete(); downstream.ExpectComplete(); upstream1.ExpectCancellation(); }, Materializer); }
public void Throttle_for_various_cost_elements_must_burst_some_elements_if_have_enough_time() { this.AssertAllStagesStopped(() => { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .Throttle(2, TimeSpan.FromMilliseconds(400), 5, e => e < 4 ? 1 : 20, ThrottleMode.Shaping) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(1); upstream.SendNext(1); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); downstream.ExpectNext(1); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); //wait to receive 2 in burst afterwards downstream.Request(5); var expected = new List <OnNext>(); for (var i = 2; i < 5; i++) { upstream.SendNext(i); if (i < 4) { expected.Add(new OnNext(i)); } } downstream.ReceiveWhile(TimeSpan.FromMilliseconds(200), filter: x => x, msgs: 2) .ShouldAllBeEquivalentTo(expected); downstream.Cancel(); }, Materializer); }
public void BatchWeighted_must_not_aggregate_heavy_elements() { var publisher = TestPublisher.CreateProbe <int>(this); var subscriber = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(publisher) .BatchWeighted(3, _ => 4, i => i, (sum, i) => sum + i) .To(Sink.FromSubscriber(subscriber)) .Run(Materializer); var sub = subscriber.EnsureSubscription(); publisher.SendNext(1); publisher.SendNext(2); sub.Request(1); subscriber.ExpectNext(1); publisher.SendNext(3); subscriber.ExpectNoMsg(TimeSpan.FromSeconds(1)); sub.Request(2); subscriber.ExpectNext(2); subscriber.ExpectNext(3); sub.Cancel(); }
public void A_Partition_must_complete_stage_after_upstream_completes() { this.AssertAllStagesStopped(() => { var c1 = TestSubscriber.CreateProbe <string>(this); var c2 = TestSubscriber.CreateProbe <string>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var partition = b.Add(new Partition <string>(2, s => s.Length > 4 ? 0 : 1)); var source = Source.From(new[] { "this", "is", "just", "another", "test" }); b.From(source).To(partition.In); b.From(partition.Out(0)).To(Sink.FromSubscriber(c1)); b.From(partition.Out(1)).To(Sink.FromSubscriber(c2)); return(ClosedShape.Instance); })).Run(Materializer); c1.Request(1); c2.Request(4); c1.ExpectNext("another"); c2.ExpectNext("this", "is", "just", "test"); c1.ExpectComplete(); c2.ExpectComplete(); }, Materializer); }
public void Throttle_for_various_cost_elements_must_burst_according_to_its_maximum_if_enough_time_passed() { this.AssertAllStagesStopped(() => { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .Throttle(2, TimeSpan.FromMilliseconds(400), 5, x => 1, ThrottleMode.Shaping) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(1); upstream.SendNext(1); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); downstream.ExpectNext(1); downstream.Request(5); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(1200)); var expected = new List <OnNext>(); for (var i = 2; i < 7; i++) { upstream.SendNext(i); expected.Add(new OnNext(i)); } downstream.ReceiveWhile(TimeSpan.FromMilliseconds(300), filter: x => x, msgs: 5) .ShouldAllBeEquivalentTo(expected); downstream.Cancel(); }, Materializer); }
public void A_Partition_must_remeber_first_pull_even_thought_first_element_target_another_out() { this.AssertAllStagesStopped(() => { var c1 = TestSubscriber.CreateProbe <int>(this); var c2 = TestSubscriber.CreateProbe <int>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var partition = b.Add(new Partition <int>(2, i => i < 6 ? 0 : 1)); var source = Source.From(new [] { 6, 3 }); b.From(source).To(partition.In); b.From(partition.Out(0)).To(Sink.FromSubscriber(c1)); b.From(partition.Out(1)).To(Sink.FromSubscriber(c2)); return(ClosedShape.Instance); })).Run(Materializer); c1.Request(1); c1.ExpectNoMsg(TimeSpan.FromSeconds(1)); c2.Request(1); c2.ExpectNext(6); c1.ExpectNext(3); c1.ExpectComplete(); c2.ExpectComplete(); }, Materializer); }
public void A_Partition_must_fail_stage_if_partitioner_outcome_is_out_of_bound() { this.AssertAllStagesStopped(() => { var c1 = TestSubscriber.CreateProbe <int>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var partition = b.Add(new Partition <int>(2, i => i < 0 ? -1 : 0)); var source = Source.From(new[] { -3 }); b.From(source).To(partition.In); b.From(partition.Out(0)).To(Sink.FromSubscriber(c1)); b.From(partition.Out(1)).To(Sink.Ignore <int>().MapMaterializedValue(_ => NotUsed.Instance)); return(ClosedShape.Instance); })).Run(Materializer); c1.Request(1); var error = c1.ExpectError(); error.Should().BeOfType <PartitionOutOfBoundsException>(); error.Message.Should() .Be( "partitioner must return an index in the range [0,1]. returned: [-1] for input [Int32]."); }, Materializer); }
public void A_Partition_must_stage_completion_is_waiting_for_pending_output() { this.AssertAllStagesStopped(() => { var c1 = TestSubscriber.CreateProbe <int>(this); var c2 = TestSubscriber.CreateProbe <int>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var partition = b.Add(new Partition <int>(2, i => i < 6 ? 0 : 1)); var source = Source.From(new[] { 6 }); b.From(source).To(partition.In); b.From(partition.Out(0)).To(Sink.FromSubscriber(c1)); b.From(partition.Out(1)).To(Sink.FromSubscriber(c2)); return(ClosedShape.Instance); })).Run(Materializer); c1.Request(1); c1.ExpectNoMsg(TimeSpan.FromSeconds(1)); c2.Request(1); c2.ExpectNext(6); c1.ExpectComplete(); c2.ExpectComplete(); }, Materializer); }
public void IdleTimeoutBidi_must_signal_error_to_all_outputs() { this.AssertAllStagesStopped(() => { var upWrite = TestPublisher.CreateProbe <string>(this); var upRead = TestSubscriber.CreateProbe <int>(this); var downWrite = TestPublisher.CreateProbe <int>(this); var downRead = TestSubscriber.CreateProbe <string>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var timeoutStage = b.Add(BidiFlow.BidirectionalIdleTimeout <string, int>(TimeSpan.FromSeconds(2))); b.From(Source.FromPublisher <string>(upWrite)).To(timeoutStage.Inlet1); b.From(timeoutStage.Outlet1).To(Sink.FromSubscriber(downRead)); b.From(timeoutStage.Outlet2).To(Sink.FromSubscriber(upRead)); b.From(Source.FromPublisher <int>(downWrite)).To(timeoutStage.Inlet2); return(ClosedShape.Instance); })).Run(Materializer); var te = new TestException("test"); upWrite.SendError(te); upRead.ExpectSubscriptionAndError().ShouldBeEquivalentTo(te); downRead.ExpectSubscriptionAndError().ShouldBeEquivalentTo(te); downWrite.ExpectCancellation(); }, Materializer); }
public void A_GroupedWithin_must_reset_time_window_when_max_elements_reached() { var input = new Iterator <int>(Enumerable.Range(1, 10000)); var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <IEnumerable <int> >(this); Source.FromPublisher(upstream) .GroupedWithin(3, TimeSpan.FromSeconds(2)) .To(Sink.FromSubscriber(downstream)) .Run(Materializer); downstream.Request(2); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(1000)); Enumerable.Range(1, 4).ForEach(_ => upstream.SendNext(input.Next())); downstream.Within(TimeSpan.FromMilliseconds(1000), () => { downstream.ExpectNext().ShouldAllBeEquivalentTo(new[] { 1, 2, 3 }); return(NotUsed.Instance); }); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(1500)); downstream.Within(TimeSpan.FromMilliseconds(1000), () => { downstream.ExpectNext().ShouldAllBeEquivalentTo(new[] { 4 }); return(NotUsed.Instance); }); upstream.SendComplete(); downstream.ExpectComplete(); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); }
protected override TestSubscriber.Probe <int> Setup(IPublisher <int> p1, IPublisher <int> p2) { var subscriber = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(p1) .Interleave(Source.FromPublisher(p2), 2) .RunWith(Sink.FromSubscriber(subscriber), Materializer); return(subscriber); }
public void ActorGraphInterpreter_should_be_able_to_properly_handle_case_where_a_stage_fails_before_subscription_happens() { // Fuzzing needs to be off, so that the failure can propagate to the output boundary // before the ExposedPublisher message. var noFuzzMaterializer = ActorMaterializer.Create(Sys, ActorMaterializerSettings.Create(Sys).WithFuzzingMode(false)); this.AssertAllStagesStopped(() => { var evilLatch = new CountdownEvent(1); // This is a somewhat tricky test setup. We need the following conditions to be met: // - the stage should fail its output port before the ExposedPublisher message is processed // - the enclosing actor (and therefore the stage) should be kept alive until a stray SubscribePending arrives // that has been enqueued after ExposedPublisher message has been enqueued, but before it has been processed // // To achieve keeping alive the stage for long enough, we use an extra input and output port and instead // of failing the stage, we fail only the output port under test. // // To delay the startup long enough, so both ExposedPublisher and SubscribePending are enqueued, we use an evil // latch to delay the preStart() (which in turn delays the enclosing actor's preStart). var failyStage = new FailyInPreStartGraphStage(evilLatch); var downstream0 = TestSubscriber.CreateProbe <int>(this); var downstream1 = TestSubscriber.CreateProbe <int>(this); var upstream = TestPublisher.CreateProbe <int>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var faily = b.Add(failyStage); b.From(Source.FromPublisher(upstream)).To(faily.In); b.From(faily.Out0).To(Sink.FromSubscriber(downstream0)); b.From(faily.Out1).To(Sink.FromSubscriber(downstream1)); return(ClosedShape.Instance); })).Run(noFuzzMaterializer); evilLatch.Signal(); var ex = downstream0.ExpectSubscriptionAndError(); ex.Should().BeOfType <TestException>(); ex.Message.Should().Be("Test failure in PreStart"); // if an NRE would happen due to unset exposedPublisher (see #19338), this would receive a failure instead // of the actual element downstream1.Request(1); upstream.SendNext(42); downstream1.ExpectNext(42); upstream.SendComplete(); downstream1.ExpectComplete(); }, noFuzzMaterializer); }
public void Throttle_for_various_cost_elements_must_cancel_when_downstream_cancels() { this.AssertAllStagesStopped(() => { var downstream = TestSubscriber.CreateProbe <int>(this); Source.From(Enumerable.Range(1, 10)) .Throttle(2, TimeSpan.FromMilliseconds(200), 0, x => x, ThrottleMode.Shaping) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Cancel(); }, Materializer); }
public void A_SkipWithin_must_deliver_completion_even_before_the_duration() { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .SkipWithin(TimeSpan.FromDays(1)) .RunWith(Sink.FromSubscriber(downstream), Materializer); upstream.SendComplete(); downstream.ExpectSubscriptionAndComplete(); }
public void IdleTimeoutBidi_must_be_able_to_signal_timeout_once_no_traffic_on_either_sides() { this.AssertAllStagesStopped(() => { var upWrite = TestPublisher.CreateProbe <string>(this); var upRead = TestSubscriber.CreateProbe <int>(this); var downWrite = TestPublisher.CreateProbe <int>(this); var downRead = TestSubscriber.CreateProbe <string>(this); RunnableGraph.FromGraph(GraphDsl.Create(b => { var timeoutStage = b.Add(BidiFlow.BidirectionalIdleTimeout <string, int>(TimeSpan.FromSeconds(2))); b.From(Source.FromPublisher <string>(upWrite)).To(timeoutStage.Inlet1); b.From(timeoutStage.Outlet1).To(Sink.FromSubscriber(downRead)); b.From(timeoutStage.Outlet2).To(Sink.FromSubscriber(upRead)); b.From(Source.FromPublisher <int>(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 GraphStage_timer_support_must_propagate_error_if_OnTimer_throws_an_Exception() { this.AssertAllStagesStopped(() => { var exception = new TestException("Expected exception to the rule"); var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .Via(new ThrowStage(exception)) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(1); downstream.ExpectError().Should().Be(exception); }, Materializer); }
public void KeepAlive_must_reset_deadline_properly_after_injected_element() { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .KeepAlive(TimeSpan.FromSeconds(1), () => 0) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(2); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); downstream.ExpectNext(0); downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); downstream.ExpectNext(0); }
public void KeepAlive_must_work_if_timer_fires_before_initial_request() { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .KeepAlive(TimeSpan.FromSeconds(1), () => 0) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.EnsureSubscription(); downstream.ExpectNoMsg(TimeSpan.FromSeconds(1.5)); downstream.Request(1); downstream.ExpectNext(0); upstream.SendComplete(); downstream.ExpectComplete(); }
public void KeepAlive_must_immediately_pull_upstream() { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .KeepAlive(TimeSpan.FromSeconds(1), () => 0) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(1); upstream.SendNext(1); downstream.ExpectNext(1); upstream.SendComplete(); downstream.ExpectComplete(); }
public void Flow_InitialDelay_must_properly_ignore_timer_while_backpressured() { this.AssertAllStagesStopped(() => { var probe = TestSubscriber.CreateProbe <int>(this); Source.From(Enumerable.Range(1, 10)) .InitialDelay(TimeSpan.FromSeconds(0.5)) .RunWith(Sink.FromSubscriber(probe), Materializer); probe.EnsureSubscription(); probe.ExpectNoMsg(TimeSpan.FromSeconds(1.5)); probe.Request(20); probe.ExpectNextN(Enumerable.Range(1, 10)); probe.ExpectComplete(); }, Materializer); }
public void Expand_musst_backpressure_publisher_when_subscriber_is_slower() { var publisher = TestPublisher.CreateProbe <int>(this); var subscriber = TestSubscriber.CreateProbe <int>(this); // Simply repeat the last element as an extrapolation step Source.FromPublisher(publisher) .Expand(i => Enumerable.Repeat(i, 200).GetEnumerator()) .To(Sink.FromSubscriber(subscriber)) .Run(Materializer); publisher.SendNext(1); subscriber.RequestNext(1); subscriber.RequestNext(1); var pending = publisher.Pending; // Deplete pending requests coming from input buffer while (pending > 0) { publisher.UnsafeSendNext(2); pending--; } // The above sends are absorbed in the input buffer, and will result in two one-sized batch requests pending += publisher.ExpectRequest(); pending += publisher.ExpectRequest(); while (pending > 0) { publisher.UnsafeSendNext(2); pending--; } publisher.ExpectNoMsg(TimeSpan.FromSeconds(1)); subscriber.Request(2); subscriber.ExpectNext(2); subscriber.ExpectNext(2); //now production is resumed publisher.ExpectRequest(); }
public ChainSetup( Func <Flow <TIn, TIn, NotUsed>, Flow <TIn, TOut, TMat> > stream, ActorMaterializerSettings settings, ActorMaterializer materializer, Func <Source <TOut, NotUsed>, ActorMaterializer, IPublisher <TOut> > toPublisher, TestKitBase system) { Settings = settings; System = system; Upstream = TestPublisher.CreateManualProbe <TIn>(system); Downstream = TestSubscriber.CreateProbe <TOut>(system); var s = Source.FromPublisher(Upstream).Via(stream((Flow <TIn, TIn, NotUsed>)Flow.Identity <TIn>().Select(x => x).Named("buh"))); Publisher = toPublisher(s, materializer); UpstreamSubscription = Upstream.ExpectSubscription(); Publisher.Subscribe(Downstream); DownstreamSubscription = Downstream.ExpectSubscription(); }
public void GraphStage_timer_support_must_produce_scheduled_ticks_as_expected() { this.AssertAllStagesStopped(() => { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .Via(new TestStage2()) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(5); downstream.ExpectNext(1, 2, 3); downstream.ExpectNoMsg(TimeSpan.FromSeconds(1)); upstream.SendComplete(); downstream.ExpectComplete(); }, Materializer); }
public void KeepAlive_must_work_if_timer_fires_before_initial_request_after_busy_period() { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.Combine(Source.From(Enumerable.Range(1, 10)), Source.FromPublisher(upstream), i => new Merge <int, int>(i)) .KeepAlive(TimeSpan.FromSeconds(1), () => 0) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.Request(10); downstream.ExpectNextN(Enumerable.Range(1, 10)); downstream.ExpectNoMsg(TimeSpan.FromSeconds(1.5)); downstream.Request(1); downstream.ExpectNext(0); upstream.SendComplete(); downstream.ExpectComplete(); }
public void ConcatAll_must_work_together_with_SplitWhen() { var subscriber = TestSubscriber.CreateProbe <int>(this); var source = Source.From(Enumerable.Range(1, 10)) .SplitWhen(x => x % 2 == 0) .PrefixAndTail(0) .Select(x => x.Item2) .ConcatSubstream() .ConcatMany(x => x); ((Source <int, NotUsed>)source).RunWith(Sink.FromSubscriber(subscriber), Materializer); for (var i = 1; i <= 10; i++) { subscriber.RequestNext(i); } subscriber.Request(1); subscriber.ExpectComplete(); }
public void KeepAlive_must_prefer_upstream_element_over_injected() { var upstream = TestPublisher.CreateProbe <int>(this); var downstream = TestSubscriber.CreateProbe <int>(this); Source.FromPublisher(upstream) .KeepAlive(TimeSpan.FromSeconds(1), () => 0) .RunWith(Sink.FromSubscriber(downstream), Materializer); downstream.EnsureSubscription(); downstream.ExpectNoMsg(TimeSpan.FromSeconds(1.5)); upstream.SendNext(1); downstream.ExpectNoMsg(TimeSpan.FromSeconds(0.5)); downstream.Request(1); downstream.ExpectNext(1); upstream.SendComplete(); downstream.ExpectComplete(); }