diff options
Diffstat (limited to 'kamon-trace/src/test')
4 files changed, 60 insertions, 2 deletions
diff --git a/kamon-trace/src/test/resources/application.conf b/kamon-trace/src/test/resources/application.conf new file mode 100644 index 00000000..e8217fc2 --- /dev/null +++ b/kamon-trace/src/test/resources/application.conf @@ -0,0 +1,3 @@ +akka { + loggers = ["akka.event.slf4j.Slf4jLogger"] +}
\ No newline at end of file diff --git a/kamon-trace/src/test/resources/logback.xml b/kamon-trace/src/test/resources/logback.xml new file mode 100644 index 00000000..2ae1e3bd --- /dev/null +++ b/kamon-trace/src/test/resources/logback.xml @@ -0,0 +1,12 @@ +<configuration scan="true"> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%date{HH:mm:ss.SSS} %-5level [%X{uow}][%X{requestId}] [%thread] %logger{55} - %msg%n</pattern> + </encoder> + </appender> + + <root level="debug"> + <appender-ref ref="STDOUT" /> + </root> + +</configuration> 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 => + } +} |