0
미래에 달려있는 배우에 대한 간단한 테스트를 작성하려고합니다. 여기에 완료하려면미래에 의존하는 배우 AKKA 배우들
import akka.actor.{ Actor, ActorSystem, Props }
import akka.testkit.{ ImplicitSender, TestKit }
import org.scalatest.{ BeforeAndAfterAll, WordSpecLike }
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
trait Provider {def get(s: String): Future[String] }
class MyActor(provider: Provider) extends Actor {
override def receive: Receive = {
case s: String ⇒
provider.get(s) map { result: String ⇒
sender() ! result
}
}
}
class FutureTest
extends TestKit(ActorSystem("Test"))
with ImplicitSender
with WordSpecLike
with BeforeAndAfterAll {
"MyActor" must {
"wait for the future" in {
val myref = system.actorOf(Props(
new MyActor((s) ⇒ Future { s })
))
myref ! "hello world"
expectMsg("hello world")
}
}
}
는 MSG는 미래를 기다리지 않습니다 기대 거의 자명의 코드는 다음과 같은 메시지와 함께 실패합니다
assertion failed: timeout (3 seconds) during expectMsg while waiting for hello world java.lang.AssertionError: assertion failed: timeout (3 seconds) during expectMsg while waiting for hello world
이 종류를 테스트하는 가장 좋은 방법은 무엇입니까 내 경우의 행동?
감사합니다.