@@ -54,6 +54,9 @@ object RememberEntitiesFailureSpec {
5454 context.stop(self)
5555 case " graceful-stop" =>
5656 context.parent ! ShardRegion .Passivate (" stop" )
57+ case " incarnation" =>
58+ // Don't do this at home, kids...
59+ sender() ! self
5760 case msg => sender() ! msg
5861 }
5962 }
@@ -395,6 +398,53 @@ class RememberEntitiesFailureSpec
395398 system.stop(sharding)
396399 }
397400 }
401+
402+ " neither restart entity nor crash when entity passivates after being eagerly restarted" in {
403+ val shardingSettings = ClusterShardingSettings (system).withRememberEntities(true )
404+
405+ var sharding : ActorRef = null
406+ val probe = TestProbe ()
407+ implicit val sender : ActorRef = probe.ref
408+
409+ val spawnProbe = TestProbe ()
410+ val props = Props [EntityActor ] {
411+ spawnProbe.ref.tell(" spawned" , ActorRef .noSender)
412+ new EntityActor ()
413+ }
414+
415+ sharding = ClusterSharding (system).start(
416+ " failStartPassivate" ,
417+ props,
418+ shardingSettings,
419+ extractEntityId,
420+ extractShardId,
421+ ShardAllocationStrategy .leastShardAllocationStrategy(absoluteLimit = 1 , relativeLimit = 0.1 ),
422+ " graceful-stop" )
423+
424+ sharding ! EntityEnvelope (1 , " incarnation" )
425+ spawnProbe.expectMsg(" spawned" )
426+ var currentIncarnation = probe.receiveN(1 ).head.asInstanceOf [ActorRef ]
427+
428+ probe.watch(currentIncarnation)
429+ currentIncarnation ! " stop"
430+ probe.expectTerminated(currentIncarnation)
431+ // The restart timer is active
432+ currentIncarnation = null
433+
434+ // restart the entity early
435+ sharding ! EntityEnvelope (1 , " incarnation" )
436+ spawnProbe.expectMsg(" spawned" )
437+ sharding ! EntityEnvelope (1 , " graceful-stop" )
438+ currentIncarnation = probe.receiveN(1 ).head.asInstanceOf [ActorRef ]
439+
440+ probe.watch(currentIncarnation)
441+ probe.expectTerminated(currentIncarnation)
442+ // entity is now passivated
443+
444+ probe.watch(sharding)
445+ spawnProbe.expectNoMessage(1 .second)
446+ probe.expectNoMessage(1 .second)
447+ }
398448 }
399449
400450}
0 commit comments