pekko/akka-actor-tests/src/test/scala/akka/testkit/CallingThreadDispatcherModelSpec.scala

44 lines
1.6 KiB
Scala
Raw Normal View History

2011-05-19 21:34:21 +02:00
/**
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
2011-05-19 21:34:21 +02:00
*/
package akka.testkit
import akka.actor.dispatch.ActorModelSpec
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicInteger
2011-07-26 18:33:59 +12:00
import org.junit.{ After, Test }
import com.typesafe.config.Config
import akka.dispatch.DispatcherPrerequisites
import akka.dispatch.MessageDispatcher
import akka.dispatch.MessageDispatcherConfigurator
object CallingThreadDispatcherModelSpec {
val config = """
boss {
type = PinnedDispatcher
}
"""
}
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class CallingThreadDispatcherModelSpec extends ActorModelSpec(CallingThreadDispatcherModelSpec.config) {
import ActorModelSpec._
val dispatcherCount = new AtomicInteger()
2011-12-21 14:00:32 +01:00
override def registerInterceptedDispatcher(): MessageDispatcherInterceptor = {
// use new id for each invocation, since the MessageDispatcherInterceptor holds state
val dispatcherId = "test-calling-thread" + dispatcherCount.incrementAndGet()
val dispatcherConfigurator = new MessageDispatcherConfigurator(system.dispatchers.defaultDispatcherConfig, system.dispatchers.prerequisites) {
val instance = new CallingThreadDispatcher(prerequisites) with MessageDispatcherInterceptor {
override def id: String = dispatcherId
}
override def dispatcher(): MessageDispatcher = instance
}
system.dispatchers.register(dispatcherId, dispatcherConfigurator)
system.dispatchers.lookup(dispatcherId).asInstanceOf[MessageDispatcherInterceptor]
}
override def dispatcherType = "Calling Thread Dispatcher"
}