scala - Actor not catching exception in Test even if thrown -


my actor looks

object logprocessoractor {   def props(f: () => unit): props = props(new logprocessoractor(f)) }  class logprocessoractor(f: () => unit) extends actor actorlogging {   def receive = loggingreceive {     case startlogreaderdisruptor => f()       sender ! startedlogreaderdisruptor   } } 

and test looks

  must "fail method throws exception" in {     val f: () => unit = () => 2/0     val logprocessorref = testactorref[logprocessoractor](logprocessoractor.props(f), name = "logprocessorsad")     intercept[arithmeticexception] {       logprocessorref ! startlogreaderdisruptor     }   } 

i see in logs exception thrown

[debug] [06/02/2015 19:25:44.598] [scalatest-run] [eventstream(akka://logprocessoractorsystem)] logger log1-slf4jlogger started [debug] [06/02/2015 19:25:44.599] [scalatest-run] [eventstream(akka://logprocessoractorsystem)] default loggers started 02 jun 2015 19:25:44,601 [debug] [logprocessoractorsystem-akka.actor.default-dispatcher-3] akka.event.eventstream| logger log1-slf4jlogger started 02 jun 2015 19:25:44,603 [debug] [logprocessoractorsystem-akka.actor.default-dispatcher-3] akka.event.eventstream| default loggers started02 jun 2015 19:25:44,782 [error] [logprocessoractorsystem-akka.actor.default-dispatcher-3] akka.actor.oneforonestrategy| / 0 java.lang.arithmeticexception: / 0     @ com.shn.lp.logprocessoractorspec$$anonfun$3$$anonfun$4.apply$mcv$sp(logprocessoractorspec.scala:18)     @ com.shn.lp.logprocessoractor$$anonfun$receive$1.applyorelse(logprocessoractor.scala:16)     @ akka.actor.actor$class.aroundreceive(actor.scala:467)     @ com.shn.lp.logprocessoractor.aroundreceive(logprocessoractor.scala:14)     @ akka.actor.actorcell.receivemessage(actorcell.scala:516) 

but still test fails

expected exception java.lang.arithmeticexception thrown, no exception thrown. scalatestfailurelocation: com.shn.lp.logprocessoractorspec$$anonfun$3 @ (logprocessoractorspec.scala:20) org.scalatest.exceptions.testfailedexception: expected exception java.lang.arithmeticexception thrown, no exception thrown. 

i tried strategy mentioned in docs, still same result.

what doing incorrect?

an uncaught exception thrown in actor's receive block not handled sender. handled according actor's supervision hierarchy. parent actor deal child according supervisor strategy.

this covered in actors , exceptions section of documentation: http://doc.akka.io/docs/akka/2.3.11/scala/actors.html#actors_and_exceptions


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -