pekko/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala

47 lines
1.4 KiB
Scala
Raw Normal View History

package akka.dispatch
2011-08-26 17:25:18 +02:00
import akka.actor.{ Props, LocalActorRef, Actor }
2011-10-11 16:05:48 +02:00
import akka.testkit.AkkaSpec
2011-10-11 16:05:48 +02:00
class PriorityDispatcherSpec extends AkkaSpec {
"A PriorityDispatcher" must {
"Order it's messages according to the specified comparator using an unbounded mailbox" in {
testOrdering(UnboundedPriorityMailbox(PriorityGenerator({
case i: Int i //Reverse order
case 'Result Int.MaxValue
}: Any Int)))
}
"Order it's messages according to the specified comparator using a bounded mailbox" in {
testOrdering(BoundedPriorityMailbox(PriorityGenerator({
case i: Int i //Reverse order
case 'Result Int.MaxValue
2011-10-11 16:05:48 +02:00
}: Any Int), 1000, app.AkkaConfig.MailboxPushTimeout))
}
}
def testOrdering(mboxType: MailboxType) {
2011-10-11 16:05:48 +02:00
val dispatcher = app.dispatcherFactory.newDispatcher("Test", 1, -1, mboxType).build
2011-10-18 17:56:23 +02:00
val actor = actorOf(Props(new Actor {
var acc: List[Int] = Nil
def receive = {
case i: Int acc = i :: acc
case 'Result tryReply(acc)
}
2011-08-26 17:25:18 +02:00
}).withDispatcher(dispatcher)).asInstanceOf[LocalActorRef]
actor.suspend //Make sure the actor isn't treating any messages, let it buffer the incoming messages
val msgs = (1 to 100).toList
for (m msgs) actor ! m
actor.resume //Signal the actor to start treating it's message backlog
actor.?('Result).as[List[Int]].get must be === (msgs.reverse)
}
}