Akka 액터 모델에서 테스트 방법을 배우고 있습니다. Akka 설명서에서 일부 코드를 실행하려고했습니다. 다음 코드를 실행하면 혼란스러운 오류가 발생합니다. JDK 1.8.121, macOS 및 Scala 2.12를 사용하고 있습니다.Akka 설명서의 테스트 코드가 이상하게 실행됩니다.
Akka documentation에서 코드 :
package TestKitDemo
import akka.actor.ActorSystem
import akka.actor.Status.Success
import akka.testkit.{TestKit, TestProbe}
import org.scalatest.{BeforeAndAfterAll, WordSpecLike}
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import scala.util.Try
class ReplyDemo extends TestKit(ActorSystem("Testsystem")) with WordSpecLike
with BeforeAndAfterAll{
// import system.dispatcher
override protected def afterAll(): Unit = {
shutdown(system)
}
implicit val timeout = Timeout(2 seconds)
"reply" should {
"same" in {
val probe = TestProbe()
val future = probe.ref ? "hello"
probe.expectMsg(0 millis, "hello") // TestActor runs on CallingThreadDispatcher
probe.reply("world")
// error
assert(future.isCompleted && future.value == Some(Success("world")))
// correct
// assert(future.isCompleted && future.value.get == Try("world"))
}
}
}
내가 assert
두 가지 유형의 사용 : 나는 내 자신의 컴퓨터에서 테스트를 설정
val probe = TestProbe()
val future = probe.ref ? "hello"
probe.expectMsg(0 millis, "hello") // TestActor runs on CallingThreadDispatcher
probe.reply("world")
assert(future.isCompleted && future.value == Some(Success("world")))
하나는 Akka documentation의 코드는 다른 하나는 Try
을 사용한 자기 평등 테스트입니다.
나는 Try
에 대한 아이디어가 있습니다. 내 지식에 따라 Try
은 Success
또는 Failure
이 될 수있는 유형입니다.
테스트 오류
이하이다future.isCompleted was true, but Some(Success("world")) did not equal Some(Success(world))
ScalaTestFailureLocation: TestKitDemo.ReplyDemo at (ReplyDemo.scala:44)
Expected :Some(Success(world))
Actual :future.isCompleted was true, but Some(Success("world"))
Some(Success("world"))
가 Some(Success(world))
같지 않다. 뭐가 문제 야? 그들은 평등해야합니다. 당신이 akka.actor.Status.Success
대신 scala.util.Success
에 일치하도록 노력하고 있기 때문에