Adding WatchedWith effect in akka actor typed testkit #27190 (#27195)

This commit is contained in:
Pritam Kadam 2019-06-21 20:29:32 +05:30 committed by Helena Edelson
parent 59f1a05819
commit 759673569a
7 changed files with 26 additions and 5 deletions

View file

@ -170,6 +170,11 @@ object Effect {
*/
final case class Watched[T](other: ActorRef[T]) extends Effect
/**
* The behavior started watching `other`, through `context.watchWith(other, message)`
*/
final case class WatchedWith[U, T](other: ActorRef[U], message: T) extends Effect
/**
* The behavior started watching `other`, through `context.unwatch(other)`
*/

View file

@ -66,7 +66,7 @@ import scala.compat.java8.FunctionConverters._
super.watch(other)
}
override def watchWith[U](other: ActorRef[U], message: T): Unit = {
effectQueue.offer(Watched(other))
effectQueue.offer(WatchedWith(other, message))
super.watchWith(other, message)
}
override def unwatch[U](other: ActorRef[U]): Unit = {

View file

@ -71,6 +71,11 @@ object Effects {
*/
def watched[T](other: ActorRef[T]): Watched[T] = Watched(other)
/**
* The behavior started watching `other`, through `context.watchWith(other, message)`
*/
def watchedWith[U, T](other: ActorRef[U], message: T): WatchedWith[U, T] = WatchedWith(other, message)
/**
* The behavior started watching `other`, through `context.unwatch(other)`
*/

View file

@ -70,6 +70,11 @@ object Effects {
*/
def watched[T](other: ActorRef[T]): Watched[T] = Watched(other)
/**
* The behavior started watching `other`, through `context.watchWith(other, message)`
*/
def watchedWith[U, T](other: ActorRef[U], message: T): WatchedWith[U, T] = WatchedWith(other, message)
/**
* The behavior started watching `other`, through `context.unwatch(other)`
*/

View file

@ -338,10 +338,14 @@ public class BehaviorTestKitTest extends JUnitSuite {
@Test
public void recordWatchWith() {
BehaviorTestKit<Command> test = BehaviorTestKit.create(behavior);
test.run(new SpawnWatchAndUnWatch("name"));
SpawnAndWatchWith spawnAndWatchWithMsg = new SpawnAndWatchWith("name");
test.run(spawnAndWatchWithMsg);
ActorRef<Object> child = test.childInbox("name").getRef();
test.expectEffectClass(Effect.Spawned.class);
assertEquals(child, test.expectEffectClass(Effect.Watched.class).other());
Effect.WatchedWith watchedWith = test.expectEffectClass(Effect.WatchedWith.class);
assertEquals(child, watchedWith.other());
assertEquals(spawnAndWatchWithMsg, watchedWith.message());
}
@Test

View file

@ -273,10 +273,11 @@ class BehaviorTestKitSpec extends WordSpec with Matchers {
"record effects for watchWith" in {
val testkit = BehaviorTestKit(Father.init)
testkit.run(SpawnAndWatchWith("hello"))
val spawnAndWatchWithMsg = SpawnAndWatchWith("hello")
testkit.run(spawnAndWatchWithMsg)
val child = testkit.childInbox("hello").ref
testkit.retrieveAllEffects() should be(
Seq(Effects.spawned(Child.initial, "hello", Props.empty), Effects.watched(child)))
Seq(Effects.spawned(Child.initial, "hello", Props.empty), Effects.watchedWith(child, spawnAndWatchWithMsg)))
}
}

View file

@ -127,6 +127,7 @@ The @apidoc[BehaviorTestKit] keeps track other effects you can verify, look at t
* SpawnedAdapter
* Stopped
* Watched
* WatchedWith
* Unwatched
* Scheduled