aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
diff options
context:
space:
mode:
authorIvan Topolnak <ivantopo@gmail.com>2013-08-07 19:06:33 -0300
committerIvan Topolnak <ivantopo@gmail.com>2013-08-07 19:06:33 -0300
commit923b88e8adef2f66b43e551fa4a0a1bbae5af7ff (patch)
treed555199f0c63b690ec51805b496ee2d54eb014da /kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
parent1e6665e30d96772eab92aca4d23e176adcd88dc5 (diff)
downloadKamon-923b88e8adef2f66b43e551fa4a0a1bbae5af7ff.tar.gz
Kamon-923b88e8adef2f66b43e551fa4a0a1bbae5af7ff.tar.bz2
Kamon-923b88e8adef2f66b43e551fa4a0a1bbae5af7ff.zip
upgrading to akka 2.2
Diffstat (limited to 'kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala')
-rw-r--r--kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala82
1 files changed, 82 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
new file mode 100644
index 00000000..de65aaca
--- /dev/null
+++ b/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
@@ -0,0 +1,82 @@
+package kamon.instrumentation
+
+import scala.concurrent.{Await, Promise, Future}
+import org.scalatest.{Matchers, OptionValues, WordSpec}
+import org.scalatest.concurrent.{ScalaFutures, PatienceConfiguration}
+import kamon.{Kamon, TraceContext}
+import java.util.UUID
+import scala.util.Success
+import scala.concurrent.duration._
+import java.util.concurrent.TimeUnit
+import akka.actor.ActorSystem
+
+
+class RunnableInstrumentationSpec extends WordSpec with Matchers with ScalaFutures with PatienceConfiguration with OptionValues {
+
+ "a instrumented runnable" when {
+ "created in a thread that does have a TraceContext" must {
+ "preserve the TraceContext" which {
+ "should be available during the run method execution" in { new FutureWithContextFixture {
+
+ whenReady(futureWithContext) { result =>
+ result.value should equal(testContext)
+ }
+ }}
+
+ "should be available during the execution of onComplete callbacks" in { new FutureWithContextFixture {
+ val onCompleteContext = Promise[TraceContext]()
+
+ futureWithContext.onComplete({
+ case _ => onCompleteContext.complete(Success(Kamon.context.get))
+ })
+
+ whenReady(onCompleteContext.future) { result =>
+ result should equal(testContext)
+ }
+ }}
+ }
+ }
+
+ "created in a thread that doest have a TraceContext" must {
+ "not capture any TraceContext for the body execution" in { new FutureWithoutContextFixture{
+
+ whenReady(futureWithoutContext) { result =>
+ result should equal(None)
+ }
+ }}
+
+ "not make any TraceContext available during the onComplete callback" in { new FutureWithoutContextFixture {
+ val onCompleteContext = Promise[Option[TraceContext]]()
+
+ futureWithoutContext.onComplete({
+ case _ => onCompleteContext.complete(Success(Kamon.context))
+ })
+
+ whenReady(onCompleteContext.future) { result =>
+ result should equal(None)
+ }
+ }}
+ }
+ }
+
+
+ /**
+ * We are using Futures for the test since they exercise Runnables in the back and also resemble the real use case we have.
+ */
+ implicit val testActorSystem = ActorSystem("test-actorsystem")
+ implicit val execContext = testActorSystem.dispatcher
+
+ class FutureWithContextFixture {
+ val testContext = TraceContext()
+ Kamon.set(testContext)
+
+ val futureWithContext = Future { Kamon.context}
+ }
+
+ trait FutureWithoutContextFixture {
+ Kamon.clear // Make sure no TraceContext is available
+ val futureWithoutContext = Future { Kamon.context }
+ }
+}
+
+