使用标量测试在 akka 中询问未来



我正在尝试运行一个简单的演员测试,它应该根据要求打印测试。未来还没有结束。

package test
import akka.actor.Actor.Receive
import akka.actor.{Actor, ActorSystem}
import akka.testkit.{TestActorRef, TestProbe, ImplicitSender, TestKit}
import akka.util.Timeout
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Matchers, WordSpecLike}
class TestSpecs(_system:ActorSystem)
  extends TestKit(_system)
  with ImplicitSender
  with WordSpecLike
  with Matchers {
  def this() = this(ActorSystem("test"))
  class TestTestTest extends Actor {
    override def receive: Receive = {
      case "test" =>  "test"
      case _ => "notest"
    }
  }
    val workerFSM = TestActorRef(new TestTestTest)
  "During initialization connection should" should {
    "have initial state as pre initialization" in {
        import scala.concurrent.duration.DurationInt
        implicit val timeout = Timeout(5.seconds)
        import akka.pattern.ask
        import system.dispatcher
        val f = workerFSM ? "test"
        println(f.isCompleted)
        f.map(x => {
          println("Hello")
        })
        expectMsg(2.seconds, "test")
    }
  }
}

是 akka 测试中未来的阻塞性质问题还是我错过了什么?

当你"问"一个演员什么时,那个演员必须回答,否则返回给原始调用者的未来将永远不会完成。 在您的情况下,TestTestTest永远不会回复,因此您将来在测试中的f将永远不会完成。

最新更新