I have the following Subscriber base class:
abstract class Subscriber(topics: Seq[String]) extends Actor with ActorLogging { import DistributedPubSubMediator.{ Subscribe, SubscribeAck } val mediator = DistributedPubSub(context.system).mediator // subscribe to each topic topics.foreach{mediator ! Subscribe(_, self)} def receive = { case SubscribeAck(Subscribe(name, None, `self`)) ⇒ log.info(s"Subscribing to $name") } }
And I would like to check that he receives messages published on topics for which the subscribed subclass is subscribed. Simple pseudocode demonstrating the following:
val topic = "foo" class FooSubscriber extends Subscriber(Seq(topic)) val fooSubActor = system.actorOf(Props[FooSubscriber]) val mediator = DistributedPubSub(system).mediator val msg = "This is a string"
The only way I know to make statements about messages that certain subjects receive is TestProbe , but I don’t know how I could make TestProbe extension of my class.
Usually Akka docs has a lot of code examples with corresponding test suites, but I could not find anything in the Akka docs cluster related to testing the receive method.
Does anyone have any suggestions?
source share