diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-07-17 13:13:41 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-07-17 13:13:41 +0200 |
commit | 483159862293a065be7cf3743d1aa759fbf31fc0 (patch) | |
tree | c6c2753c1c7abd7f2e44d7686bd088a51267867d /kamon-core/src/test/scala/kamon/trace/DefaultIdentityGeneratorSpec.scala | |
parent | 34010efc7b273e50d805a277646f14aa96aaa8b2 (diff) | |
download | Kamon-483159862293a065be7cf3743d1aa759fbf31fc0.tar.gz Kamon-483159862293a065be7cf3743d1aa759fbf31fc0.tar.bz2 Kamon-483159862293a065be7cf3743d1aa759fbf31fc0.zip |
working on ID generation and SpanContext encoding/decoding
Diffstat (limited to 'kamon-core/src/test/scala/kamon/trace/DefaultIdentityGeneratorSpec.scala')
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/DefaultIdentityGeneratorSpec.scala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/trace/DefaultIdentityGeneratorSpec.scala b/kamon-core/src/test/scala/kamon/trace/DefaultIdentityGeneratorSpec.scala new file mode 100644 index 00000000..bbd04df1 --- /dev/null +++ b/kamon-core/src/test/scala/kamon/trace/DefaultIdentityGeneratorSpec.scala @@ -0,0 +1,46 @@ +package kamon.trace + +import kamon.trace.IdentityProvider.Identifier +import org.scalatest.{Matchers, OptionValues, WordSpecLike} +import org.scalactic.TimesOnInt._ + +class DefaultIdentityGeneratorSpec extends WordSpecLike with Matchers with OptionValues { + val idProvider = IdentityProvider.Default() + val traceGenerator = idProvider.traceIdentifierGenerator() + val spanGenerator = idProvider.spanIdentifierGenerator() + + validateGenerator("TraceID Generator", traceGenerator) + validateGenerator("SpanID Generator", spanGenerator) + + def validateGenerator(generatorName: String, generator: IdentityProvider.Generator) = { + s"The $generatorName" should { + "generate random longs (8 byte) as Span and Trace identifiers" in { + 100 times { + val Identifier(string, bytes) = generator.generate() + + string.length should be(16) + bytes.length should be(8) + } + } + + "decode the string representation back into a identifier" in { + 100 times { + val identifier = generator.generate() + val decodedIdentifier = generator.from(identifier.string) + + identifier.string should equal(decodedIdentifier.string) + identifier.bytes should equal(decodedIdentifier.bytes) + } + } + + "decode the bytes representation back into a identifier" in { + 100 times { + val identifier = generator.generate() + val decodedIdentifier = generator.from(identifier.bytes) + + identifier should equal(decodedIdentifier) + } + } + } + } +} |