This commit is contained in:
Viktor Klang 2011-03-16 12:37:48 +01:00
parent 2d80ff4e04
commit fadd30e96b
2 changed files with 45 additions and 45 deletions

View file

@ -65,17 +65,9 @@ trait DefaultActorPool extends ActorPool { this: Actor =>
self reply_? Stats(_delegates length) self reply_? Stats(_delegates length)
case max: MaximumNumberOfRestartsWithinTimeRangeReached => case max: MaximumNumberOfRestartsWithinTimeRangeReached =>
_delegates = _delegates filterNot { _.uuid == max.victim.uuid } _delegates = _delegates filterNot { _.uuid == max.victim.uuid }
case msg => case msg =>
_capacity() _capacity()
_select() foreach { delegate => _select() foreach { _ forward msg }
self.senderFuture match {
case None =>
delegate ! msg
case Some(future) =>
delegate.!!!(msg, TimeUnit.NANOSECONDS.toMillis(future.timeoutInNanos)).onComplete( future.completeWith(_) )
}
}
} }
private def _capacity() = { private def _capacity() = {

View file

@ -180,44 +180,52 @@ class RoutingSpec extends junit.framework.TestCase with Suite with MustMatchers
for(a <- List(t1,t2,d1,d2)) a.stop for(a <- List(t1,t2,d1,d2)) a.stop
} }
// Actor Pool Capacity Tests // Actor Pool Capacity Tests
//
// make sure the pool is of the fixed, expected capacity
//
@Test def testFixedCapacityActorPool = {
val latch = new CountDownLatch(2) //
val counter = new AtomicInteger(0) // make sure the pool is of the fixed, expected capacity
class TestPool extends Actor with DefaultActorPool //
with FixedCapacityStrategy @Test def testFixedCapacityActorPool = {
with SmallestMailboxSelector val latch = new CountDownLatch(2)
{ val counter = new AtomicInteger(0)
def factory = actorOf(new Actor { class TestPool extends Actor with DefaultActorPool
def receive = { with FixedCapacityStrategy
case _ => with SmallestMailboxSelector
counter.incrementAndGet {
latch.countDown def factory = actorOf(new Actor {
} def receive = {
}) case _ =>
counter.incrementAndGet
def limit = 2 latch.countDown
def selectionCount = 1 self reply_? "success"
def partialFill = true
def instance = factory
def receive = _route
}
val pool = actorOf(new TestPool).start
pool ! "a"
pool ! "b"
val done = latch.await(1,TimeUnit.SECONDS)
done must be (true)
counter.get must be (2)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be (2)
pool stop
} }
})
def limit = 2
def selectionCount = 1
def partialFill = true
def instance = factory
def receive = _route
}
val successes = new CountDownLatch(2)
implicit val successCounterActor = Some(actorOf(new Actor {
def receive = {
case "success" => successes.countDown
}
}).start)
val pool = actorOf(new TestPool).start
pool ! "a"
pool ! "b"
latch.await(1,TimeUnit.SECONDS) must be (true)
successes.await(1,TimeUnit.SECONDS) must be (true)
counter.get must be (2)
(pool !! ActorPool.Stat).asInstanceOf[Option[ActorPool.Stats]].get.size must be (2)
pool stop
}
// //
// make sure the pool starts at the expected lower limit and grows to the upper as needed // make sure the pool starts at the expected lower limit and grows to the upper as needed