Exemplo n.º 1
0
        public void MergeHub_must_notify_new_producers_if_consumer_cancels_before_first_producer()
        {
            this.AssertAllStagesStopped(() =>
            {
                var sink     = Sink.Cancelled <int>().RunWith(MergeHub.Source <int>(16), Materializer);
                var upstream = this.CreatePublisherProbe <int>();

                Source.FromPublisher(upstream).RunWith(sink, Materializer);

                upstream.ExpectCancellation();
            }, Materializer);
        }
Exemplo n.º 2
0
        public void Simple_server_connection_must_close_incoming_connection()
        {
            Source <Tcp.IncomingConnection, Task <Tcp.ServerBinding> > connections =
                Sys.TcpStream().Bind("127.0.0.1", 8888);

            connections.RunForeach(connection =>
            {
                #region close-incoming-connection
                var closed = Flow.FromSinkAndSource(Sink.Cancelled <ByteString>(), Source.Empty <ByteString>());
                connection.HandleWith(closed, Materializer);
                #endregion
            }, Materializer);
        }
Exemplo n.º 3
0
        public void A_lazy_source_must_fail_the_materialized_value_when_downstream_cancels_without_ever_consuming_any_element()
        {
            this.AssertAllStagesStopped(() =>
            {
                var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 }))
                             .ToMaterialized(Sink.Cancelled <int>(), Keep.Left)
                             .Run(Materializer);

                Intercept(() =>
                {
                    var boom = result.Result;
                });
            }, Materializer);
        }
Exemplo n.º 4
0
        public async Task Source_prematerialization_must_survive_cancellation_of_downstream_materialized_sources()
        {
            var matValPoweredSource = Source.Queue <string>(Int32.MaxValue, OverflowStrategy.Fail);
            var matted = matValPoweredSource.PreMaterialize(Sys.Materializer());
            var mat    = matted.Item1;
            var src    = matted.Item2;

            var probe1 = src.RunWith(this.SinkProbe <string>(), Sys.Materializer());

            src.RunWith(Sink.Cancelled <string>(), Sys.Materializer());

            probe1.Request(1);
            await mat.OfferAsync("One");

            probe1.ExpectNext("One");
        }
Exemplo n.º 5
0
        public void SplitWhen_must_support_cancelling_both_master_and_substream()
        {
            this.AssertAllStagesStopped(() =>
            {
                var inputs = this.CreatePublisherProbe <int>();

                var substream    = this.CreateSubscriberProbe <int>();
                var masterStream = this.CreateSubscriberProbe <NotUsed>();

                Source.FromPublisher(inputs)
                .SplitWhen(x => x == 2)
                .Lift()
                .Select(x => x.RunWith(Sink.FromSubscriber(substream), Materializer))
                .RunWith(Sink.FromSubscriber(masterStream), Materializer);

                masterStream.Request(1);
                inputs.SendNext(1);

                substream.Cancel();

                masterStream.ExpectNext(NotUsed.Instance);
                masterStream.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                masterStream.Cancel();
                inputs.ExpectCancellation();

                var inputs2 = this.CreatePublisherProbe <int>();
                Source.FromPublisher(inputs2)
                .SplitWhen(x => x == 2)
                .Lift()
                .Select(x => x.RunWith(Sink.Cancelled <int>(), Materializer))
                .RunWith(Sink.Cancelled <NotUsed>(), Materializer);
                inputs2.ExpectCancellation();

                var inputs3       = this.CreatePublisherProbe <int>();
                var masterStream3 = this.CreateSubscriberProbe <Source <int, NotUsed> >();

                Source.FromPublisher(inputs3)
                .SplitWhen(x => x == 2)
                .Lift()
                .RunWith(Sink.FromSubscriber(masterStream3), Materializer);

                masterStream3.Request(1);
                inputs3.SendNext(1);

                var src = masterStream3.ExpectNext();
                src.RunWith(Sink.Cancelled <int>(), Materializer);

                masterStream3.Request(1);
                inputs3.SendNext(2);
                var src2       = masterStream3.ExpectNext();
                var substream4 = this.CreateSubscriberProbe <int>();
                src2.RunWith(Sink.FromSubscriber(substream4), Materializer);

                substream4.RequestNext(2);
                substream4.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                masterStream3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                inputs3.ExpectRequest();
                inputs3.ExpectRequest();
                inputs3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                substream4.Cancel();
                inputs3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                masterStream3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

                masterStream3.Cancel();
                inputs3.ExpectCancellation();
            }, Materializer);
        }