2011-05-19 21:34:21 +02:00
|
|
|
/**
|
2011-07-14 16:03:08 +02:00
|
|
|
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
|
2011-05-19 21:34:21 +02:00
|
|
|
*/
|
2011-03-05 14:36:08 +01:00
|
|
|
package akka.testkit
|
|
|
|
|
|
|
|
|
|
import akka.actor.dispatch.ActorModelSpec
|
2011-03-17 22:18:39 +01:00
|
|
|
import java.util.concurrent.CountDownLatch
|
2011-07-26 18:33:59 +12:00
|
|
|
import org.junit.{ After, Test }
|
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
|
|
|
|
|
|
|
|
|
|
object CallingThreadDispatcherModelSpec {
|
|
|
|
|
val config = """
|
|
|
|
|
boss {
|
|
|
|
|
type = PinnedDispatcher
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
}
|
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 14:00:32 +01:00
|
|
|
var dispatcherCount = 0
|
|
|
|
|
|
2011-12-20 21:08:27 +01:00
|
|
|
override def registerInterceptedDispatcher(): MessageDispatcherInterceptor = {
|
2011-12-21 14:00:32 +01:00
|
|
|
// use new key for each invocation, since the MessageDispatcherInterceptor holds state
|
|
|
|
|
dispatcherCount += 1
|
|
|
|
|
val confKey = "test-calling-thread" + dispatcherCount
|
2011-12-20 21:08:27 +01:00
|
|
|
val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatcherFactory.defaultDispatcherConfig, system.dispatcherFactory.prerequisites) {
|
|
|
|
|
val instance = new CallingThreadDispatcher(prerequisites) with MessageDispatcherInterceptor {
|
|
|
|
|
override def key: String = confKey
|
|
|
|
|
}
|
|
|
|
|
override def dispatcher(): MessageDispatcher = instance
|
|
|
|
|
}
|
|
|
|
|
system.dispatcherFactory.register(confKey, dispatcherConfigurator)
|
|
|
|
|
system.dispatcherFactory.lookup(confKey).asInstanceOf[MessageDispatcherInterceptor]
|
|
|
|
|
}
|
|
|
|
|
override def dispatcherType = "Calling Thread Dispatcher"
|
2011-03-17 22:18:39 +01:00
|
|
|
|
2011-03-05 14:36:08 +01:00
|
|
|
}
|