Ok after reading the documentation which says :
*The supervisor itself is supervised by the top-level actor provided by
the ActorSystem, which has the default policy to restart in case of
all Exception cases (with the notable exceptions
of ActorInitializationException and ActorKilledException). Since the
default directive in case of a restart is to kill all children, we expected
our poor child not to survive this failure.*
So I change my code to do not override preStart, postStart and let the
top-level actor use the default strategy. Now I have this code :
case class ActorConsumer() extends Actor with ActorLogging {
var x : Int = 0
def receive = {
case y : Int =>
println("receive = " + y)
x = x + y
println("x = " + this.x)
case LetItCrash =>
sender ! x
throw new Exception
case Get => sender() ! x
}
}
class TestResumeActor
extends TestKit(ActorSystem("foo"))
with ImplicitSender
with WordSpecLike
with Matchers
with BeforeAndAfterAll {
override def afterAll() = {
TestKit.shutdownActorSystem(system)
}
"An actor consumer" must {
"get 1 even exceptions are throws" in {
val actorRef = TestActorRef[ActorConsumer]
actorRef ! 1
actorRef ! LetItCrash
expectMsg(1)
actorRef ! Get
expectMsg(1)
}
}
}
The test fails again and I didn't defined a fail over strategy like in my
first post. Also, because I'm in a test environment, do I need to do
something special when create a child of actor system ?
Le jeudi 12 janvier 2017 14:41:11 UTC+1, Konrad Malawski a écrit :
>
>
> On Thu, Jan 12, 2017 at 2:31 PM, Kilic Ali-Firat <[email protected]
> <javascript:>> wrote:
>
>>
>> override def supervisorStrategy: SupervisorStrategy =
>> OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minutes) {
>> case _ : Exception => Resume
>> }
>>
>
> The supervision strategy must be in the *parent* of this actor.
> You're not setting your "own" strategy, your parent is handling it for it.
>
> What you've done here has effect for any children of this Actor, not for
> itself.
> Read up about spawning child actors.
>
>
> --
> Cheers,
> Konrad 'ktoso' Malawski
> Akka <http://akka.io/> @ Typesafe <http://typesafe.com/>
>
--
>>>>>>>>>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.