【问题标题】:Spray route testing with Akka TestProbe使用 Akka TestProbe 进行喷涂路线测试
【发布时间】:2015-03-18 00:48:34
【问题描述】:

在我的 Spray 路线中,我委托一个 actor 来处理请求。 RequestContext 在消息中发送给那个演员。

path("mypath") {
  parameters("thing".as[String]) { thing => ctx =>
    myActor ! ProcessThingAndResondToContext(thing, ctx)
  }
}

在我的测试中,我用TestProbe 代替了actor,因为actor 的处理成本很高。

class MySpec extends Specification with Specs2RouteTest with ScalaCheck with MyService {
  val testProbe = TestProbe()
  override val myActor = testProbe.ref

  def is = s2"""
    it should $doTheRightThing
  """

  def doTheRightThing = {
    Get(s"/mypath?thing=fruit") ~> route ~> check {
      testProbe.expectMsgClass(classOf[ProcessThingAndResondToContext])
      status mustEqual StatusCodes.Success
    }
  }

此规范失败,因为没有 status。 TestProbe 什么都不做,因此 ctx 从未得到响应。

Request was neither completed nor rejected within 1 second

status mustEqual StatusCodes.Success 行对我的测试并不重要,但我无法删除它,因为那时规范无法编译 - 该方法不再作为 MatchResult 进行类型检查。

如何测试委托给actor的路由?

【问题讨论】:

    标签: scala spray specs2 spray-test akka-testkit


    【解决方案1】:

    我没有解决问题,但通过使用TestActorRef 而不是TestProbe 解决了我的问题。然后我可以指定一个简化的行为并仍然回复ctx

    【讨论】:

      猜你喜欢
      • 2016-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多