Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

could not find implicit value for parameter system: akka.actor.ActorSystem

Tags:

scala

akka

actor

I am creating a unit test case for an Akka Actor using TestActorRef.

def actorRefFactory = context
        implicit def executionContext = actorRefFactory.dispatcher
        implicit val OutputActor = actorRefFactory.actorOf(Props[OutputActor], "OutputActor")

        val actorRef = TestActorRef[OutputActor]
        val actor = actorRef.underlyingActor

Getting the following error in creation of actorRef:

- could not find implicit value for parameter system: akka.actor.ActorSystem
    - not enough arguments for method apply: (implicit t: 
     scala.reflect.ClassTag[org.musigma.muhpc.OutputActor], implicit system: 
     akka.actor.ActorSystem)akka.testkit.TestActorRef[org.musigma.muhpc.OutputActor] in object 
     TestActorRef. Unspecified value parameter system.

I am very new to this. Kindly help.

like image 725
Piyush Shrivastava Avatar asked Feb 04 '16 13:02

Piyush Shrivastava


1 Answers

All instances of actors, TestActorRef or actual real instances, need an ActorSystem to reside in. The methods that instantiate and start actors (again, test or otherwise) require an implicit ActorSystem to be in scope so that the underlying code creating that actor knows where to put it.

So, taking that into account, you just need to make sure that you add a line of code like this at the start of your test code:

implicit val system = ActorSystem()
like image 97
cmbaxter Avatar answered Oct 17 '22 09:10

cmbaxter