Example #1
0
        public void SplitWhen_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(elementCount: 4, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    var s1 = new StreamPuppet(getSubFlow().RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                    masterSubscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s1.Request(2);
                    s1.ExpectNext(1);
                    s1.ExpectNext(2);
                    s1.Request(1);
                    s1.ExpectComplete();

                    var s2 = new StreamPuppet(getSubFlow().RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                    masterSubscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s2.Request(1);
                    s2.ExpectNext(3);
                    s2.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s2.Request(1);
                    s2.ExpectNext(4);
                    s2.Request(1);
                    s2.ExpectComplete();

                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
Example #2
0
        public void GroupBy_must_fail_when_exceeding_maxSubstreams()
        {
            this.AssertAllStagesStopped(() =>
            {
                var f = Flow.Create <int>().GroupBy(1, x => x % 2).PrefixAndTail(0).MergeSubstreams();
                var t = ((Flow <int, Tuple <IImmutableList <int>, Source <int, NotUsed> >, NotUsed>)f)
                        .RunWith(TestSource.SourceProbe <int>(this), TestSink.SinkProbe <Tuple <IImmutableList <int>, Source <int, NotUsed> > >(this), Materializer);
                var up   = t.Item1;
                var down = t.Item2;

                down.Request(2);

                up.SendNext(1);
                var first = down.ExpectNext();
                var s1    = new StreamPuppet(first.Item2.RunWith(Sink.AsPublisher <int>(false), Materializer), this);

                s1.Request(1);
                s1.ExpectNext(1);

                up.SendNext(2);
                var ex = down.ExpectError();
                ex.Message.Should().Contain("too many substreams");
                s1.ExpectError(ex);
            }, Materializer);
        }
Example #3
0
        public void GroupBy_must_abort_onError_from_upstream_when_substreams_are_running()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = TestPublisher.CreateManualProbe <int>(this);
                var publisher      =
                    Source.FromPublisher(publisherProbe)
                    .GroupBy(2, x => x % 2)
                    .Lift(x => x % 2)
                    .RunWith(Sink.AsPublisher <Tuple <int, Source <int, NotUsed> > >(false), Materializer);
                var subscriber = TestSubscriber.CreateManualProbe <Tuple <int, Source <int, NotUsed> > >(this);
                publisher.Subscribe(subscriber);

                var upstreamSubscription   = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();
                downstreamSubscription.Request(100);
                upstreamSubscription.SendNext(1);
                var substream       = subscriber.ExpectNext().Item2;
                var substreamPuppet = new StreamPuppet(substream.RunWith(Sink.AsPublisher <int>(false), Materializer), this);

                substreamPuppet.Request(1);
                substreamPuppet.ExpectNext(1);

                var ex = new TestException("test");
                upstreamSubscription.SendError(ex);

                substreamPuppet.ExpectError(ex);
                subscriber.ExpectError().Should().Be(ex);
            }, Materializer);
        }
Example #4
0
        public void SplitWhen_must_support_cancelling_the_master_stream()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(5, 8, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    var s1 = new StreamPuppet(getSubFlow().RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                    masterSubscription.Cancel();

                    s1.Request(4);
                    s1.ExpectNext(1);
                    s1.ExpectNext(2);
                    s1.ExpectNext(3);
                    s1.ExpectNext(4);
                    s1.Request(1);
                    s1.ExpectComplete();
                });
            }, Materializer);
        }
