aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test
diff options
context:
space:
mode:
authorDiego Parra <diegolparra@gmail.com>2016-07-03 15:07:03 -0300
committerGitHub <noreply@github.com>2016-07-03 15:07:03 -0300
commitebc560f24154ddec862411b82a79033164bb2c31 (patch)
treedd12aad175583349f160c4b960b3fdfadedcc68c /kamon-core/src/test
parent8516613ad2ffd5b29f2e611a0a9e9006c5613ea4 (diff)
parent8e7f64134c6e2ef48926bf63943fa3338636a62c (diff)
downloadKamon-ebc560f24154ddec862411b82a79033164bb2c31.tar.gz
Kamon-ebc560f24154ddec862411b82a79033164bb2c31.tar.bz2
Kamon-ebc560f24154ddec862411b82a79033164bb2c31.zip
Merge pull request #363 from dspasojevic/mdc
= kamon-core: add context name and token to MDC
Diffstat (limited to 'kamon-core/src/test')
-rw-r--r--kamon-core/src/test/scala/kamon/trace/logging/MdcKeysSupportSpec.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/trace/logging/MdcKeysSupportSpec.scala b/kamon-core/src/test/scala/kamon/trace/logging/MdcKeysSupportSpec.scala
new file mode 100644
index 00000000..6193f028
--- /dev/null
+++ b/kamon-core/src/test/scala/kamon/trace/logging/MdcKeysSupportSpec.scala
@@ -0,0 +1,44 @@
+package kamon.trace.logging
+
+import kamon.testkit.BaseKamonSpec
+import kamon.trace.{ EmptyTraceContext, Tracer }
+import org.slf4j.MDC
+
+class MdcKeysSupportSpec extends BaseKamonSpec("mdc-keys-support-spec") {
+
+ "Running code with MDC support" should {
+ "add nothing to the MDC" when {
+ "the trace context is empty" in {
+ // Given an empty trace context.
+ Tracer.withContext(EmptyTraceContext) {
+ // When some code is executed with MDC support.
+ MdcKeysSupport.withMdc {
+ // Then the MDC should not contain the trace token.
+ Option(MDC.get(MdcKeysSupport.traceTokenKey)) should be(None)
+ // Or name
+ Option(MDC.get(MdcKeysSupport.traceNameKey)) should be(None)
+ }
+ }
+ }
+ }
+ "add the trace token and name to the context" when {
+ "the trace context is not empty" in {
+ // Given a trace context.
+ Tracer.withNewContext("name", Some("token")) {
+ // When some code is executed with MDC support.
+ MdcKeysSupport.withMdc {
+ // Then the MDC should contain the trace token.
+ Option(MDC.get(MdcKeysSupport.traceTokenKey)) should be(Some("token"))
+ // And name
+ Option(MDC.get(MdcKeysSupport.traceNameKey)) should be(Some("name"))
+ }
+
+ // Then after code is executed the MDC should have been cleared.
+ Option(MDC.get(MdcKeysSupport.traceTokenKey)) should be(None)
+ Option(MDC.get(MdcKeysSupport.traceNameKey)) should be(None)
+ }
+ }
+ }
+ }
+
+}