Testing Akka actors that mixin Stash with TestActorRef

前端 未结 3 943
情歌与酒
情歌与酒 2021-02-13 10:31

I\'m running into a problem with an actor that extends Stash and which works perfectly fine when instantiating it with actorOf in a simple ActorSystem. Now I would actually like

相关标签:
3条回答
  • 2021-02-13 11:08

    Using the default akka dispatcher allowed me to use Stash and TestActorRef:

    val myActor = TestActorRef[MyActor](Props(classOf[MyActor]).withDispatcher("akka.actor.default-dispatcher"))
    

    Note that this means your tests will no longer use the default CallingThreadDispatcher and will lose the benefits highlighted in the akka docs

    0 讨论(0)
  • 2021-02-13 11:22

    TestActorRef can't be used together with Stash. TestActorRef requires a CallingThreadMailbox and Stash requires DequeBasedMessageQueueSemantics. The documentation should include this limitation and the error messages should be improved.

    0 讨论(0)
  • 2021-02-13 11:23

    I was able to test actors with Stash like this:

    val actor = TestActorRef(Props(new MyActorWithStash()).withDispatcher("deque"))
    
    0 讨论(0)
提交回复
热议问题