diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2013-11-23 22:54:47 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2013-11-23 22:54:47 -0300 |
commit | 7298ddee182f08f7232e8daf8e628b089678f77b (patch) | |
tree | 126a64b1e63637ed3b052f7f92b7252350e12a54 /kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala | |
parent | ddb000a4510dfce20f7090ac92ea9144403addd6 (diff) | |
download | Kamon-7298ddee182f08f7232e8daf8e628b089678f77b.tar.gz Kamon-7298ddee182f08f7232e8daf8e628b089678f77b.tar.bz2 Kamon-7298ddee182f08f7232e8daf8e628b089678f77b.zip |
simple test for ActorLogging instrumentation
Diffstat (limited to 'kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala')
-rw-r--r-- | kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala new file mode 100644 index 00000000..cb18fe86 --- /dev/null +++ b/kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala @@ -0,0 +1,43 @@ +package kamon.trace.instrumentation + +import akka.testkit.TestKit +import akka.actor.{Props, Actor, ActorSystem} +import org.scalatest.{Matchers, WordSpecLike} +import akka.event.Logging.Warning +import scala.concurrent.duration._ +import akka.pattern.ask +import akka.util.Timeout +import kamon.trace.{Trace, ContextAware} +import org.scalatest.OptionValues._ + + +class AskPatternTracingSpec extends TestKit(ActorSystem("ask-pattern-tracing-spec")) with WordSpecLike with Matchers { + + "the AskPatternTracing" should { + "log a warning with a stack trace and TraceContext taken from the moment the ask was triggered" in { + implicit val ec = system.dispatcher + implicit val timeout = Timeout(10 milliseconds) + val noReply = system.actorOf(Props[NoReply]) + system.eventStream.subscribe(testActor, classOf[Warning]) + + within(500 milliseconds) { + val initialCtx = Trace.start("ask-test") + noReply ? "hello" + + val warn = expectMsgPF() { + case warn: Warning if warn.message.toString.contains("Timeout triggered for ask pattern") => warn + } + val capturedCtx = warn.asInstanceOf[ContextAware].traceContext + + capturedCtx should be('defined) + capturedCtx.value should equal (initialCtx) + } + } + } +} + +class NoReply extends Actor { + def receive = { + case any => + } +} |