Actor
私が取り組んでいる新しいものが予期しないメッセージをどのように処理するかをテストしています。GibberishException
これらの場合は a がスローされると断言したいと思います。これまでのテストと実装は次のとおりです。
テスト:
"""throw a GibberishException for unrecognized messages""" in {
//define a service that creates gibberish-speaking repositories
val stubs = new svcStub(
actorOf(new Actor{
def receive = { case _ => {
self.channel ! "you're savage with the cabbage"
}
}
})
)
val model = actorOf(new HomeModel(stubs.svc,stubs.store))
val supervisor = Supervisor(
SupervisorConfig(
OneForOneStrategy(List(classOf[Exception]), 3, 1000),
Supervise(model,Permanent) :: Nil
)
)
try{
intercept[GibberishException] {
supervisor.start
model !! "plan"
}
} finally {
supervisor.shutdown
}
stubs.store.plan should equal (null)
stubs.svcIsOpen should be (false)
}
実装:
class HomeModel(service: PlanService, store: HomeStore)
extends Actor {
private val loaderRepo = service.getRepo()
private var view: Channel[Any] = null
override def postStop() = {
service.close()
}
def receive = {
case "plan" => {
view=self.channel
loaderRepo ! LoadRequest()
}
case p: Plan => {
store.plan=p
view ! store.plan
}
case _ => throw new GibberishException(_)
}
}
ただし、テストを実行すると、例外の詳細がSupervisor
確立されますが、ログを記録したり、型をテストしたりする方法がわかりません。ここでスーパーバイザーから例外の詳細を取得できるようにしたいので、テストでそれらを再スローしてインターセプトできます。テスト メソッド以外では、実行中のアプリの UI で例外の性質を報告したい場合に、これが役立つと想像できます。それが起こったときからこれを取得する方法はありSupervisor
ますか?