How to test that Akka actor was created in Scala -


i'm trying write test verify actor below creating heartbeatexpireworker , heartbeataccepter, have no idea how it.

first thinking use mockhito mock or spy in place of context , verify called actorof, can't figure out way inject context without breaking akka testing framework.

then, thinking send identify message workers verify exist. occurred me that wouldn't work either because akka testkit doesn't seem create children actors of actor under test. can take in testprobes can stand in neighboring actors.

class heartbeatpumpworker(chatservice: chatservice, target: heartbeatmessagecmd) extends actor actorlogging workersreference {    val heartbeatinterval = chatservice.getheartbeatinterval    val tick = context.system.scheduler.schedule(0 millis, heartbeatinterval millis, self, sendheartbeat(target))    override def poststop() = tick.cancel()    def receive = {     case sendheartbeat(command: heartbeatmessagecmd) =>       log.debug("sending heartbeat")       //send heartbeat gwt       val usertarget = networkworker.buildeventusertarget(command.geteventcode, command.getuser)        val uuid: string = uuid.randomuuid().tostring       val freshcommand = new heartbeatmessagecmd(command.getuser, command.geteventcode, uuid, command.getusersession)       networkworker ! networkbroadcast(usertarget, freshcommand)        val heartbeatid: string = freshcommand.getuuid       //create expirer       val heartbeatexpireworkerref = context.actorof(heartbeatexpireworker.props(chatservice, freshcommand),         heartbeatexpireworker.name(heartbeatid))       val heartbeataccepterref = context         .actorof(heartbeatacceptworker.props(chatservice, freshcommand), heartbeatacceptworker.name(heartbeatid))        //record heartbeat         chatservice.savesentheartbeat(heartbeatid, freshcommand.getusersession, freshcommand.geteventcode,           freshcommand.getuser,         freshcommand.gettimecmdgenerated)     case _ =>       log.error("pumper received unknown message.  shouldn't happen " + sender.path.tostring)       self ! poisonpill   }  }   object heartbeatpumpworker {   def name(eventcode: string, user: string, sessionid: string) = f"heartbeatpumpworker-$eventcode-$user-$sessionid"    def path(eventcode: string, user: string, sessionid: string) : string = {     eventworker.path + "/" + name(eventcode, user, sessionid)   }    def props(chatservice: chatservice, heartbeatmsgcmd: heartbeatmessagecmd) = {     props(classof[heartbeatpumpworker], chatservice, heartbeatmsgcmd)   } } 

inject props children (e.g. heartbeatacceptworker.props) in constructor of parent heartbeatpumpworker. pass props want test. let parent instantiate children via provided props. interact children. last part dependent on data flow. instance if parent shields children, delegates messages them, send message parent. if children talk each other use test probes or similar.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -