Make typed TestProbe a RecipientRef (#29928)
This commit is contained in:
parent
51548f6227
commit
1fd66f5f49
5 changed files with 27 additions and 3 deletions
|
|
@ -0,0 +1,4 @@
|
|||
# Changes to @DoNotInherit classes
|
||||
|
||||
ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("akka.actor.testkit.typed.scaladsl.TestProbe.tell")
|
||||
ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("akka.actor.testkit.typed.javadsl.TestProbe.tell")
|
||||
|
|
@ -16,6 +16,8 @@ import scala.concurrent.duration._
|
|||
import scala.reflect.ClassTag
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
import akka.actor.ActorRefProvider
|
||||
import akka.actor.ExtendedActorSystem
|
||||
import akka.actor.testkit.typed.FishingOutcome
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.javadsl.{ TestProbe => JavaTestProbe }
|
||||
|
|
@ -26,6 +28,7 @@ import akka.actor.typed.ActorSystem
|
|||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.Signal
|
||||
import akka.actor.typed.Terminated
|
||||
import akka.actor.typed.internal.InternalRecipientRef
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import akka.annotation.InternalApi
|
||||
import akka.japi.function.Creator
|
||||
|
|
@ -63,7 +66,8 @@ private[akka] object TestProbeImpl {
|
|||
@InternalApi
|
||||
private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
||||
extends JavaTestProbe[M]
|
||||
with ScalaTestProbe[M] {
|
||||
with ScalaTestProbe[M]
|
||||
with InternalRecipientRef[M] {
|
||||
|
||||
import TestProbeImpl._
|
||||
|
||||
|
|
@ -390,5 +394,14 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
testActor.asInstanceOf[ActorRef[AnyRef]] ! Stop
|
||||
}
|
||||
|
||||
def tell(m: M) = testActor.tell(m)
|
||||
|
||||
// impl InternalRecipientRef
|
||||
def provider: ActorRefProvider =
|
||||
system.classicSystem.asInstanceOf[ExtendedActorSystem].provider
|
||||
|
||||
// impl InternalRecipientRef
|
||||
def isTerminated: Boolean = false
|
||||
|
||||
override private[akka] def asJava: JavaTestProbe[M] = this
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import akka.actor.testkit.typed.TestKitSettings
|
|||
import akka.actor.testkit.typed.internal.TestProbeImpl
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.RecipientRef
|
||||
import akka.actor.typed.internal.InternalRecipientRef
|
||||
import akka.annotation.DoNotInherit
|
||||
import akka.util.unused
|
||||
|
||||
|
|
@ -65,7 +67,7 @@ object TestProbe {
|
|||
* Not for user extension
|
||||
*/
|
||||
@DoNotInherit
|
||||
abstract class TestProbe[M] {
|
||||
abstract class TestProbe[M] extends RecipientRef[M] { this: InternalRecipientRef[M] =>
|
||||
|
||||
implicit protected def settings: TestKitSettings
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import akka.actor.testkit.typed.TestKitSettings
|
|||
import akka.actor.testkit.typed.internal.TestProbeImpl
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.RecipientRef
|
||||
import akka.actor.typed.internal.InternalRecipientRef
|
||||
import akka.annotation.DoNotInherit
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
|
|
@ -56,7 +58,7 @@ object TestProbe {
|
|||
*
|
||||
* Not for user extension
|
||||
*/
|
||||
@DoNotInherit trait TestProbe[M] {
|
||||
@DoNotInherit trait TestProbe[M] extends RecipientRef[M] { this: InternalRecipientRef[M] =>
|
||||
|
||||
implicit protected def settings: TestKitSettings
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ The following demonstrates:
|
|||
* Creating a `TestProbe`
|
||||
* Verifying that the actor under test responds via the `TestProbe`
|
||||
|
||||
Note that it is possible to use a `TestProbe` directly as a @apidoc[akka.actor.typed.RecipientRef] (a common supertype of `ActorRef` and @ref:[Cluster Sharding](cluster-sharding.md)
|
||||
`EntityRef`), in cases where a message protocol uses `RecipientRef` instead of specifying `ActorRef` or `EntityRef`.
|
||||
|
||||
Scala
|
||||
: @@snip [AsyncTestingExampleSpec.scala](/akka-actor-testkit-typed/src/test/scala/docs/akka/actor/testkit/typed/scaladsl/AsyncTestingExampleSpec.scala) { #test-spawn }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue