public void When_actor_Stops_Then_it_sends_ActorTerminated_message_to_supervisor() { var system = new TestActorSystem(); system.Start(); var parentMailbox = new TestMailbox(system.CreateDefaultMailbox()); ParentWithFailingChildActor parentInstance = null; var props = new DelegateActorCreationProperties(() => parentInstance = new ParentWithFailingChildActor()) { MailboxCreator = () => parentMailbox }; var actor = system.CreateActor(props, "Parent"); actor.Send("A trigger message that will cause actor to fail", null); var actorsTerminated = parentMailbox.GetStateChangesForEnquingSystemMessagesOfType <ActorTerminated>().ToList(); actorsTerminated.Should().HaveCount(1).And.ContainSingle(s => ((ActorTerminated)s.GetLastEnqueuedSystemMessage().Message).TerminatedActor == parentInstance.FailingChild); }
public void Given_an_actor_with_children_When_it_crashes_during_handling_message_Then_its_children_terminates_and_sends_ActorTerminated_to_their_parent() { //The children get created since their parent gets created var system = new TestActorSystem(); system.Start(); var mailbox = new TestMailbox(system.CreateDefaultMailbox()); var props = new DelegateActorCreationProperties(() => new ParentWhichFailsWithChildrenActor(2, childName: i => "Child" + i)) { MailboxCreator = () => mailbox }; var actor = system.CreateActor(props, "Parent"); actor.Send("A trigger message that will cause actor to fail", null); var actorTerminatedMessages = mailbox.GetStateChangesForEnquingSystemMessagesOfType <ActorTerminated>(); actorTerminatedMessages.Count.Should().Be(2); var terminatedActorNames = actorTerminatedMessages.Select(m => ((ActorTerminated)m.GetLastEnqueuedSystemMessage().Message).TerminatedActor.Name).OrderBy(n => n).ToList(); terminatedActorNames.Should().ContainInOrder(new [] { "Child1", "Child2" }); }
public void When_a_child_actor_is_created_Then_it_sends_SuperviseActor_message_to_parent() { var system = new TestActorSystem(); system.Start(); var mailbox = new TestMailbox(system.CreateDefaultMailbox()); ParentWithChildActor parent = null; var parentProps = new DelegateActorCreationProperties(() => { parent = new ParentWithChildActor(); return(parent); }) { MailboxCreator = () => mailbox }; var parentRef = system.CreateActor(parentProps, "Parent"); var stateChanges = mailbox.GetStateChangesForEnquingSystemMessagesOfType <SuperviseActor>(); stateChanges.Count.Should().Be(1); ((SuperviseActor)stateChanges.First().GetLastEnqueuedSystemMessage().Message).ActorToSupervise.Should().BeSameAs(parent.Child); }