2013-09-19 08:00:05 +02:00
|
|
|
/**
|
2014-02-02 19:05:45 -06:00
|
|
|
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
2013-09-19 08:00:05 +02:00
|
|
|
*/
|
|
|
|
|
package akka.routing
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap
|
|
|
|
|
import scala.concurrent.Await
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
import akka.actor.{ Props, Actor }
|
|
|
|
|
import akka.testkit.{ TestLatch, ImplicitSender, DefaultTimeout, AkkaSpec }
|
|
|
|
|
|
|
|
|
|
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
|
|
|
|
class SmallestMailboxSpec extends AkkaSpec("akka.actor.serialize-messages = off")
|
|
|
|
|
with DefaultTimeout with ImplicitSender {
|
|
|
|
|
|
|
|
|
|
"smallest mailbox pool" must {
|
|
|
|
|
|
|
|
|
|
"deliver messages to idle actor" in {
|
|
|
|
|
val usedActors = new ConcurrentHashMap[Int, String]()
|
|
|
|
|
val router = system.actorOf(SmallestMailboxPool(3).props(routeeProps = Props(new Actor {
|
|
|
|
|
def receive = {
|
|
|
|
|
case (busy: TestLatch, receivedLatch: TestLatch) ⇒
|
|
|
|
|
usedActors.put(0, self.path.toString)
|
|
|
|
|
self ! "another in busy mailbox"
|
|
|
|
|
receivedLatch.countDown()
|
|
|
|
|
Await.ready(busy, TestLatch.DefaultTimeout)
|
|
|
|
|
case (msg: Int, receivedLatch: TestLatch) ⇒
|
|
|
|
|
usedActors.put(msg, self.path.toString)
|
|
|
|
|
receivedLatch.countDown()
|
|
|
|
|
case s: String ⇒
|
|
|
|
|
}
|
|
|
|
|
})))
|
|
|
|
|
|
|
|
|
|
val busy = TestLatch(1)
|
|
|
|
|
val received0 = TestLatch(1)
|
|
|
|
|
router ! ((busy, received0))
|
|
|
|
|
Await.ready(received0, TestLatch.DefaultTimeout)
|
|
|
|
|
|
|
|
|
|
val received1 = TestLatch(1)
|
|
|
|
|
router ! ((1, received1))
|
|
|
|
|
Await.ready(received1, TestLatch.DefaultTimeout)
|
|
|
|
|
|
|
|
|
|
val received2 = TestLatch(1)
|
|
|
|
|
router ! ((2, received2))
|
|
|
|
|
Await.ready(received2, TestLatch.DefaultTimeout)
|
|
|
|
|
|
|
|
|
|
val received3 = TestLatch(1)
|
|
|
|
|
router ! ((3, received3))
|
|
|
|
|
Await.ready(received3, TestLatch.DefaultTimeout)
|
|
|
|
|
|
|
|
|
|
busy.countDown()
|
|
|
|
|
|
|
|
|
|
val busyPath = usedActors.get(0)
|
2013-12-17 14:25:56 +01:00
|
|
|
busyPath should not be (null)
|
2013-09-19 08:00:05 +02:00
|
|
|
|
|
|
|
|
val path1 = usedActors.get(1)
|
|
|
|
|
val path2 = usedActors.get(2)
|
|
|
|
|
val path3 = usedActors.get(3)
|
|
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
path1 should not be (busyPath)
|
|
|
|
|
path2 should not be (busyPath)
|
|
|
|
|
path3 should not be (busyPath)
|
2013-09-19 08:00:05 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|