Example #5
0
        public void GroupBy_must_resume_stream_when_GroupBy_function_throws()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = TestPublisher.CreateManualProbe <int>(this);
                var ex             = new TestException("test");
                var publisher      = Source.FromPublisher(publisherProbe).GroupBy(2, i =>
                {
                    if (i == 2)
                    {
                        throw ex;
                    }
                    return(i % 2);
                })
                                     .Lift(x => x % 2)
                                     .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider))
                                     .RunWith(Sink.AsPublisher <Tuple <int, Source <int, NotUsed> > >(false), Materializer);

                var subscriber = TestSubscriber.CreateManualProbe <Tuple <int, Source <int, NotUsed> > >(this);
                publisher.Subscribe(subscriber);

                var upstreamSubscription   = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();
                downstreamSubscription.Request(100);

                upstreamSubscription.SendNext(1);

                var substream        = subscriber.ExpectNext().Item2;
                var substreamPuppet1 = new StreamPuppet(substream.RunWith(Sink.AsPublisher <int>(false), Materializer), this);

                substreamPuppet1.Request(10);
                substreamPuppet1.ExpectNext(1);

                upstreamSubscription.SendNext(2);
                upstreamSubscription.SendNext(4);

                var substream2       = subscriber.ExpectNext().Item2;
                var substreamPuppet2 = new StreamPuppet(substream2.RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                substreamPuppet2.Request(10);
                substreamPuppet2.ExpectNext(4);

                upstreamSubscription.SendNext(3);
                substreamPuppet1.ExpectNext(3);

                upstreamSubscription.SendNext(6);
                substreamPuppet2.ExpectNext(6);

                upstreamSubscription.SendComplete();
                subscriber.ExpectComplete();
                substreamPuppet1.ExpectComplete();
                substreamPuppet2.ExpectComplete();
            }, Materializer);
        }
