2010-10-26 12:49:25 +02:00
|
|
|
package akka.actor.dispatch
|
2010-09-09 15:49:59 +02:00
|
|
|
|
|
|
|
|
import org.scalatest.junit.JUnitSuite
|
2010-09-21 18:52:41 +02:00
|
|
|
|
2010-09-09 15:49:59 +02:00
|
|
|
import org.junit.Test
|
2010-09-21 18:52:41 +02:00
|
|
|
|
2010-10-26 12:49:25 +02:00
|
|
|
import akka.actor.Actor
|
|
|
|
|
import akka.util.Duration
|
|
|
|
|
import akka.dispatch._
|
2010-09-21 18:52:41 +02:00
|
|
|
import Actor._
|
2010-09-09 15:49:59 +02:00
|
|
|
|
2010-09-21 18:52:41 +02:00
|
|
|
import java.util.concurrent.{BlockingQueue, CountDownLatch, TimeUnit}
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference
|
2010-09-09 15:49:59 +02:00
|
|
|
|
2010-09-21 18:52:41 +02:00
|
|
|
class MailboxTypeSpec extends JUnitSuite {
|
|
|
|
|
@Test def shouldDoNothing = assert(true)
|
2010-09-09 15:49:59 +02:00
|
|
|
|
2010-09-21 18:52:41 +02:00
|
|
|
/*
|
2010-09-09 15:49:59 +02:00
|
|
|
private val unit = TimeUnit.MILLISECONDS
|
|
|
|
|
|
|
|
|
|
@Test def shouldCreateUnboundedQueue = {
|
2010-09-21 18:52:41 +02:00
|
|
|
val m = UnboundedMailbox(false)
|
|
|
|
|
assert(m.newMailbox("uuid").asInstanceOf[BlockingQueue[MessageInvocation]].remainingCapacity === Integer.MAX_VALUE)
|
2010-09-09 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test def shouldCreateBoundedQueue = {
|
2010-09-21 18:52:41 +02:00
|
|
|
val m = BoundedMailbox(blocking = false, capacity = 1)
|
|
|
|
|
assert(m.newMailbox("uuid").asInstanceOf[BlockingQueue[MessageInvocation]].remainingCapacity === 1)
|
2010-09-09 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = classOf[MessageQueueAppendFailedException]) def shouldThrowMessageQueueAppendFailedExceptionWhenTimeOutEnqueue = {
|
2010-09-21 18:52:41 +02:00
|
|
|
val m = BoundedMailbox(false, 1, Duration(1, unit))
|
2010-09-09 15:49:59 +02:00
|
|
|
val testActor = actorOf( new Actor { def receive = { case _ => }} )
|
2010-09-21 18:52:41 +02:00
|
|
|
val mbox = m.newMailbox("uuid")
|
|
|
|
|
(1 to 10000) foreach { i => mbox.enqueue(new MessageInvocation(testActor, i, None, None, None)) }
|
2010-09-09 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test def shouldBeAbleToDequeueUnblocking = {
|
2010-09-21 18:52:41 +02:00
|
|
|
val m = BoundedMailbox(false, 1, Duration(1, unit))
|
|
|
|
|
val mbox = m.newMailbox("uuid")
|
2010-09-09 15:49:59 +02:00
|
|
|
val latch = new CountDownLatch(1)
|
|
|
|
|
val t = new Thread { override def run = {
|
|
|
|
|
mbox.dequeue
|
|
|
|
|
latch.countDown
|
|
|
|
|
}}
|
|
|
|
|
t.start
|
|
|
|
|
val result = latch.await(5000,unit)
|
|
|
|
|
if (!result)
|
|
|
|
|
t.interrupt
|
|
|
|
|
assert(result === true)
|
|
|
|
|
}
|
2010-09-21 18:52:41 +02:00
|
|
|
*/
|
2010-09-09 15:49:59 +02:00
|
|
|
}
|