* All default values removed from code and loaded from akka-actor-reference.conf, located in src/main/resources (included in jar) * Default test configuration included in AkkaSpec instead of using akka.test.conf, avoids problems when running test (in IDE) and forgetting to use -Dakka.mode=test. * System.properties used first, if availble * Next step will be to split akka-actor-reference.conf in separate -reference for each module
This commit is contained in:
parent
80d766b07b
commit
4b8f11ea92
137 changed files with 8689 additions and 1411 deletions
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
package akka.testkit
|
||||
|
||||
import akka.config.Configuration
|
||||
import org.scalatest.{ WordSpec, BeforeAndAfterAll, Tag }
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.actor.{ ActorSystem, ActorSystemImpl }
|
||||
|
|
@ -12,10 +11,37 @@ import akka.dispatch.MessageDispatcher
|
|||
import akka.event.{ Logging, LoggingAdapter }
|
||||
import akka.util.duration._
|
||||
import akka.dispatch.FutureTimeoutException
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import com.typesafe.config.ConfigParseOptions
|
||||
import java.io.StringReader
|
||||
|
||||
object TimingTest extends Tag("timing")
|
||||
|
||||
abstract class AkkaSpec(_application: ActorSystem = ActorSystem())
|
||||
object AkkaSpec {
|
||||
val testConf =
|
||||
ActorSystem.DefaultConfigurationLoader.defaultConfig.withFallback(
|
||||
ConfigFactory.parseReader(new StringReader("""
|
||||
akka {
|
||||
event-handlers = ["akka.testkit.TestEventListener"]
|
||||
loglevel = "WARNING"
|
||||
actor {
|
||||
default-dispatcher {
|
||||
core-pool-size = 4
|
||||
max-pool-size = 32
|
||||
}
|
||||
}
|
||||
}
|
||||
"""), ConfigParseOptions.defaults))
|
||||
|
||||
def mapToConfig(map: Map[String, Any]): Config = {
|
||||
import scala.collection.JavaConverters._
|
||||
ConfigFactory.parseMap(map.asJava)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract class AkkaSpec(_application: ActorSystem = ActorSystem(getClass.getSimpleName, AkkaSpec.testConf))
|
||||
extends TestKit(_application) with WordSpec with MustMatchers with BeforeAndAfterAll {
|
||||
|
||||
val log: LoggingAdapter = Logging(system, this)
|
||||
|
|
@ -36,7 +62,11 @@ abstract class AkkaSpec(_application: ActorSystem = ActorSystem())
|
|||
|
||||
protected def atTermination() {}
|
||||
|
||||
def this(config: Configuration) = this(ActorSystem(getClass.getSimpleName, ActorSystem.defaultConfig ++ config))
|
||||
def this(config: Config) = this(ActorSystem(getClass.getSimpleName, config.withFallback(AkkaSpec.testConf)))
|
||||
|
||||
def this(configMap: Map[String, _]) = {
|
||||
this(AkkaSpec.mapToConfig(configMap).withFallback(AkkaSpec.testConf))
|
||||
}
|
||||
|
||||
def actorOf(props: Props): ActorRef = system.actorOf(props)
|
||||
|
||||
|
|
@ -55,10 +85,12 @@ abstract class AkkaSpec(_application: ActorSystem = ActorSystem())
|
|||
class AkkaSpecSpec extends WordSpec with MustMatchers {
|
||||
"An AkkaSpec" must {
|
||||
"terminate all actors" in {
|
||||
import ActorSystem.defaultConfig
|
||||
val system = ActorSystem("test", defaultConfig ++ Configuration(
|
||||
import ActorSystem.DefaultConfigurationLoader.defaultConfig
|
||||
import scala.collection.JavaConverters._
|
||||
val conf = Map(
|
||||
"akka.actor.debug.lifecycle" -> true, "akka.actor.debug.event-stream" -> true,
|
||||
"akka.loglevel" -> "DEBUG", "akka.stdout-loglevel" -> "DEBUG"))
|
||||
"akka.loglevel" -> "DEBUG", "akka.stdout-loglevel" -> "DEBUG")
|
||||
val system = ActorSystem("test", ConfigFactory.parseMap(conf.asJava).withFallback(defaultConfig))
|
||||
val spec = new AkkaSpec(system) {
|
||||
val ref = Seq(testActor, system.actorOf(Props.empty, "name"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue