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:
commit
750d5afee6
2 changed files with 38 additions and 12 deletions
|
|
@ -79,14 +79,36 @@ class DeferredSpec extends TypedSpec {
|
||||||
|
|
||||||
def `must stop when exception from factory`(): Unit = {
|
def `must stop when exception from factory`(): Unit = {
|
||||||
val probe = TestProbe[Event]("evt")
|
val probe = TestProbe[Event]("evt")
|
||||||
val behv = Actor.deferred[Command] { _ ⇒
|
val behv = Actor.deferred[Command] { ctx ⇒
|
||||||
probe.ref ! Started
|
val child = ctx.spawnAnonymous(Actor.deferred[Command] { _ ⇒
|
||||||
throw new RuntimeException("simulated exc from factory") with NoStackTrace
|
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)
|
probe.expectMsg(Started)
|
||||||
ref ! Ping
|
probe.expectMsg(Pong)
|
||||||
probe.expectNoMsg(100.millis)
|
}
|
||||||
|
|
||||||
|
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 = {
|
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 DeferredBehavior (stubbed, native)` extends StubbedTests with NativeSystem
|
||||||
object `A Restarter (stubbed, adapted)` extends StubbedTests with AdaptedSystem
|
object `A DeferredBehavior (stubbed, adapted)` extends StubbedTests with AdaptedSystem
|
||||||
|
|
||||||
object `A Restarter (real, native)` extends RealTests with NativeSystem
|
object `A DeferredBehavior (real, native)` extends RealTests with NativeSystem
|
||||||
object `A Restarter (real, adapted)` extends RealTests with AdaptedSystem
|
object `A DeferredBehavior (real, adapted)` extends RealTests with AdaptedSystem
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,16 +75,20 @@ import akka.util.OptionVal
|
||||||
a.SupervisorStrategy.Stop
|
a.SupervisorStrategy.Stop
|
||||||
}
|
}
|
||||||
|
|
||||||
override def preStart(): Unit =
|
override def preStart(): Unit = {
|
||||||
behavior = validateAsInitial(undefer(behavior, ctx))
|
behavior = validateAsInitial(undefer(behavior, ctx))
|
||||||
|
if (!isAlive(behavior)) context.stop(self)
|
||||||
|
}
|
||||||
|
|
||||||
override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
|
override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
|
||||||
Behavior.interpretSignal(behavior, ctx, PreRestart)
|
Behavior.interpretSignal(behavior, ctx, PreRestart)
|
||||||
behavior = Behavior.stopped
|
behavior = Behavior.stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
override def postRestart(reason: Throwable): Unit =
|
override def postRestart(reason: Throwable): Unit = {
|
||||||
behavior = validateAsInitial(undefer(behavior, ctx))
|
behavior = validateAsInitial(undefer(behavior, ctx))
|
||||||
|
if (!isAlive(behavior)) context.stop(self)
|
||||||
|
}
|
||||||
|
|
||||||
override def postStop(): Unit = {
|
override def postStop(): Unit = {
|
||||||
behavior match {
|
behavior match {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue