scala - Akka Actor restarts after exception during Unit test -
my actor
looks
import akka.actor.status.failure import akka.actor.{actor, actorlogging, props} import akka.event.loggingreceive object runner { def props(race: race) = props(classof[runner], race) } class runner(race: race) extends actor actorlogging { override def receive: receive = loggingreceive { case start => sender ! "ok" log.debug("running...") thread.sleep(10) throw new runtimeexception("marathonrunner tired") case failure(throwable) => throw throwable case stop => log.debug("stopping runner") context.stop(self) } }
and test looks
import akka.actor.{terminated, actorsystem} import akka.testkit.{implicitsender, testactorref, testkit} import org.scalatest._ import scala.concurrent.duration._ class runnerspec extends testkit(actorsystem("testsystem")) wordspeclike mustmatchers implicitsender { "must fail exception" in { val runnerref = testactorref(new runner(new marathon), "testrunnerexception") runnerref ! start expectmsg("ok") watch(runnerref) expectmsg(20 millis, terminated) } }
- however, see in logs fails since, once
runtimeexception
occurs,actor
restarted. - as see
actor
not definesupervisorstrategy
, parent
class coach() extends actor actorlogging { val runner = context.actorof(runner.props(new marathon).withdispatcher("my-pinned-dispatcher"), "runner") override def supervisorstrategy: supervisorstrategy = oneforonestrategy(maxnrofretries = 2, withintimerange = 5 seconds) { case _: runtimeexception => sender ! start restart }
but not testing supervisor
here, infact supervisor not part of test.
what going wrong here?
log
testing started @ 11:48 ... [debug] [06/02/2015 11:48:08.068] [scalatest-run] [eventstream(akka://testsystem)] logger log1-logging$defaultlogger started [debug] [06/02/2015 11:48:08.069] [scalatest-run] [eventstream(akka://testsystem)] default loggers started [debug] [06/02/2015 11:48:08.072] [testsystem-akka.actor.default-dispatcher-4] [akka://testsystem/system] supervising actor[akka://testsystem/system/deadletterlistener#58458639] [debug] [06/02/2015 11:48:08.075] [testsystem-akka.actor.default-dispatcher-4] [akka://testsystem/system/deadletterlistener] started (akka.event.deadletterlistener@7b2fe415) [debug] [06/02/2015 11:48:08.089] [testsystem-akka.actor.default-dispatcher-5] [akka://testsystem/system/testactor1] started (akka.testkit.testactor@6242009b) [debug] [06/02/2015 11:48:08.090] [testsystem-akka.actor.default-dispatcher-5] [akka://testsystem/system] supervising actor[akka://testsystem/system/testactor1#1776291392][debug] [06/02/2015 11:48:08.249] [testsystem-akka.actor.default-dispatcher-4] [akka://testsystem/user] supervising testactor[akka://testsystem/user/testrunnerexception] [debug] [06/02/2015 11:48:08.250] [scalatest-run-running-runnerspec] [akka://testsystem/user/testrunnerexception] started (com.learner.ahka.ruforever.runner@afdd280) [debug] [06/02/2015 11:48:08.251] [scalatest-run-running-runnerspec] [akka://testsystem/user/testrunnerexception] received handled message start [debug] [06/02/2015 11:48:08.254] [scalatest-run-running-runnerspec] [akka://testsystem/user/testrunnerexception] running... [debug] [06/02/2015 11:48:08.267] [scalatest-run-running-runnerspec] [akka://testsystem/user/testrunnerexception] watched actor[akka://testsystem/system/testactor1#1776291392] [error] [06/02/2015 11:48:08.269] [testsystem-akka.actor.default-dispatcher-5] [akka://testsystem/user/testrunnerexception] marathonrunner tired java.lang.runtimeexception: marathonrunner tired @ com.learner.ahka.ruforever.runner$$anonfun$receive$1.applyorelse(runner.scala:18) @ scala.runtime.abstractpartialfunction.apply(abstractpartialfunction.scala:36) @ akka.event.loggingreceive.apply(loggingreceive.scala:62) @ akka.event.loggingreceive.apply(loggingreceive.scala:50) @ scala.partialfunction$class.applyorelse(partialfunction.scala:123) @ akka.event.loggingreceive.applyorelse(loggingreceive.scala:50) @ akka.actor.actor$class.aroundreceive(actor.scala:467) @ com.learner.ahka.ruforever.runner.aroundreceive(runner.scala:11) @ akka.actor.actorcell.receivemessage(actorcell.scala:516) @ akka.actor.actorcell.invoke(actorcell.scala:487) @ akka.testkit.callingthreaddispatcher.process$1(callingthreaddispatcher.scala:251) @ akka.testkit.callingthreaddispatcher.runqueue(callingthreaddispatcher.scala:284) @ akka.testkit.callingthreaddispatcher.dispatch(callingthreaddispatcher.scala:208) @ akka.actor.dungeon.dispatch$class.sendmessage(dispatch.scala:123) @ akka.actor.actorcell.sendmessage(actorcell.scala:369) @ akka.actor.cell$class.sendmessage(actorcell.scala:290) @ akka.actor.actorcell.sendmessage(actorcell.scala:369) @ akka.actor.localactorref.$bang(actorref.scala:384) @ com.learner.ahka.ruforever.runnerspec$$anonfun$1.apply$mcv$sp(runnerspec.scala:15) @ com.learner.ahka.ruforever.runnerspec$$anonfun$1.apply(runnerspec.scala:13) @ com.learner.ahka.ruforever.runnerspec$$anonfun$1.apply(runnerspec.scala:13) @ org.scalatest.transformer$$anonfun$apply$1.apply$mcv$sp(transformer.scala:22) @ org.scalatest.outcomeof$class.outcomeof(outcomeof.scala:85) @ org.scalatest.outcomeof$.outcomeof(outcomeof.scala:104) @ org.scalatest.transformer.apply(transformer.scala:22) @ org.scalatest.transformer.apply(transformer.scala:20) @ org.scalatest.wordspeclike$$anon$1.apply(wordspeclike.scala:953) @ org.scalatest.suite$class.withfixture(suite.scala:1122) @ com.learner.ahka.ruforever.runnerspec.withfixture(runnerspec.scala:9) @ org.scalatest.wordspeclike$class.invokewithfixture$1(wordspeclike.scala:950) @ org.scalatest.wordspeclike$$anonfun$runtest$1.apply(wordspeclike.scala:962) @ org.scalatest.wordspeclike$$anonfun$runtest$1.apply(wordspeclike.scala:962) @ org.scalatest.superengine.runtestimpl(engine.scala:306) @ org.scalatest.wordspeclike$class.runtest(wordspeclike.scala:962) @ com.learner.ahka.ruforever.runnerspec.runtest(runnerspec.scala:9) @ org.scalatest.wordspeclike$$anonfun$runtests$1.apply(wordspeclike.scala:1021) @ org.scalatest.wordspeclike$$anonfun$runtests$1.apply(wordspeclike.scala:1021) @ org.scalatest.superengine$$anonfun$traversesubnodes$1$1.apply(engine.scala:413) @ org.scalatest.superengine$$anonfun$traversesubnodes$1$1.apply(engine.scala:401) @ scala.collection.immutable.list.foreach(list.scala:381) @ org.scalatest.superengine.traversesubnodes$1(engine.scala:401) @ org.scalatest.superengine.org$scalatest$superengine$$runtestsinbranch(engine.scala:396) @ org.scalatest.superengine.runtestsimpl(engine.scala:483) @ org.scalatest.wordspeclike$class.runtests(wordspeclike.scala:1021) @ com.learner.ahka.ruforever.runnerspec.runtests(runnerspec.scala:9) @ org.scalatest.suite$class.run(suite.scala:1424) @ com.learner.ahka.ruforever.runnerspec.org$scalatest$wordspeclike$$super$run(runnerspec.scala:9) @ org.scalatest.wordspeclike$$anonfun$run$1.apply(wordspeclike.scala:1067) @ org.scalatest.wordspeclike$$anonfun$run$1.apply(wordspeclike.scala:1067) @ org.scalatest.superengine.runimpl(engine.scala:545) @ org.scalatest.wordspeclike$class.run(wordspeclike.scala:1067) @ com.learner.ahka.ruforever.runnerspec.run(runnerspec.scala:9) @ org.scalatest.tools.suiterunner.run(suiterunner.scala:55) @ org.scalatest.tools.runner$$anonfun$dorunrunrundadorunrun$3.apply(runner.scala:2563) @ org.scalatest.tools.runner$$anonfun$dorunrunrundadorunrun$3.apply(runner.scala:2557) @ scala.collection.immutable.list.foreach(list.scala:381) @ org.scalatest.tools.runner$.dorunrunrundadorunrun(runner.scala:2557) @ org.scalatest.tools.runner$$anonfun$runoptionallywithpassfailreporter$2.apply(runner.scala:1044) @ org.scalatest.tools.runner$$anonfun$runoptionallywithpassfailreporter$2.apply(runner.scala:1043) @ org.scalatest.tools.runner$.withclassloaderanddispatchreporter(runner.scala:2722) @ org.scalatest.tools.runner$.runoptionallywithpassfailreporter(runner.scala:1043) @ org.scalatest.tools.runner$.run(runner.scala:883) @ org.scalatest.tools.runner.run(runner.scala) @ org.jetbrains.plugins.scala.testingsupport.scalatest.scalatestrunner.runscalatest2(scalatestrunner.java:138) @ org.jetbrains.plugins.scala.testingsupport.scalatest.scalatestrunner.main(scalatestrunner.java:28) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140) [debug] [06/02/2015 11:48:08.269] [testsystem-akka.actor.default-dispatcher-5] [akka://testsystem/user/testrunnerexception] restarting [debug] [06/02/2015 11:48:08.272] [testsystem-akka.actor.default-dispatcher-5] [akka://testsystem/user/testrunnerexception] restarted assertion failed: timeout (20 milliseconds) during expectmsg while waiting terminated java.lang.assertionerror: assertion failed: timeout (20 milliseconds) during expectmsg while waiting terminated @ scala.predef$.assert(predef.scala:165) @ akka.testkit.testkitbase$class.expectmsg_internal(testkit.scala:338) @ akka.testkit.testkitbase$class.expectmsg(testkit.scala:324) @ akka.testkit.testkit.expectmsg(testkit.scala:718) @ com.learner.ahka.ruforever.runnerspec$$anonfun$1.apply$mcv$sp(runnerspec.scala:18) @ com.learner.ahka.ruforever.runnerspec$$anonfun$1.apply(runnerspec.scala:13) @ com.learner.ahka.ruforever.runnerspec$$anonfun$1.apply(runnerspec.scala:13) @ org.scalatest.transformer$$anonfun$apply$1.apply$mcv$sp(transformer.scala:22) @ org.scalatest.outcomeof$class.outcomeof(outcomeof.scala:85) @ org.scalatest.outcomeof$.outcomeof(outcomeof.scala:104) @ org.scalatest.transformer.apply(transformer.scala:22) @ org.scalatest.transformer.apply(transformer.scala:20) @ org.scalatest.wordspeclike$$anon$1.apply(wordspeclike.scala:953) @ org.scalatest.suite$class.withfixture(suite.scala:1122) @ com.learner.ahka.ruforever.runnerspec.withfixture(runnerspec.scala:9) @ org.scalatest.wordspeclike$class.invokewithfixture$1(wordspeclike.scala:950) @ org.scalatest.wordspeclike$$anonfun$runtest$1.apply(wordspeclike.scala:962) @ org.scalatest.wordspeclike$$anonfun$runtest$1.apply(wordspeclike.scala:962) @ org.scalatest.superengine.runtestimpl(engine.scala:306) @ org.scalatest.wordspeclike$class.runtest(wordspeclike.scala:962) @ com.learner.ahka.ruforever.runnerspec.runtest(runnerspec.scala:9) @ org.scalatest.wordspeclike$$anonfun$runtests$1.apply(wordspeclike.scala:1021) @ org.scalatest.wordspeclike$$anonfun$runtests$1.apply(wordspeclike.scala:1021) @ org.scalatest.superengine$$anonfun$traversesubnodes$1$1.apply(engine.scala:413) @ org.scalatest.superengine$$anonfun$traversesubnodes$1$1.apply(engine.scala:401) @ scala.collection.immutable.list.foreach(list.scala:381) @ org.scalatest.superengine.traversesubnodes$1(engine.scala:401) @ org.scalatest.superengine.org$scalatest$superengine$$runtestsinbranch(engine.scala:396) @ org.scalatest.superengine.runtestsimpl(engine.scala:483) @ org.scalatest.wordspeclike$class.runtests(wordspeclike.scala:1021) @ com.learner.ahka.ruforever.runnerspec.runtests(runnerspec.scala:9) @ org.scalatest.suite$class.run(suite.scala:1424) @ com.learner.ahka.ruforever.runnerspec.org$scalatest$wordspeclike$$super$run(runnerspec.scala:9) @ org.scalatest.wordspeclike$$anonfun$run$1.apply(wordspeclike.scala:1067) @ org.scalatest.wordspeclike$$anonfun$run$1.apply(wordspeclike.scala:1067) @ org.scalatest.superengine.runimpl(engine.scala:545) @ org.scalatest.wordspeclike$class.run(wordspeclike.scala:1067) @ com.learner.ahka.ruforever.runnerspec.run(runnerspec.scala:9) @ org.scalatest.tools.suiterunner.run(suiterunner.scala:55) @ org.scalatest.tools.runner$$anonfun$dorunrunrundadorunrun$3.apply(runner.scala:2563) @ org.scalatest.tools.runner$$anonfun$dorunrunrundadorunrun$3.apply(runner.scala:2557) @ scala.collection.immutable.list.foreach(list.scala:381) @ org.scalatest.tools.runner$.dorunrunrundadorunrun(runner.scala:2557) @ org.scalatest.tools.runner$$anonfun$runoptionallywithpassfailreporter$2.apply(runner.scala:1044) @ org.scalatest.tools.runner$$anonfun$runoptionallywithpassfailreporter$2.apply(runner.scala:1043) @ org.scalatest.tools.runner$.withclassloaderanddispatchreporter(runner.scala:2722) @ org.scalatest.tools.runner$.runoptionallywithpassfailreporter(runner.scala:1043) @ org.scalatest.tools.runner$.run(runner.scala:883) @ org.scalatest.tools.runner.run(runner.scala) @ org.jetbrains.plugins.scala.testingsupport.scalatest.scalatestrunner.runscalatest2(scalatestrunner.java:138) @ org.jetbrains.plugins.scala.testingsupport.scalatest.scalatestrunner.main(scalatestrunner.java:28) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140)
based on comment @cmbaxter, digged little bit , solved problem. had override supervisionstrategy
test not allow restart.
here test looks
class runnerspec extends testkit(actorsystem("testsystem")) flatspeclike mustmatchers implicitsender { behavior of "a marathon runner" must "must fail exception" in { val supervisorref = testactorref[dummysupervisor] val runnerref = testactorref(runner.props(new marathon), supervisorref, "runnerfail") runnerref ! start expectmsg("ok") watch(runnerref) expectterminated(runnerref, 10 millis) } } class dummysupervisor extends coach { override def supervisorstrategy: supervisorstrategy = oneforonestrategy() { case _: runtimeexception => stop } }
Comments
Post a Comment