Esempio n. 1
0
        public void When_Actor_is_created_Then_it_marks_the_ActorRef_as_consumed()
        {
            var       mailbox           = A.Fake <Mailbox>();
            var       actorInstantiator = A.Fake <ActorInstantiator>();
            TestActor actor             = null;
            ImmutableStack <LocalActorRef> stackDuringActorCreation = null;

            A.CallTo(() => actorInstantiator.CreateNewActor()).Invokes(() =>
            {
                stackDuringActorCreation = ActorHelper.GetActorRefStack();
            }).ReturnsLazily(() =>
            {
                actor = new TestActor();
                return(actor);
            });

            var actorRef = new LocalActorRef(new TestActorSystem(), actorInstantiator, new RootActorPath("test"), mailbox, A.Dummy <InternalActorRef>());

            //Send Create message so that the instance is created
            actorRef.HandleSystemMessage(new SystemMessageEnvelope(actorRef, new CreateActor(), A.Fake <ActorRef>()));

            var actorRefsAddedDuringConstructor = actor.LocalActorRefStackInConstructor.Except(stackDuringActorCreation).ToList();

            actorRefsAddedDuringConstructor.Count.Should().Be(1);
            actorRefsAddedDuringConstructor[0].Should().BeNull();
        }
Esempio n. 2
0
        public void When_handling_CreateActor_message_Then_the_LocalActorRef_is_pushed_to_stack_and_afterwards_removed()
        {
            var mailbox           = A.Fake <Mailbox>();
            var actorInstantiator = A.Fake <ActorInstantiator>();
            ImmutableStack <LocalActorRef> stackDuringActorCreation = null;

            A.CallTo(() => actorInstantiator.CreateNewActor()).Invokes(() =>
            {
                stackDuringActorCreation = ActorHelper.GetActorRefStack();
            }).ReturnsLazily(() => new TestActor());
            var actorRef = new LocalActorRef(new TestActorSystem(), actorInstantiator, new RootActorPath("test"), mailbox, A.Dummy <InternalActorRef>());

            actorRef.HandleSystemMessage(new SystemMessageEnvelope(actorRef, new CreateActor(), A.Fake <ActorRef>()));
            var stackAfterActorCreation = ActorHelper.GetActorRefStack();

            stackDuringActorCreation.IsEmpty.Should().BeFalse("The stack should contain one item");
            stackDuringActorCreation.Peek().Should().BeSameAs(actorRef, "The item on stack should be the LocalActorRef that creates the actor");
            stackDuringActorCreation.Count().Should().Be(1, "The stack should only contain one item.");
            (stackAfterActorCreation == null || stackAfterActorCreation.IsEmpty).Should().BeTrue("The stack should be empty after creation");
        }
Esempio n. 3
0
 public TestActor()
 {
     //At this stage base ctor has been called.
     //Store what's on the stack right now.
     LocalActorRefStackInConstructor = ActorHelper.GetActorRefStack();
 }