Example #6
0
        public void GroupBy_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(2, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    var s1 = new StreamPuppet(getSubFlow(1).RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                    masterSubscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s1.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                    s1.Request(1);
                    s1.ExpectNext(1);
                    s1.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    var s2 = new StreamPuppet(getSubFlow(0).RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                    s2.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                    s2.Request(2);
                    s2.ExpectNext(2);
                    // Important to request here on the OTHER stream because the buffer space is exactly one without the fanout box
                    s1.Request(1);
                    s2.ExpectNext(4);

                    s2.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s1.ExpectNext(3);

                    s2.Request(1);
                    // Important to request here on the OTHER stream because the buffer space is exactly one without the fanout box
                    s1.Request(1);
                    s2.ExpectNext(6);
                    s2.ExpectComplete();

                    s1.ExpectNext(5);
                    s1.ExpectComplete();
                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
Example #7
0
        public void GroupBy_must_support_cancelling_substreams()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(2, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    new StreamPuppet(getSubFlow(1).RunWith(Sink.AsPublisher <int>(false), Materializer), this).Cancel();
                    var substream = new StreamPuppet(getSubFlow(0).RunWith(Sink.AsPublisher <int>(false), Materializer), this);

                    substream.Request(2);
                    substream.ExpectNext(2);
                    substream.ExpectNext(4);
                    substream.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    substream.Request(2);
                    substream.ExpectNext(6);
                    substream.ExpectComplete();

                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
Example #8
0
        public void SplitWhen_must_work_when_first_element_is_split_by()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(1, 3, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    var s1 = new StreamPuppet(getSubFlow().RunWith(Sink.AsPublisher <int>(false), Materializer), this);

                    s1.Request(5);
                    s1.ExpectNext(1);
                    s1.ExpectNext(2);
                    s1.ExpectNext(3);
                    s1.ExpectComplete();

                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
        public void SplitAfter_should_work_when_last_element_is_split_by() => this.AssertAllStagesStopped(() =>
        {
            WithSubstreamsSupport(splitAfter: 3, elementCount: 3,
                                  run: (masterSubscriber, masterSubscription, expectSubFlow) =>
            {
                var s1 = new StreamPuppet(expectSubFlow()
                                          .RunWith(Sink.AsPublisher <int>(false), Materializer), this);
                masterSubscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                s1.Request(3);
                s1.ExpectNext(1);
                s1.ExpectNext(2);
                s1.ExpectNext(3);
                s1.ExpectComplete();

                masterSubscription.Request(1);
                masterSubscriber.ExpectComplete();
            });
        }, Materializer);
Example #10
0
        public void SplitWhen_must_fail_stream_when_SplitWhen_function_throws()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = this.CreateManualPublisherProbe <int>();
                var ex             = new TestException("test");
                var publisher      = Source.FromPublisher(publisherProbe).SplitWhen(i =>
                {
                    if (i == 3)
                    {
                        throw ex;
                    }
                    return(i % 3 == 0);
                }).Lift().RunWith(Sink.AsPublisher <Source <int, NotUsed> >(false), Materializer);

                var subscriber = this.CreateManualSubscriberProbe <Source <int, NotUsed> >();
                publisher.Subscribe(subscriber);

                var upstreamSubscription   = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();

                downstreamSubscription.Request(100);
                upstreamSubscription.SendNext(1);

                var substream       = subscriber.ExpectNext();
                var substreamPuppet = new StreamPuppet(substream.RunWith(Sink.AsPublisher <int>(false), Materializer), this);

                substreamPuppet.Request(10);
                substreamPuppet.ExpectNext(1);

                upstreamSubscription.SendNext(2);
                substreamPuppet.ExpectNext(2);

                upstreamSubscription.SendNext(3);

                subscriber.ExpectError().Should().Be(ex);
                substreamPuppet.ExpectError(ex);
                upstreamSubscription.ExpectCancellation();
            }, Materializer);
        }
Example #11
0
        public void GroupBy_must_resume_stream_when_GroupBy_function_throws()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = this.CreateManualPublisherProbe<int>();
                var ex = new TestException("test");
                var publisher = Source.FromPublisher(publisherProbe).GroupBy(2, i =>
                {
                    if (i == 2)
                        throw ex;
                    return i%2;
                })
                    .Lift(x => x%2)
                    .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider))
                    .RunWith(Sink.AsPublisher<Tuple<int, Source<int, NotUsed>>>(false), Materializer);

                var subscriber = this.CreateManualSubscriberProbe<Tuple<int, Source<int, NotUsed>>>();
                publisher.Subscribe(subscriber);

                var upstreamSubscription = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();
                downstreamSubscription.Request(100);

                upstreamSubscription.SendNext(1);

                var substream = subscriber.ExpectNext().Item2;
                var substreamPuppet1 = new StreamPuppet(substream.RunWith(Sink.AsPublisher<int>(false), Materializer), this);

                substreamPuppet1.Request(10);
                substreamPuppet1.ExpectNext(1);

                upstreamSubscription.SendNext(2);
                upstreamSubscription.SendNext(4);

                var substream2 = subscriber.ExpectNext().Item2;
                var substreamPuppet2 = new StreamPuppet(substream2.RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                substreamPuppet2.Request(10);
                substreamPuppet2.ExpectNext(4);

                upstreamSubscription.SendNext(3);
                substreamPuppet1.ExpectNext(3);

                upstreamSubscription.SendNext(6);
                substreamPuppet2.ExpectNext(6);

                upstreamSubscription.SendComplete();
                subscriber.ExpectComplete();
                substreamPuppet1.ExpectComplete();
                substreamPuppet2.ExpectComplete();

            }, Materializer);
        }
        public void SplitAfter_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(3,5,run: (masterSubscriber, masterSubscription, expectSubFlow) =>
                {
                    var s1 = new StreamPuppet(expectSubFlow().RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                    masterSubscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s1.Request(2);
                    s1.ExpectNext(1);
                    s1.ExpectNext(2);
                    s1.Request(1);
                    s1.ExpectNext(3);
                    s1.Request(1);
                    s1.ExpectComplete();

                    var s2 = new StreamPuppet(expectSubFlow().RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                    s2.Request(2);
                    s2.ExpectNext(4);
                    s2.ExpectNext(5);
                    s2.ExpectComplete();

                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
        public void SplitAfter_must_fail_stream_when_SplitAfter_function_throws()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = TestPublisher.CreateManualProbe<int>(this);
                var ex = new TestException("test");
                var publisher = Source.FromPublisher(publisherProbe).SplitAfter(i =>
                {
                    if (i == 3)
                        throw ex;
                    return i%3 == 0;
                }).Lift().RunWith(Sink.AsPublisher<Source<int, NotUsed>>(false), Materializer);
                
                var subscriber = TestSubscriber.CreateManualProbe<Source<int, NotUsed>>(this);
                publisher.Subscribe(subscriber);

                var upstreamSubscription = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();

                downstreamSubscription.Request(100);
                upstreamSubscription.SendNext(1);

                var substream = subscriber.ExpectNext();
                var substreamPuppet = new StreamPuppet(substream.RunWith(Sink.AsPublisher<int>(false), Materializer), this);

                substreamPuppet.Request(10);
                substreamPuppet.ExpectNext(1);

                upstreamSubscription.SendNext(2);
                substreamPuppet.ExpectNext(2);

                upstreamSubscription.SendNext(3);

                subscriber.ExpectError().Should().Be(ex);
                substreamPuppet.ExpectError(ex);
                upstreamSubscription.ExpectCancellation();
            }, Materializer);
        }
 public void SplitAfter_must_support_cancelling_substreams()
 {
     this.AssertAllStagesStopped(() =>
     {
         WithSubstreamsSupport(5, 8, run: (masterSubscriber, masterSubscription, expectSubFlow) =>
         {
             var s1 = new StreamPuppet(expectSubFlow().RunWith(Sink.AsPublisher<int>(false), Materializer), this);
             masterSubscription.Cancel();
             s1.Request(5);
             s1.ExpectNext(1);
             s1.ExpectNext(2);
             s1.ExpectNext(3);
             s1.ExpectNext(4);
             s1.ExpectNext(5);
             s1.Request(1);
             s1.ExpectComplete();
         });
     }, Materializer);
 }
Example #15
0
        public void GroupBy_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(2, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    var s1 = new StreamPuppet(getSubFlow(1).RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                    masterSubscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s1.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                    s1.Request(1);
                    s1.ExpectNext(1);
                    s1.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    var s2 = new StreamPuppet(getSubFlow(0).RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                    s2.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                    s2.Request(2);
                    s2.ExpectNext(2);
                    // Important to request here on the OTHER stream because the buffer space is exactly one without the fanout box
                    s1.Request(1);
                    s2.ExpectNext(4);

                    s2.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    s1.ExpectNext(3);

                    s2.Request(1);
                    // Important to request here on the OTHER stream because the buffer space is exactly one without the fanout box
                    s1.Request(1);
                    s2.ExpectNext(6);
                    s2.ExpectComplete();

                    s1.ExpectNext(5);
                    s1.ExpectComplete();
                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
Example #16
0
        public void GroupBy_must_fail_stream_when_GroupBy_function_throws()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = this.CreateManualPublisherProbe<int>();
                var ex = new TestException("test");
                var publisher = Source.FromPublisher(publisherProbe).GroupBy(2, i =>
                {
                    if (i == 2)
                        throw ex;
                    return i%2;
                })
                    .Lift(x => x%2)
                    .RunWith(Sink.AsPublisher<Tuple<int, Source<int, NotUsed>>>(false), Materializer);


                var subscriber = this.CreateManualSubscriberProbe<Tuple<int, Source<int, NotUsed>>>();
                publisher.Subscribe(subscriber);

                var upstreamSubscription = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();
                downstreamSubscription.Request(100);

                upstreamSubscription.SendNext(1);

                var substream = subscriber.ExpectNext().Item2;
                var substreamPuppet = new StreamPuppet(substream.RunWith(Sink.AsPublisher<int>(false), Materializer), this);

                substreamPuppet.Request(1);
                substreamPuppet.ExpectNext(1);

                upstreamSubscription.SendNext(2);
                subscriber.ExpectError().Should().Be(ex);
                substreamPuppet.ExpectError(ex);
                upstreamSubscription.ExpectCancellation();
            }, Materializer);
        }
Example #17
0
        public void GroupBy_must_abort_onError_from_upstream_when_substreams_are_running()
        {
            this.AssertAllStagesStopped(() =>
            {
                var publisherProbe = this.CreateManualPublisherProbe<int>();
                var publisher =
                    Source.FromPublisher(publisherProbe)
                        .GroupBy(2, x => x % 2)
                        .Lift(x => x % 2)
                        .RunWith(Sink.AsPublisher<Tuple<int, Source<int, NotUsed>>>(false), Materializer);
                var subscriber = this.CreateManualSubscriberProbe<Tuple<int, Source<int, NotUsed>>>();
                publisher.Subscribe(subscriber);

                var upstreamSubscription = publisherProbe.ExpectSubscription();
                var downstreamSubscription = subscriber.ExpectSubscription();
                downstreamSubscription.Request(100);
                upstreamSubscription.SendNext(1);
                var substream = subscriber.ExpectNext().Item2;
                var substreamPuppet = new StreamPuppet(substream.RunWith(Sink.AsPublisher<int>(false), Materializer), this);

                substreamPuppet.Request(1);
                substreamPuppet.ExpectNext(1);

                var ex = new TestException("test");
                upstreamSubscription.SendError(ex);

                substreamPuppet.ExpectError(ex);
                subscriber.ExpectError().Should().Be(ex);
            }, Materializer);
        }
Example #18
0
        public void GroupBy_must_support_cancelling_substreams()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(2, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    new StreamPuppet(getSubFlow(1).RunWith(Sink.AsPublisher<int>(false), Materializer), this).Cancel();
                    var substream = new StreamPuppet(getSubFlow(0).RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                    
                    substream.Request(2);
                    substream.ExpectNext(2);
                    substream.ExpectNext(4);
                    substream.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                    substream.Request(2);
                    substream.ExpectNext(6);
                    substream.ExpectComplete();

                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }
Example #19
0
        public void GroupBy_must_fail_when_exceeding_maxSubstreams()
        {
            this.AssertAllStagesStopped(() =>
            {
                var f = Flow.Create<int>().GroupBy(1, x => x%2).PrefixAndTail(0).MergeSubstreams();
                var t = ((Flow<int, Tuple<IImmutableList<int>, Source<int, NotUsed>>, NotUsed>) f)
                    .RunWith(this.SourceProbe<int>(), this.SinkProbe<Tuple<IImmutableList<int>, Source<int, NotUsed>>>(), Materializer);
                var up = t.Item1;
                var down = t.Item2;

                down.Request(2);

                up.SendNext(1);
                var first = down.ExpectNext();
                var s1 = new StreamPuppet(first.Item2.RunWith(Sink.AsPublisher<int>(false), Materializer), this);

                s1.Request(1);
                s1.ExpectNext(1);

                up.SendNext(2);
                var ex = down.ExpectError();
                ex.Message.Should().Contain("too many substreams");
                s1.ExpectError(ex);
            }, Materializer);
        }
Example #20
0
        public void SplitWhen_must_work_when_first_element_is_split_by()
        {
            this.AssertAllStagesStopped(() =>
            {
                WithSubstreamsSupport(1, 3, run: (masterSubscriber, masterSubscription, getSubFlow) =>
                {
                    var s1 = new StreamPuppet(getSubFlow().RunWith(Sink.AsPublisher<int>(false), Materializer), this);
                   
                    s1.Request(5);
                    s1.ExpectNext(1);
                    s1.ExpectNext(2);
                    s1.ExpectNext(3);
                    s1.ExpectComplete();

                    masterSubscription.Request(1);
                    masterSubscriber.ExpectComplete();
                });
            }, Materializer);
        }