测试 Actor 时,Scala 规范不会退出
我正在尝试使用 scala 规范测试一些演员。我在 IDEA 或 Maven(作为 junit)中运行测试,但它没有退出。查看代码,我的测试已完成,但一些内部线程(调度程序)仍在徘徊。我怎样才能完成测试?
I'm trying to test some actors using scala specs. I run the test in IDEA or Maven (as junit) and it does not exit. Looking at the code, my test finished, but some internal threads (scheduler) are hanging around. How can I make the test finish?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,这只能通过强制关闭 Actor 框架的调度程序来实现:
但是,调度程序的底层实现最近在补丁版本中发生了变化,因此这可能会有所不同,或者与您所在的版本不太兼容。在2.7.7中,默认调度程序似乎是
scala.actors.FJTaskScheduler2
的一个实例,这种方法应该适用,但是如果您最终得到一个SingleThreadedScheduler
它不会,因为shutdown
方法是无操作只有当你的参与者当时没有等待
react
时,这才会起作用Currently this is only possible by causing the actor framework's scheduler to forcibly shut down:
However, the underlying implementation of the scheduler has been changing in patch-releases lately, so this may be different, or not quite work with the version you are on. In 2.7.7 the default scheduler appears to be an instance of
scala.actors.FJTaskScheduler2
for which this approach should work, however if you end up with aSingleThreadedScheduler
it will not, as theshutdown
method is a no-opThis will only work if your actors are not waiting on a
react
at that time