2018-03-13 23:45:55 +09:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2018-2020 Lightbend Inc. <https://www.lightbend.com>
|
2018-03-13 23:45:55 +09:00
|
|
|
*/
|
|
|
|
|
|
2014-03-11 17:03:05 +01:00
|
|
|
package akka.dispatch
|
|
|
|
|
|
2019-03-11 10:38:24 +01:00
|
|
|
import akka.testkit.{ AkkaSpec, DefaultTimeout }
|
2014-03-11 17:03:05 +01:00
|
|
|
import akka.actor.{ Actor, Props }
|
|
|
|
|
|
|
|
|
|
object ControlAwareDispatcherSpec {
|
|
|
|
|
val config = """
|
|
|
|
|
unbounded-control-dispatcher {
|
|
|
|
|
mailbox-type = "akka.dispatch.UnboundedControlAwareMailbox"
|
|
|
|
|
}
|
|
|
|
|
bounded-control-dispatcher {
|
|
|
|
|
mailbox-type = "akka.dispatch.BoundedControlAwareMailbox"
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
case object ImportantMessage extends ControlMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ControlAwareDispatcherSpec extends AkkaSpec(ControlAwareDispatcherSpec.config) with DefaultTimeout {
|
|
|
|
|
import ControlAwareDispatcherSpec.ImportantMessage
|
|
|
|
|
|
|
|
|
|
"A ControlAwareDispatcher" must {
|
|
|
|
|
"deliver control messages first using an unbounded mailbox" in {
|
|
|
|
|
val dispatcherKey = "unbounded-control-dispatcher"
|
|
|
|
|
testControl(dispatcherKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"deliver control messages first using a bounded mailbox" in {
|
|
|
|
|
val dispatcherKey = "bounded-control-dispatcher"
|
|
|
|
|
testControl(dispatcherKey)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def testControl(dispatcherKey: String) = {
|
|
|
|
|
// It's important that the actor under test is not a top level actor
|
|
|
|
|
// with RepointableActorRef, since messages might be queued in
|
|
|
|
|
// UnstartedCell and the sent to the PriorityQueue and consumed immediately
|
|
|
|
|
// without the ordering taking place.
|
2019-04-15 09:54:16 +01:00
|
|
|
system.actorOf(Props(new Actor {
|
2014-03-11 17:03:05 +01:00
|
|
|
context.actorOf(Props(new Actor {
|
|
|
|
|
|
|
|
|
|
self ! "test"
|
|
|
|
|
self ! "test2"
|
|
|
|
|
self ! ImportantMessage
|
|
|
|
|
|
|
|
|
|
def receive = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case x => testActor ! x
|
2014-03-11 17:03:05 +01:00
|
|
|
}
|
|
|
|
|
}).withDispatcher(dispatcherKey))
|
|
|
|
|
|
|
|
|
|
def receive = Actor.emptyBehavior
|
|
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
expectMsg(ImportantMessage)
|
|
|
|
|
expectMsg("test")
|
|
|
|
|
expectMsg("test2")
|
|
|
|
|
}
|
|
|
|
|
}
|