diff options
author | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-12 18:15:00 -0300 |
---|---|---|
committer | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-12 18:15:00 -0300 |
commit | ef8ef647162b5f3eb9033bafb87805e2de5f576e (patch) | |
tree | b7c0d86e6519b497903152d23c307652f0e3a2f5 /kamon-trace/src/test/scala/kamon | |
parent | 5c8eb362ea6a957449419cec6c48b54159d4c68e (diff) | |
download | Kamon-ef8ef647162b5f3eb9033bafb87805e2de5f576e.tar.gz Kamon-ef8ef647162b5f3eb9033bafb87805e2de5f576e.tar.bz2 Kamon-ef8ef647162b5f3eb9033bafb87805e2de5f576e.zip |
Initial ask pattern tracing
Diffstat (limited to 'kamon-trace/src/test/scala/kamon')
-rw-r--r-- | kamon-trace/src/test/scala/kamon/ActorInstrumentationSpec.scala | 4 | ||||
-rw-r--r-- | kamon-trace/src/test/scala/kamon/AskPatternTracingSpec.scala | 43 |
2 files changed, 45 insertions, 2 deletions
diff --git a/kamon-trace/src/test/scala/kamon/ActorInstrumentationSpec.scala b/kamon-trace/src/test/scala/kamon/ActorInstrumentationSpec.scala index f5d88f06..d675c4f4 100644 --- a/kamon-trace/src/test/scala/kamon/ActorInstrumentationSpec.scala +++ b/kamon-trace/src/test/scala/kamon/ActorInstrumentationSpec.scala @@ -65,7 +65,7 @@ class ActorInstrumentationSpec extends TestKit(ActorSystem("ActorInstrumentation } trait TraceContextEchoFixture { - val testTraceContext = Trace.newTraceContext() + val testTraceContext = Trace.newTraceContext("") val echo = system.actorOf(Props[TraceContextEcho]) Trace.set(testTraceContext) @@ -75,7 +75,7 @@ class ActorInstrumentationSpec extends TestKit(ActorSystem("ActorInstrumentation override val echo = system.actorOf(Props[TraceContextEcho].withRouter(RoundRobinRouter(nrOfInstances = 10))) def tellWithNewContext(target: ActorRef, message: Any): TraceContext = { - val context = Trace.newTraceContext() + val context = Trace.newTraceContext("") Trace.set(context) target ! message diff --git a/kamon-trace/src/test/scala/kamon/AskPatternTracingSpec.scala b/kamon-trace/src/test/scala/kamon/AskPatternTracingSpec.scala new file mode 100644 index 00000000..c2566725 --- /dev/null +++ b/kamon-trace/src/test/scala/kamon/AskPatternTracingSpec.scala @@ -0,0 +1,43 @@ +package kamon + +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 => + } +} |