aboutsummaryrefslogtreecommitdiff
path: root/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2013-11-23 22:54:47 -0300
committerIvan Topolnjak <ivantopo@gmail.com>2013-11-23 22:54:47 -0300
commit7298ddee182f08f7232e8daf8e628b089678f77b (patch)
tree126a64b1e63637ed3b052f7f92b7252350e12a54 /kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala
parentddb000a4510dfce20f7090ac92ea9144403addd6 (diff)
downloadKamon-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/FutureTracingSpec.scala')
-rw-r--r--kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala56
1 files changed, 56 insertions, 0 deletions
diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala
new file mode 100644
index 00000000..9ba98381
--- /dev/null
+++ b/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala
@@ -0,0 +1,56 @@
+package kamon.trace.instrumentation
+
+import scala.concurrent.{ExecutionContext, Await, Promise, Future}
+import org.scalatest.{Matchers, OptionValues, WordSpec}
+import org.scalatest.concurrent.{ScalaFutures, PatienceConfiguration}
+import java.util.UUID
+import scala.util.{Random, Success}
+import scala.concurrent.duration._
+import java.util.concurrent.TimeUnit
+import akka.actor.{Actor, ActorSystem}
+import kamon.trace.{Trace, TraceContext}
+
+
+class FutureTracingSpec extends WordSpec with Matchers with ScalaFutures with PatienceConfiguration with OptionValues {
+
+ implicit val execContext = ExecutionContext.Implicits.global
+
+ "a Future created with FutureTracing" should {
+ "capture the TraceContext available when created" which {
+ "must be available when executing the future's body" in new TraceContextFixture {
+ var future: Future[Option[TraceContext]] = _
+
+ Trace.withContext(testTraceContext) {
+ future = Future(Trace.context)
+ }
+
+ whenReady(future)( ctxInFuture =>
+ ctxInFuture should equal(testTraceContext)
+ )
+ }
+
+ "must be available when executing callbacks on the future" in new TraceContextFixture {
+ var future: Future[Option[TraceContext]] = _
+
+ Trace.withContext(testTraceContext) {
+ future = Future("Hello Kamon!")
+ // The TraceContext is expected to be available during all intermediate processing.
+ .map (_.length)
+ .flatMap(len => Future(len.toString))
+ .map (s => Trace.context())
+ }
+
+ whenReady(future)( ctxInFuture =>
+ ctxInFuture should equal(testTraceContext)
+ )
+ }
+ }
+ }
+
+ trait TraceContextFixture {
+ val random = new Random(System.nanoTime)
+ val testTraceContext = Some(TraceContext(Actor.noSender, random.nextInt))
+ }
+}
+
+