public void PersistenceSupervisor_should_buffer_messages_while_ActorIsRestarting()
        {
            Func <IActorRef, Props> childProps = i => Props.Create(() => new AckActor(i, TestActor, "fuber", true));

            // make the backoff window huge, so we have to manually restart it
            var supervisorConfig = new PersistenceSupervisionConfig(o => o is string, ToConfirmableMessage,
                                                                    new ManualReset(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10));

            var supervisorProps = Props.Create(() =>
                                               new PersistenceSupervisor(childProps, "myPersistentActor", supervisorConfig, null));
            var actor = Sys.ActorOf(supervisorProps);

            actor.Tell(BackoffSupervisor.GetCurrentChild.Instance);
            var child = ExpectMsg <BackoffSupervisor.CurrentChild>().Ref;

            Watch(child);

            // send some events
            actor.Tell("event1");
            actor.Tell("event2");
            ExpectMsg <Confirmation>().ConfirmationId.Should().Be(1L);
            ExpectMsg <Confirmation>().ConfirmationId.Should().Be(2L);

            // kill the child
            EventFilter.Exception <ApplicationException>("boom").ExpectOne(() =>
            {
                actor.Tell(AckActor.Fail.Instance);
                ExpectTerminated(child); // child should be stopped by default parent supervisor strategy
            });

            // send a blend of events and other messages prior to restart
            actor.Tell("event3");
            actor.Tell(1);
            actor.Tell(2);
            actor.Tell("event4");
            actor.Tell(true);

            // shouldn't hear anything back
            ExpectNoMsg(250);

            // create the child manually (timer is still running in background)
            actor.Tell(BackoffSupervisor.StartChild.Instance);

            ExpectMsg <Confirmation>().ConfirmationId.Should().Be(3L);
            ExpectMsg(1);
            ExpectMsg(2);
            ExpectMsg <Confirmation>().ConfirmationId.Should().Be(4L);
            ExpectMsg(true);
        }
        public void PersistentSupervisor_should_kill_child_and_self_if_RestartCount_Exceeded()
        {
            Func <IActorRef, Props> childProps = i => Props.Create(() => new AckActor(i, TestActor, "fuber", true));
            var supervisorConfig = new PersistenceSupervisionConfig(o => o is string, ToConfirmableMessage,
                                                                    new ManualReset(), TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(10));

            var supervisorProps = Props.Create(() =>
                                               new PersistenceSupervisor(childProps, "myPersistentActor", supervisorConfig,
                                                                         SupervisorStrategy.StoppingStrategy.WithMaxNrOfRetries(1)));
            var actor = Sys.ActorOf(supervisorProps);

            Watch(actor);

            actor.Tell(BackoffSupervisor.GetCurrentChild.Instance);
            var child = ExpectMsg <BackoffSupervisor.CurrentChild>().Ref;

            Watch(child);

            actor.Tell(AckActor.Fail.Instance); // forces the actor to fail
            ExpectTerminated(child);

            AwaitCondition(() =>
            {
                actor.Tell(BackoffSupervisor.GetCurrentChild.Instance);
                child = ExpectMsg <BackoffSupervisor.CurrentChild>().Ref;
                if (child.IsNobody())
                {
                    return(false);
                }

                Watch(child);
                actor.Tell(AckActor.Fail.Instance); // forces the actor to fail
                ExpectTerminated(child);
                return(true);
            });

            ExpectTerminated(actor);
        }