Ejemplo n.º 1
0
        public void ActorPublisher_should_be_able_to_define_a_subscription_timeout_which_is_cancelled_by_the_first_incoming_Subscriber()
        {
            var timeout = TimeSpan.FromMilliseconds(500);
            var sub     = this.CreateManualSubscriberProbe <int>();

            var pub = ActorPublisher.Create <int>(ActorOf(TimeoutingPublisher.Props(TestActor, timeout)));

            // subscribe right away, should cancel subscription-timeout
            pub.Subscribe(sub);
            sub.ExpectSubscription();

            ExpectNoMsg(TimeSpan.FromSeconds(1));
        }
Ejemplo n.º 2
0
        public void ActorPublisher_should_be_able_to_define_a_subscription_timeout_after_which_it_should_shut_down()
        {
            var materializer = Sys.Materializer();

            this.AssertAllStagesStopped(() =>
            {
                var timeout = TimeSpan.FromMilliseconds(150);
                var a       = ActorOf(TimeoutingPublisher.Props(TestActor, timeout));
                var pub     = ActorPublisher.Create <int>(a);

                // don't subscribe for `timeout` millis, so it will shut itself down
                ExpectMsg("timed-out");

                // now subscribers will already be rejected, while the actor could perform some clean-up
                var sub = this.CreateManualSubscriberProbe <int>();
                pub.Subscribe(sub);
                sub.ExpectSubscriptionAndError();

                ExpectMsg("cleaned-up");
                // termination is triggered by user code
                Watch(a);
                ExpectTerminated(a);
            }, materializer);
        }