INTERNAL This special ActorRef is exclusively for use during unit testing in a single-threaded environment. Therefore, it overrides the dispatcher to CallingThreadDispatcher and sets the receiveTimeout to None. Otherwise, it acts just like a normal ActorRef. You may retrieve a reference to the underlying actor to test internal logic. Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.
Inheritance: Akka.Actor.LocalActorRef
Beispiel #1
0
        /// <summary>
        /// INTERNAL
        /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
        /// </summary>
        public static InternalTestActorRef Create(ActorSystem system, Props props, ActorRef supervisor = null, string name = null)
        {
            if (name == null)
            {
                name = CreateUniqueName();
            }

            if (supervisor == null)
            {
                var systemImpl = (ActorSystemImpl)system;
                supervisor = systemImpl.Guardian;
            }


            if (props.Deploy.Dispatcher == Deploy.NoDispatcherGiven)
            {
                props = props.WithDispatcher(CallingThreadDispatcher.Id);
            }

            //TODO: Should be val dispatcher = _system.dispatchers.lookup(props.dispatcher)
            //      but since we don't have the CallingThreadDispatcherConfigurator yet, we'll just create the dispatcher manually
            var dispatcher = props.Deploy.Dispatcher == CallingThreadDispatcher.Id ? new CallingThreadDispatcher() : system.Dispatchers.FromConfig(props.Dispatcher);

            var supervisorLocal = supervisor as LocalActorRef;

            if (supervisorLocal != null)
            {
                supervisorLocal.Cell.ReserveChild(name);
            }
            else
            {
                var supervisorRep = supervisor as RepointableActorRef;
                if (supervisorRep != null)
                {
                    var repUnderlying = supervisorRep.Underlying;
                    if (repUnderlying is UnstartedCell)
                    {
                        throw new IllegalStateException("Cannot attach a TestActor to an unstarted top-level actor, ensure that it is started by sending a message and observing the reply");
                    }
                    var cellUnderlying = repUnderlying as ActorCell;
                    if (cellUnderlying != null)
                    {
                        cellUnderlying.ReserveChild(name);
                    }
                    else
                    {
                        system.Log.Error("Trying to attach child {0} to unknown type of supervisor cell {1}, this is not going to end well", name, repUnderlying.GetType());
                    }
                }
            }
            //TODO: Should be: Func<Mailbox> mailbox = () => system.Mailboxes.FromConfig(dispatcher.Configurator.Config);
            Func <Mailbox> mailbox      = () => system.Mailboxes.CreateMailbox(props, null);
            var            testActorRef = new InternalTestActorRef(system, props, dispatcher, mailbox, (InternalActorRef)supervisor, supervisor.Path / name);

            // we need to start ourselves since the creation of an actor has been split into initialization and starting
            testActorRef.Underlying.Start();
            return(testActorRef);
        }
Beispiel #2
0
        /// <summary>
        /// INTERNAL
        /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
        /// </summary>
        /// <param name="system">TBD</param>
        /// <param name="props">TBD</param>
        /// <param name="supervisor">TBD</param>
        /// <param name="name">TBD</param>
        /// <exception cref="IllegalStateException">TBD</exception>
        /// <returns>TBD</returns>
        public static InternalTestActorRef Create(ActorSystem system, Props props, IActorRef supervisor = null, string name = null)
        {
            if (name == null)
            {
                name = CreateUniqueName();
            }

            if (supervisor == null)
            {
                var systemImpl = (ActorSystemImpl)system;
                supervisor = systemImpl.Guardian;
            }


            if (props.Deploy.Dispatcher == Deploy.NoDispatcherGiven)
            {
                props = props.WithDispatcher(CallingThreadDispatcher.Id);
            }

            var dispatcher = system.Dispatchers.Lookup(props.Deploy.Dispatcher);

            if (supervisor is LocalActorRef supervisorLocal)
            {
                supervisorLocal.Cell.ReserveChild(name);
            }
            else
            {
                if (supervisor is RepointableActorRef supervisorRep)
                {
                    var repUnderlying = supervisorRep.Underlying;
                    if (repUnderlying is UnstartedCell)
                    {
                        throw new IllegalStateException("Cannot attach a TestActor to an unstarted top-level actor, ensure that it is started by sending a message and observing the reply");
                    }
                    if (repUnderlying is ActorCell cellUnderlying)
                    {
                        cellUnderlying.ReserveChild(name);
                    }
                    else
                    {
                        system.Log.Error("Trying to attach child {0} to unknown type of supervisor cell {1}, this is not going to end well", name, repUnderlying.GetType());
                    }
                }
            }

            var mailbox      = system.Mailboxes.GetMailboxType(props, dispatcher.Configurator.Config);
            var testActorRef = new InternalTestActorRef((ActorSystemImpl)system, props, dispatcher, mailbox, (IInternalActorRef)supervisor, supervisor.Path / name);

            // we need to start ourselves since the creation of an actor has been split into initialization and starting
            testActorRef.Underlying.Start();
            return(testActorRef);
        }
        /// <summary>
        /// INTERNAL
        /// <remarks>Note! Part of internal API. Breaking changes may occur without notice. Use at own risk.</remarks>
        /// </summary>
        public static InternalTestActorRef Create(ActorSystem system, Props props, IActorRef supervisor = null, string name = null)
        {
            if(name == null)
                name = CreateUniqueName();

            if(supervisor == null)
            {
                var systemImpl = (ActorSystemImpl)system;
                supervisor = systemImpl.Guardian;
            }


            if(props.Deploy.Dispatcher == Deploy.NoDispatcherGiven)
            {
                props = props.WithDispatcher(CallingThreadDispatcher.Id);
            }

            var dispatcher = system.Dispatchers.Lookup(props.Deploy.Dispatcher);

            var supervisorLocal = supervisor as LocalActorRef;
            if(supervisorLocal != null)
            {
                supervisorLocal.Cell.ReserveChild(name);
            }
            else
            {
                var supervisorRep = supervisor as RepointableActorRef;
                if(supervisorRep != null)
                {
                    var repUnderlying = supervisorRep.Underlying;
                    if(repUnderlying is UnstartedCell)
                        throw new IllegalStateException("Cannot attach a TestActor to an unstarted top-level actor, ensure that it is started by sending a message and observing the reply");
                    var cellUnderlying = repUnderlying as ActorCell;
                    if(cellUnderlying != null)
                    {
                        cellUnderlying.ReserveChild(name);
                    }
                    else
                    {
                        system.Log.Error("Trying to attach child {0} to unknown type of supervisor cell {1}, this is not going to end well", name, repUnderlying.GetType());
                    }
                }
            }
            //TODO: Should be: Func<Mailbox> mailbox = () => system.Mailboxes.FromConfig(dispatcher.Configurator.Config);
            Func<Mailbox> mailbox = () => system.Mailboxes.CreateMailbox(props, null);
            var testActorRef = new InternalTestActorRef(system, props, dispatcher, mailbox, (IInternalActorRef)supervisor, supervisor.Path / name);

            // we need to start ourselves since the creation of an actor has been split into initialization and starting
            testActorRef.Underlying.Start();
            return testActorRef;
        }