2011-05-19 21:34:21 +02:00
|
|
|
/**
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
|
2011-05-19 21:34:21 +02:00
|
|
|
*/
|
2011-03-05 14:36:08 +01:00
|
|
|
package akka.testkit
|
|
|
|
|
|
2011-12-21 19:02:06 +01:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger
|
2012-01-01 16:30:33 +01:00
|
|
|
import akka.actor.dispatch.ActorModelSpec
|
2011-12-20 21:08:27 +01:00
|
|
|
import com.typesafe.config.Config
|
|
|
|
|
import akka.dispatch.DispatcherPrerequisites
|
|
|
|
|
import akka.dispatch.MessageDispatcher
|
|
|
|
|
import akka.dispatch.MessageDispatcherConfigurator
|
2012-02-19 10:28:56 +01:00
|
|
|
import akka.dispatch.UnboundedMailbox
|
2011-12-20 21:08:27 +01:00
|
|
|
|
|
|
|
|
object CallingThreadDispatcherModelSpec {
|
2012-01-01 16:30:33 +01:00
|
|
|
import ActorModelSpec._
|
|
|
|
|
|
|
|
|
|
val config = {
|
2011-12-20 21:08:27 +01:00
|
|
|
"""
|
2012-01-01 16:30:33 +01:00
|
|
|
boss {
|
2012-02-07 09:50:03 +01:00
|
|
|
executor = thread-pool-executor
|
2012-01-01 16:30:33 +01:00
|
|
|
type = PinnedDispatcher
|
|
|
|
|
}
|
|
|
|
|
""" +
|
|
|
|
|
// use unique dispatcher id for each test, since MessageDispatcherInterceptor holds state
|
|
|
|
|
(for (n ← 1 to 30) yield """
|
|
|
|
|
test-calling-thread-%s {
|
|
|
|
|
type = "akka.testkit.CallingThreadDispatcherModelSpec$CallingThreadDispatcherInterceptorConfigurator"
|
|
|
|
|
}""".format(n)).mkString
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CallingThreadDispatcherInterceptorConfigurator(config: Config, prerequisites: DispatcherPrerequisites)
|
|
|
|
|
extends MessageDispatcherConfigurator(config, prerequisites) {
|
|
|
|
|
|
|
|
|
|
private val instance: MessageDispatcher =
|
2013-06-01 21:58:34 +02:00
|
|
|
new CallingThreadDispatcher(this) with MessageDispatcherInterceptor {
|
2012-01-01 16:30:33 +01:00
|
|
|
override def id: String = config.getString("id")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def dispatcher(): MessageDispatcher = instance
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 21:08:27 +01:00
|
|
|
}
|
2011-03-05 14:36:08 +01:00
|
|
|
|
2011-10-21 18:47:44 +02:00
|
|
|
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
2011-12-20 21:08:27 +01:00
|
|
|
class CallingThreadDispatcherModelSpec extends ActorModelSpec(CallingThreadDispatcherModelSpec.config) {
|
2011-10-12 15:15:17 +02:00
|
|
|
import ActorModelSpec._
|
|
|
|
|
|
2011-12-21 19:02:06 +01:00
|
|
|
val dispatcherCount = new AtomicInteger()
|
2011-12-21 14:00:32 +01:00
|
|
|
|
2012-01-01 16:30:33 +01:00
|
|
|
override def interceptedDispatcher(): MessageDispatcherInterceptor = {
|
|
|
|
|
// use new id for each test, since the MessageDispatcherInterceptor holds state
|
|
|
|
|
system.dispatchers.lookup("test-calling-thread-" + dispatcherCount.incrementAndGet()).asInstanceOf[MessageDispatcherInterceptor]
|
2011-12-20 21:08:27 +01:00
|
|
|
}
|
|
|
|
|
override def dispatcherType = "Calling Thread Dispatcher"
|
2011-03-17 22:18:39 +01:00
|
|
|
|
2011-03-05 14:36:08 +01:00
|
|
|
}
|