Adding initial support for Props
This commit is contained in:
parent
4bc0cfe0bf
commit
c7d58c600b
102 changed files with 1141 additions and 1524 deletions
|
|
@ -9,6 +9,7 @@ import akka.util.ReflectiveAccess
|
|||
import akka.event.EventHandler
|
||||
|
||||
import com.eaio.uuid.UUID
|
||||
import akka.actor.Props._
|
||||
|
||||
/**
|
||||
* This special ActorRef is exclusively for use during unit testing in a single-threaded environment. Therefore, it
|
||||
|
|
@ -18,24 +19,20 @@ import com.eaio.uuid.UUID
|
|||
* @author Roland Kuhn
|
||||
* @since 1.1
|
||||
*/
|
||||
class TestActorRef[T <: Actor](factory: () ⇒ T, address: String) extends LocalActorRef(factory, address) {
|
||||
|
||||
dispatcher = CallingThreadDispatcher.global
|
||||
receiveTimeout = None
|
||||
|
||||
class TestActorRef[T <: Actor](props: Props, address: String) extends LocalActorRef(props.withDispatcher(CallingThreadDispatcher.global), address) {
|
||||
/**
|
||||
* Directly inject messages into actor receive behavior. Any exceptions
|
||||
* thrown will be available to you, while still being able to use
|
||||
* become/unbecome and their message counterparts.
|
||||
*/
|
||||
def apply(o: Any) { actor(o) }
|
||||
def apply(o: Any) { actorInstance.get().apply(o) }
|
||||
|
||||
/**
|
||||
* Retrieve reference to the underlying actor, where the static type matches the factory used inside the
|
||||
* constructor. Beware that this reference is discarded by the ActorRef upon restarting the actor (should this
|
||||
* reference be linked to a supervisor). The old Actor may of course still be used in post-mortem assertions.
|
||||
*/
|
||||
def underlyingActor: T = actor.asInstanceOf[T]
|
||||
def underlyingActor: T = actorInstance.get().asInstanceOf[T]
|
||||
|
||||
override def toString = "TestActor[" + address + ":" + uuid + "]"
|
||||
|
||||
|
|
@ -49,9 +46,10 @@ class TestActorRef[T <: Actor](factory: () ⇒ T, address: String) extends Local
|
|||
* supervisor, but then you just asked for trouble.
|
||||
*/
|
||||
override def supervisor_=(a: Option[ActorRef]) {
|
||||
for (ref ← a) {
|
||||
if (!ref.dispatcher.isInstanceOf[CallingThreadDispatcher])
|
||||
EventHandler.warning(this, "supervisor " + ref + " does not use CallingThreadDispatcher")
|
||||
a match { //TODO This should probably be removed since the Supervisor could be a remote actor for all we know
|
||||
case Some(l: SelfActorRef) if !l.dispatcher.isInstanceOf[CallingThreadDispatcher] ⇒
|
||||
EventHandler.warning(this, "supervisor " + l + " does not use CallingThreadDispatcher")
|
||||
case _ ⇒
|
||||
}
|
||||
super.supervisor_=(a)
|
||||
}
|
||||
|
|
@ -60,14 +58,17 @@ class TestActorRef[T <: Actor](factory: () ⇒ T, address: String) extends Local
|
|||
|
||||
object TestActorRef {
|
||||
|
||||
def apply[T <: Actor](factory: ⇒ T): TestActorRef[T] = apply[T](factory, new UUID().toString)
|
||||
def apply[T <: Actor](factory: ⇒ T): TestActorRef[T] = apply[T](Props(factory), new UUID().toString)
|
||||
|
||||
def apply[T <: Actor](factory: ⇒ T, address: String): TestActorRef[T] = new TestActorRef(() ⇒ factory, address)
|
||||
def apply[T <: Actor](factory: ⇒ T, address: String): TestActorRef[T] = apply[T](Props(factory), address)
|
||||
|
||||
def apply[T <: Actor](props: Props): TestActorRef[T] = apply[T](props, new UUID().toString).start()
|
||||
|
||||
def apply[T <: Actor](props: Props, address: String): TestActorRef[T] = new TestActorRef(props, address).start()
|
||||
|
||||
def apply[T <: Actor: Manifest]: TestActorRef[T] = apply[T](new UUID().toString)
|
||||
|
||||
def apply[T <: Actor: Manifest](address: String): TestActorRef[T] = new TestActorRef[T]({ () ⇒
|
||||
|
||||
def apply[T <: Actor: Manifest](address: String): TestActorRef[T] = apply[T](Props({
|
||||
import ReflectiveAccess.{ createInstance, noParams, noArgs }
|
||||
createInstance[T](manifest[T].erasure, noParams, noArgs) match {
|
||||
case Right(value) ⇒ value
|
||||
|
|
@ -77,5 +78,5 @@ object TestActorRef {
|
|||
"\nif so put it outside the class/trait, f.e. in a companion object," +
|
||||
"\nOR try to change: 'actorOf[MyActor]' to 'actorOf(new MyActor)'.", exception)
|
||||
}
|
||||
}, address)
|
||||
}), address)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue