在课堂上找不到匹配的构造函数[]



我有以下测试:

  it should "ask yarn about the running jobs" in new TestScope {
    val testSender: TestProbe = TestProbe()
    val testReceiver: TestProbe = TestProbe()
    val yarnActorRef = system.actorOf(YarnActor.props(testReceiver.ref))
    testSender.send(yarnActorRef, UpdateListOfJobs(Instant.now()))
    testReceiver.expectMsg(YarnJobStatus("Not running"))
  }

对于这个演员:

object YarnActor {
  trait Message
  case class UpdateListOfJobs(timeStamp: Instant) extends Message
  def props(stateActorRef: ActorRef) = Props(new YarnActor(stateActorRef))
}
class YarnActor(stateActorRef: ActorRef) extends Actor with ActorLogging {
  override def receive: Receive = {
    case UpdateListOfJobs(timeStamp) => {
      //check if the job is still running
      val address = url("someUrlAddress")
      val status: Future[String] = Await.ready(Http(address OK as.String), 1 second)
      status onComplete {
        case Success(message) => stateActorRef ! YarnJobStatus(message)
        case Failure(_) => stateActorRef ! YarnJobStatus("Not running")
      }
    }
  }
}

我得到了:

[info] - should ask yarn about the running jobs *** FAILED ***
[info]   java.lang.IllegalArgumentException: no matching constructor found on class myPackage.YarnActor for arguments []

为什么出现此错误?在伴随对象中,我正在用1个参数构造演员(应该是所有需要的)。

我不使用Spec2,但是类似的代码正在使用Scalatest

import akka.actor._
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import dispatch._
import org.joda.time.Instant
import org.scalatest.{FlatSpecLike, Matchers}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.{Failure, Success}

case class YarnJobStatus(message: String)
object YarnActor {
  trait Message
  case class UpdateListOfJobs(timeStamp: Instant) extends Message
  def props(stateActorRef: ActorRef) =
    Props(new YarnActor(stateActorRef))
}
class YarnActor(stateActorRef: ActorRef)
  extends Actor with ActorLogging {
  import Defaults._
  import YarnActor._
  override def receive: Receive = {
    case UpdateListOfJobs(timeStamp) => {
      //check if the job is still running
      val addr = url("http://127.0.0.1")
      val status: Future[String] = Await.ready(Http(addr OK as.String), 2 second)
      status onComplete {
        case Success(message) => stateActorRef ! YarnJobStatus(message)
        case Failure(_) => stateActorRef ! YarnJobStatus("Not running")
      }
    }
  }
}
class ActorSpec extends TestKit(ActorSystem("MySpec"))
  with ImplicitSender with FlatSpecLike with Matchers {
  it should "ask yarn about the running jobs" in {
      val testSender: TestProbe = TestProbe()
      val testReceiver: TestProbe = TestProbe()
      val yarnActorRef = system.actorOf(YarnActor.props(testReceiver.ref))
      testSender.send(yarnActorRef, YarnActor.UpdateListOfJobs(Instant.now()))
      testReceiver.expectMsg[YarnJobStatus](YarnJobStatus("Not running"))
    }
}