Hi Carsten,
9 maj 2014 kl. 14:50 skrev Carsten Saathoff <[email protected]>:
> Hi,
>
> Am Freitag, 9. Mai 2014 13:34:50 UTC+2 schrieb Konrad Malawski:
> How about extracting the actor’s behaviour to a trait, and test that trait
> for the expected throw behaviour using plain old ScalaTest
> `intercept[Exception] { … }`, would it make sense in your case or are the
> interactions “very relying on the thing being an actor”?
>
> right, that's an option I did not think of before. I think that could work.
>
> However, you actually got me thinking about my particular design and whether
> a thrown Exception should be part of the "API" of an actor at all. Maybe the
> fact that I can' properly test this is indeed just a consequence of a bad
> design in that particular case. I assume that's what you meant in your first
> response with "you usually don't interact with actors in that way"?
The failure modes of an actor do make sense to view as part of its API, it is
something the supervisor will have to know about and prepared to handle (or
escalate). Therefore I agree with the sentiment that it should be testable as
well. What I use is what I call a StepParent actor that looks like this:
class StepParent(target: ActorRef) extends Actor {
override val supervisorStrategy = OneForOneStrategy() {
case thr: Throwable => target ! thr; Restart // or make it
configurable/controllable during the test
}
def receive = {
case p: Props => sender ! context.actorOf(p, "child")
}
}
... // in a test
val parent = system.actorOf(Props(new StepParent(testActor)), "stepParent")
parent ! Props(...) // for the actor under test
val subject = expectMsgType[ActorRef]
// and now test the subject
Regards,
Roland
>
> Thanks so far!
>
> Carsten
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.