public void When_an_actor_crashes_during_handling_message_Then_the_actors_mailbox_gets_suspended() { var system = new TestActorSystem(); system.Start(); var mailbox = new TestMailbox(system.CreateDefaultMailbox()); var props = new DelegateActorCreationProperties(() => AnonymousActor.Create <object>(_ => { throw new Exception(); })) { MailboxCreator = () => mailbox }; var actor = system.CreateActor(props); actor.Send("A trigger message that will cause actor to fail", null); var suspendCalls = mailbox.GetStateChangesFor(TestMailbox.StateChange.Suspend); suspendCalls.Count.Should().Be(1); }
public void When_watching_another_actor_Then_a_Watch_message_is_sent_to_that_actor() { var system = new TestActorSystem(); system.Start(); var mailbox = new TestMailbox(system.CreateDefaultMailbox()); var watchedActorProps = new DelegateActorCreationProperties(() => AnonymousActor.Create <object>(_ => { })) { MailboxCreator = () => mailbox }; var watchedActor = system.CreateActor(watchedActorProps, "WatchedActor"); var watcher = system.CreateActor(ActorCreationProperties.Create(() => new WatchingActor(watchedActor)), "Watcher"); watcher.Send("watch", null); var watchMessages = mailbox.GetEnquedSystemMessagesOfType <WatchActor>(); watchMessages.Should().HaveCount(1); watchMessages[0].Watcher.Should().BeSameAs(watcher); }
public void Given_supervisor_that_restarts_all_children_When_child_crashes_Then_all_its_siblings_are_restarted() { var system = new TestActorSystem(); system.Start(); var failingChildMailbox = new TestMailbox(system.CreateDefaultMailbox()); var childrenMailboxes = Enumerable.Range(1, 10).Select(_ => new TestMailbox(system.CreateDefaultMailbox())).ToList(); var parent = system.CreateActor(ActorCreationProperties.Create(() => new ParentWithFailingChildActor(failingChildMailbox, childrenMailboxes, AllForOneSupervisorStrategy.DefaultAllForOne))); parent.Send("A trigger message that will cause the child actor to fail", null); var childRestarts = childrenMailboxes.Select(m => m.GetStateChangesForEnquingSystemMessagesOfType <RecreateActor>()).ToList(); childRestarts.Count.Should().Be(10); for (int i = 0; i < childRestarts.Count; i++) { var suspendCalls = childRestarts[i]; suspendCalls.Count.Should().Be(1, "Mailbox for child " + i + " should have been restarted."); } }
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_watched_actor_dies_Then_an_WatchedActorTerminated_message_is_sent_to_watchers() { var system = new TestActorSystem(); system.Start(); var mailbox = new TestMailbox(system.CreateDefaultMailbox()); var watchedActor = system.CreateActor(ActorCreationProperties.Create <StoppingActor>(), "WatchedActor"); var watcherProps = new DelegateActorCreationProperties(() => new WatchingActor(watchedActor)) { MailboxCreator = () => mailbox }; var watcher = system.CreateActor(watcherProps, "Watcher"); watcher.Send("watch", null); mailbox.ClearEnqueuedMessages(); watchedActor.Send("stop", null); var watchMessages = mailbox.GetEnquedMessagesOfType <WatchedActorTerminated>(); watchMessages.Should().HaveCount(1); watchMessages[0].TerminatedActor.Should().BeSameAs(watchedActor); }
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); }
public void Given_an_actor_with_children_When_it_crashes_during_handling_message_Then_its_children_are_stopped() { var system = new TestActorSystem(); system.Start(); var childrenMailboxes = Enumerable.Range(1, 10).Select(_ => new TestMailbox(system.CreateDefaultMailbox())).ToList(); var mailbox = new TestMailbox(system.CreateDefaultMailbox()); var props = new DelegateActorCreationProperties(() => new ParentWhichFailsWithChildrenActor(childrenMailboxes)) { MailboxCreator = () => mailbox }; var actor = system.CreateActor(props); actor.Send("A trigger message that will cause actor to fail", null); var childTerminations = childrenMailboxes.Select(m => m.GetStateChangesForEnquingSystemMessagesOfType <TerminateActor>()).ToList(); childTerminations.Count.Should().Be(10); for (int i = 0; i < childTerminations.Count; i++) { var terminateCalls = childTerminations[i]; terminateCalls.Count.Should().Be(1, "Mailbox for child " + i + " should have been terminated."); } }