parent
578f32d322
commit
f4fbbf9312
2 changed files with 36 additions and 3 deletions
|
|
@ -5,8 +5,10 @@
|
|||
package akka.actor.typed.scaladsl
|
||||
|
||||
import akka.Done
|
||||
import akka.actor.typed.{ PostStop, TypedAkkaSpecWithShutdown }
|
||||
import akka.actor.testkit.typed.scaladsl.ActorTestKit
|
||||
import akka.actor.testkit.typed.TE
|
||||
import akka.actor.testkit.typed.scaladsl.{ ActorTestKit, TestProbe }
|
||||
import akka.actor.typed.{ Behavior, PostStop, SupervisorStrategy, Terminated, TypedAkkaSpecWithShutdown }
|
||||
import akka.testkit.EventFilter
|
||||
|
||||
import scala.concurrent.Promise
|
||||
|
||||
|
|
@ -58,4 +60,19 @@ class StopSpec extends ActorTestKit with TypedAkkaSpecWithShutdown {
|
|||
|
||||
}
|
||||
|
||||
"PostStop" should {
|
||||
"immediately throw when a deferred behavior (setup) is passed in as postStop" in {
|
||||
val ex = intercept[IllegalArgumentException] {
|
||||
Behaviors.stopped(
|
||||
// illegal:
|
||||
Behaviors.setup[String] { _ ⇒
|
||||
throw TE("boom!")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
ex.getMessage should include("Behavior used as `postStop` behavior in Stopped(...) was a deferred one ")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,7 +233,23 @@ object Behavior {
|
|||
* that PostStop can be sent to previous behavior from `finishTerminate`.
|
||||
*/
|
||||
private[akka] class StoppedBehavior[T](val postStop: OptionVal[Behavior[T]]) extends Behavior[T] {
|
||||
override def toString = "Stopped"
|
||||
validatePostStop(postStop)
|
||||
|
||||
@throws[IllegalArgumentException]
|
||||
private final def validatePostStop(postStop: OptionVal[Behavior[T]]): Unit = {
|
||||
postStop match {
|
||||
case OptionVal.Some(b: DeferredBehavior[_]) ⇒
|
||||
throw new IllegalArgumentException(s"Behavior used as `postStop` behavior in Stopped(...) was a deferred one [${b.toString}], which is not supported (it would never be evaluated).")
|
||||
case _ ⇒ // all good
|
||||
}
|
||||
}
|
||||
|
||||
override def toString = "Stopped" + {
|
||||
postStop match {
|
||||
case OptionVal.Some(_) ⇒ "(postStop)"
|
||||
case _ ⇒ "()"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue