Merge pull request #22935 from akka/wip-22934-fix-deferred-RK

Actor.deferred should stop when factory yields stopped, #22934
This commit is contained in:
Patrik Nordwall 2017-05-22 10:05:11 +02:00 committed by GitHub
commit 750d5afee6
2 changed files with 38 additions and 12 deletions

View file

@ -79,14 +79,36 @@ class DeferredSpec extends TypedSpec {
def `must stop when exception from factory`(): Unit = {
val probe = TestProbe[Event]("evt")
val behv = Actor.deferred[Command] { _
probe.ref ! Started
throw new RuntimeException("simulated exc from factory") with NoStackTrace
val behv = Actor.deferred[Command] { ctx
val child = ctx.spawnAnonymous(Actor.deferred[Command] { _
probe.ref ! Started
throw new RuntimeException("simulated exc from factory") with NoStackTrace
})
ctx.watch(child)
Actor.immutable[Command]((_, _) Actor.same).onSignal {
case (_, Terminated(`child`))
probe.ref ! Pong
Actor.stopped
}
}
val ref = start(behv)
start(behv)
probe.expectMsg(Started)
ref ! Ping
probe.expectNoMsg(100.millis)
probe.expectMsg(Pong)
}
def `must stop when deferred result it Stopped`(): Unit = {
val probe = TestProbe[Event]("evt")
val behv = Actor.deferred[Command] { ctx
val child = ctx.spawnAnonymous(Actor.deferred[Command](_ Actor.stopped))
ctx.watch(child)
Actor.immutable[Command]((_, _) Actor.same).onSignal {
case (_, Terminated(`child`))
probe.ref ! Pong
Actor.stopped
}
}
start(behv)
probe.expectMsg(Pong)
}
def `must create underlying when nested`(): Unit = {
@ -136,10 +158,10 @@ class DeferredSpec extends TypedSpec {
}
object `A Restarter (stubbed, native)` extends StubbedTests with NativeSystem
object `A Restarter (stubbed, adapted)` extends StubbedTests with AdaptedSystem
object `A DeferredBehavior (stubbed, native)` extends StubbedTests with NativeSystem
object `A DeferredBehavior (stubbed, adapted)` extends StubbedTests with AdaptedSystem
object `A Restarter (real, native)` extends RealTests with NativeSystem
object `A Restarter (real, adapted)` extends RealTests with AdaptedSystem
object `A DeferredBehavior (real, native)` extends RealTests with NativeSystem
object `A DeferredBehavior (real, adapted)` extends RealTests with AdaptedSystem
}

View file

@ -75,16 +75,20 @@ import akka.util.OptionVal
a.SupervisorStrategy.Stop
}
override def preStart(): Unit =
override def preStart(): Unit = {
behavior = validateAsInitial(undefer(behavior, ctx))
if (!isAlive(behavior)) context.stop(self)
}
override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
Behavior.interpretSignal(behavior, ctx, PreRestart)
behavior = Behavior.stopped
}
override def postRestart(reason: Throwable): Unit =
override def postRestart(reason: Throwable): Unit = {
behavior = validateAsInitial(undefer(behavior, ctx))
if (!isAlive(behavior)) context.stop(self)
}
override def postStop(): Unit = {
behavior match {