scala - TestActorRef: Could not get the underlyingActor, says Nothing -
i trying write first scalatest following actor
object runner { def props(race: race) = props(classof[runner], race) } class runner(race: race) extends actor actorlogging { import context.dispatcher @throws[exception](classof[exception]) override def postrestart(reason: throwable): unit = context.parent ! restartrunner override def receive: receive = loggingreceive { case start => { log.debug("running...") (i <- 1 3) { thread.sleep(200) } throw new runtimeexception("marathonrunner tired") } case startwithfuture => log.debug("i starting run") race.start pipeto self case failure(throwable) => throw throwable case stop => log.debug("stopping runner") context.stop(self) } } so,
import akka.actor.{props, actorsystem} import akka.testkit.{testactorref, testkit} import org.scalatest._ class runnerspec extends testkit(actorsystem("test")) wordspeclike mustmatchers { "a runner actor" must { val runner = testactorref(props(new runner(new marathon))) "receive messages" in { runner ! start runner.under <== says nothing (see attachment) } } } but see

why don't runner actor?
since props untyped not know type of actor (in case runner) build. consequently, testactorref cannot infer type either. why need explicitly state type of underlying actor when constructing testactorref using
val runner = testactorref[runner](props(new runner(new marathon))) in case actor did not require parameters, shortened to
val runner = testactorref[runner] however, since nothing base class of every scala type, underlying actor same in either case. if changing testactorref definition not possible casted yield runner.
runner.underlyingactor.asinstanceof[runner]
Comments
Post a Comment