找不到参数上下文的隐含值:akka.actor.ActorContext

时间:2015-05-28 21:36:16

标签: scala unit-testing akka actor scalatest

我想使用TestActorRef为以下程序编写测试用例。嵌套的actor场景,但是当我尝试创建上下文时,我面临编译错误。请帮我解决问题。

主程序:

object TextCleaningScheduler extends App {

  val system = ActorSystem("cleanText")

  val projectsActor = system.actorOf( Props(classOf[DataByProjects]) )

  projectsActor ! ProcessDataByConnections(1,1)


}

case class ProcessDataByConnections( accID : Int, projectID : Int )

class DataByProjects extends Actor {
  def receive = {

    case ProcessDataByConnections( accID, projectID ) => {

      val dbName            = "some_example"
      val connectionStr     = "cassandra://IPaddress/" + dbName
      val elasticsearchIp   = "ipaddress"
      val elasticsearchPort = "9200"

      val dbObject = new DatabaseOperations(dbName,
        connectionStr,
        elasticsearchIp,
        elasticsearchPort
      )

      val query       = "{ \"query\" : { \"match\" : { \"project_info_mapping.project_id\" : " + projectID + " } } }"
      val fetchedData = dbObject.queryData("project_instance",query,"project_instance","data")
      var counter = 0
      //for ( row <- fetchedData) {
        val row = fetchedData(0)
        println(row)
        val conn              = row("project_instance_id")
        val textCleaningInfo  = row("text_cleaning")

        val tempConn = 3
        val queueName         = "RAWDATA_A" + accID + "_C" + tempConn


        var accInfo : Map[String, Any]   = Map( "accID" -> accID , "projectID" -> projectID, "conn" -> tempConn )
        accInfo        += ("textCleaning" -> textCleaningInfo, "wordsToRemove" ->  row("remove_words"), "findAndReplace" -> row("find_and_replace") )
        accInfo        += ("dataVariable" -> row("data_variable_name"), "dataLabel" -> row("data_variable_label") )

        val queueActor = context.actorOf(Props(classOf[GetAndPushQueue], accInfo ), "queue" + counter )

TestProgram:使用flatspec scalatest框架的内部测试类

    val actorRef = TestActorRef[DataByProjects]

    actorRef ! ProcessDataByConnections(1, 1)

    val accInfo =1

    val counter = 0

    *val context = actorRef.underlyingActor

   (this line i m getting error)  actorRef.forward("child" , context.context)*

信息:5/29/15 11:05 AM - 编译在17s 68ms内完成了2个错误和0个警告

Error:Error:line (32)could not find implicit value for parameter context: akka.actor.ActorContext
actorRef.forward()
                ^
Error:Error:line (32)not enough arguments for method forward: (implicit context: akka.actor.ActorContext)Unit.

未指定的值参数上下文。     actorRef.forward()                     ^

0 个答案:

没有答案
相关问题