2016-12-07 127 views
1

我有以下測試:沒有匹配的構造函數類的發現參數[]

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個參數構建我的actor(這應該是它所需要的)。

+0

? –

+0

'dispatch' http://dispatch.databinder.net/Dispatch.html – octavian

回答

0

我不使用SPEC2,但這樣的代碼是一個HTTP客戶端您使用的工作與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")) 
    } 
} 
相關問題