From d4c91ef61c045e0d2d45f43e23b1571728e719d6 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 3 Nov 2011 21:41:32 +0100 Subject: [PATCH] expand MainBusSpec wrt. logLevel setting --- .../test/scala/akka/event/MainBusSpec.scala | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/event/MainBusSpec.scala b/akka-actor-tests/src/test/scala/akka/event/MainBusSpec.scala index 887628ec94..16e735542b 100644 --- a/akka-actor-tests/src/test/scala/akka/event/MainBusSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/event/MainBusSpec.scala @@ -6,27 +6,70 @@ package akka.event import akka.testkit.AkkaSpec import akka.config.Configuration import akka.util.duration._ +import akka.actor.{ Actor, ActorRef } object MainBusSpec { case class M(i: Int) + + case class SetTarget(ref: ActorRef) + + class MyLog extends Actor { + var dst: ActorRef = app.deadLetters + def receive = { + case Logging.InitializeLogger(bus) ⇒ bus.subscribe(context.self, classOf[SetTarget]) + case SetTarget(ref) ⇒ dst = ref + case e: Logging.LogEvent ⇒ dst ! e + } + } } class MainBusSpec extends AkkaSpec(Configuration( - "akka.actor.debug.lifecycle" -> true, - "akka.actor.debug.mainbus" -> true)) { + "akka.stdout-loglevel" -> "WARNING", + "akka.loglevel" -> "INFO", + "akka.event-handlers" -> Seq("akka.event.MainBusSpec$MyLog", Logging.StandardOutLoggerName))) { import MainBusSpec._ "A MainBus" must { - "allow subscriptions" in { + "manage subscriptions" in { val bus = new MainBus(true) bus.start(app) bus.subscribe(testActor, classOf[M]) bus.publish(M(42)) - expectMsg(1 second, M(42)) + within(1 second) { + expectMsg(M(42)) + bus.unsubscribe(testActor) + bus.publish(M(13)) + expectNoMsg + } + } + + "manage log levels" in { + val bus = new MainBus(false) + bus.start(app) + bus.startDefaultLoggers(app, app.AkkaConfig) + bus.publish(SetTarget(testActor)) + within(1 second) { + import Logging._ + verifyLevel(bus, InfoLevel) + bus.logLevel = WarningLevel + verifyLevel(bus, WarningLevel) + bus.logLevel = DebugLevel + verifyLevel(bus, DebugLevel) + bus.logLevel = ErrorLevel + verifyLevel(bus, ErrorLevel) + } } } + private def verifyLevel(bus: LoggingBus, level: Logging.LogLevel) { + import Logging._ + val allmsg = Seq(Debug(this, "debug"), Info(this, "info"), Warning(this, "warning"), Error(this, "error")) + val msg = allmsg filter (_.level <= level) + allmsg foreach bus.publish + msg foreach (x ⇒ expectMsg(x)) + } + } \ No newline at end of file