diff --git a/akka-cluster/src/main/scala/akka/cluster/Cluster.scala b/akka-cluster/src/main/scala/akka/cluster/Cluster.scala index ecb7160833..af6d88371e 100644 --- a/akka-cluster/src/main/scala/akka/cluster/Cluster.scala +++ b/akka-cluster/src/main/scala/akka/cluster/Cluster.scala @@ -406,7 +406,8 @@ class Cluster(val system: ExtendedActorSystem) extends Extension { /** * The supplied thunk will be run, once, when current cluster member is `Removed`. * If the cluster has already been shutdown the thunk will run on the caller thread immediately. - * Typically used together `cluster.leave(cluster.selfAddress)` and then `system.terminate()`. + * If this is called "at the same time" as `shutdown()` there is a possibility that the the thunk + * is not invoked. It's often better to use [[akka.actor.CoordinatedShutdown]] for this purpose. */ def registerOnMemberRemoved[T](code: => T): Unit = registerOnMemberRemoved(new Runnable { override def run(): Unit = code }) @@ -414,7 +415,8 @@ class Cluster(val system: ExtendedActorSystem) extends Extension { /** * Java API: The supplied thunk will be run, once, when current cluster member is `Removed`. * If the cluster has already been shutdown the thunk will run on the caller thread immediately. - * Typically used together `cluster.leave(cluster.selfAddress)` and then `system.terminate()`. + * If this is called "at the same time" as `shutdown()` there is a possibility that the the thunk + * is not invoked. It's often better to use [[akka.actor.CoordinatedShutdown]] for this purpose. */ def registerOnMemberRemoved(callback: Runnable): Unit = { if (_isTerminated.get()) diff --git a/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala b/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala index b3e2c78350..1155c5f2cb 100644 --- a/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala +++ b/akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala @@ -137,17 +137,12 @@ class ClusterSpec extends AkkaSpec(ClusterSpec.config) with ImplicitSender { // this should be the last test step, since the cluster is shutdown "publish MemberRemoved when shutdown" in { - val callbackProbe = TestProbe() - cluster.registerOnMemberRemoved(callbackProbe.ref ! "OnMemberRemoved") - cluster.subscribe(testActor, classOf[ClusterEvent.MemberRemoved]) // first, is in response to the subscription expectMsgClass(classOf[ClusterEvent.CurrentClusterState]) cluster.shutdown() expectMsgType[ClusterEvent.MemberRemoved].member.address should ===(selfAddress) - - callbackProbe.expectMsg("OnMemberRemoved") } "allow join and leave with local address" in {