From c85c28d8c1b12b3d35cfc6dca628e72115db49f3 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 25 May 2015 17:08:01 -0300 Subject: + Ensure that the TraceLocalStorage can be used from Java and close #196 --- .../src/test/scala/kamon/trace/TraceLocalSpec.scala | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'kamon-core/src/test') diff --git a/kamon-core/src/test/scala/kamon/trace/TraceLocalSpec.scala b/kamon-core/src/test/scala/kamon/trace/TraceLocalSpec.scala index b58b247f..41d5bc83 100644 --- a/kamon-core/src/test/scala/kamon/trace/TraceLocalSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/TraceLocalSpec.scala @@ -19,6 +19,7 @@ package kamon.trace import kamon.testkit.BaseKamonSpec import kamon.trace.TraceLocal.AvailableToMdc import kamon.trace.logging.MdcKeysSupport +import kamon.util.Supplier import org.scalatest.concurrent.PatienceConfiguration import org.scalatest.OptionValues import org.slf4j.MDC @@ -26,7 +27,7 @@ import org.slf4j.MDC class TraceLocalSpec extends BaseKamonSpec("trace-local-spec") with PatienceConfiguration with OptionValues with MdcKeysSupport { val SampleTraceLocalKeyAvailableToMDC = AvailableToMdc("someKey") - object SampleTraceLocalKey extends TraceLocal.TraceLocalKey { type ValueType = String } + object SampleTraceLocalKey extends TraceLocal.TraceLocalKey[String] "the TraceLocal storage" should { "allow storing and retrieving values" in { @@ -44,6 +45,20 @@ class TraceLocalSpec extends BaseKamonSpec("trace-local-spec") with PatienceConf } } + "throws an exception when trying to get a non existent key" in { + Tracer.withContext(newContext("non-existent-key")) { + intercept[NoSuchElementException] { + TraceLocal.get(SampleTraceLocalKey) + } + } + } + + "return the given value when retrieving a non existent key" in { + Tracer.withContext(newContext("non-existent-key")) { + TraceLocal.getOrElse(SampleTraceLocalKey, new Supplier[String] { def get = "optionalValue" }) should equal("optionalValue") + } + } + "return None when retrieving a key without a current TraceContext" in { TraceLocal.retrieve(SampleTraceLocalKey) should equal(None) } -- cgit v1.2.3