Exemplo n.º 1
0
        public async Task StreamRefThrowsSubscriptionTimeout()
        {
            var ex = await Assert.ThrowsAsync <RemoteStreamRefActorTerminatedException>(async delegate
            {
                TimeSpan subscriptionTimeout = TimeSpan.FromSeconds(3);

                var sourceRef = await Source
                                .Single("NeverConsumedMsg")
                                .RunWith(StreamRefs.SourceRef <string>()
                                         .AddAttributes(StreamRefAttributes.CreateSubscriptionTimeout(subscriptionTimeout)),
                                         Sys.Materializer());

                Task.Delay(subscriptionTimeout + TimeSpan.FromSeconds(1)).Wait();

                await sourceRef.Source.RunWith(Sink.Ignore <string>(), Sys.Materializer());
            });

            // ex.InnerException.Should().BeOfType<StreamRefSubscriptionTimeoutException>(); // null inside
        }
Exemplo n.º 2
0
        protected override bool Receive(object message)
        {
            switch (message)
            {
            case "give":
            {
                /*
                 * Here we're able to send a source to a remote recipient
                 * For them it's a Source; for us it is a Sink we run data "into"
                 */
                var source = Source.From(new[] { "hello", "world" });
                var aref   = source.RunWith(StreamRefs.SourceRef <string>(), _materializer);
                aref.PipeTo(Sender);
                return(true);
            }

            case "give-infinite":
            {
                var source = Source.From(Enumerable.Range(1, int.MaxValue).Select(i => "ping-" + i));
                var t      = source.ToMaterialized(StreamRefs.SourceRef <string>(), Keep.Right).Run(_materializer);
                t.PipeTo(Sender);
                return(true);
            }

            case "give-fail":
            {
                var r = Source.Failed <string>(new Exception("Boom!"))
                        .RunWith(StreamRefs.SourceRef <string>(), _materializer);
                r.PipeTo(Sender);
                return(true);
            }

            case "give-complete-asap":
            {
                var r = Source.Empty <string>().RunWith(StreamRefs.SourceRef <string>(), _materializer);
                r.PipeTo(Sender);
                return(true);
            }

            case "give-subscribe-timeout":
            {
                var r = Source.Repeat("is anyone there?")
                        .ToMaterialized(StreamRefs.SourceRef <string>(), Keep.Right)
                        .WithAttributes(StreamRefAttributes.CreateSubscriptionTimeout(TimeSpan.FromMilliseconds(500)))
                        .Run(_materializer);
                r.PipeTo(Sender);
                return(true);
            }

            case "receive":
            {
                /*
                 * We write out code, knowing that the other side will stream the data into it.
                 * For them it's a Sink; for us it's a Source.
                 */
                var sink = StreamRefs.SinkRef <string>().To(Sink.ActorRef <string>(_probe, "<COMPLETE>"))
                           .Run(_materializer);
                sink.PipeTo(Sender);
                return(true);
            }

            case "receive-ignore":
            {
                var sink = StreamRefs.SinkRef <string>().To(Sink.Ignore <string>()).Run(_materializer);
                sink.PipeTo(Sender);
                return(true);
            }

            case "receive-subscribe-timeout":
            {
                var sink = StreamRefs.SinkRef <string>()
                           .WithAttributes(StreamRefAttributes.CreateSubscriptionTimeout(TimeSpan.FromMilliseconds(500)))
                           .To(Sink.ActorRef <string>(_probe, "<COMPLETE>"))
                           .Run(_materializer);
                sink.PipeTo(Sender);
                return(true);
            }

            case "receive-32":
            {
                //                    var t = StreamRefs.SinkRef<string>()
                //                        .ToMaterialized(TestSink.SinkProbe<string>(Context.System), Keep.Both)
                //                        .Run(_materializer);
                //
                //                    var sink = t.Item1;
                //                    var driver = t.Item2;
                //                    Task.Run(() =>
                //                    {
                //                        driver.EnsureSubscription();
                //                        driver.Request(2);
                //                        driver.ExpectNext();
                //                        driver.ExpectNext();
                //                        driver.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                //                        driver.Request(30);
                //                        driver.ExpectNextN(30);
                //
                //                        return "<COMPLETED>";
                //                    }).PipeTo(_probe);

                return(true);
            }

            default: return(false);
            }
        }