diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-08-24 11:21:50 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-08-24 11:21:50 +0200 |
commit | 5291089bcc6bb048dcecad2c931f3408bd539574 (patch) | |
tree | 4885a7200242f9a2076dd3414170f36026de7cca /kamon-testkit/src/main/scala | |
parent | eaa4f83b5b2c6335e7cf6cecc10bfe4de9f47533 (diff) | |
parent | d5719438ed9a93c4035262fa8bd94ee60eead048 (diff) | |
download | Kamon-5291089bcc6bb048dcecad2c931f3408bd539574.tar.gz Kamon-5291089bcc6bb048dcecad2c931f3408bd539574.tar.bz2 Kamon-5291089bcc6bb048dcecad2c931f3408bd539574.zip |
Merge branch 'kamon-1.0-develop' of github.com:kamon-io/Kamon into kamon-1.0-develop
Diffstat (limited to 'kamon-testkit/src/main/scala')
-rw-r--r-- | kamon-testkit/src/main/scala/kamon/testkit/ContextTesting.scala | 2 | ||||
-rw-r--r-- | kamon-testkit/src/main/scala/kamon/testkit/SimpleStringCodec.scala | 42 |
2 files changed, 44 insertions, 0 deletions
diff --git a/kamon-testkit/src/main/scala/kamon/testkit/ContextTesting.scala b/kamon-testkit/src/main/scala/kamon/testkit/ContextTesting.scala index 8fd51024..b9e243d4 100644 --- a/kamon-testkit/src/main/scala/kamon/testkit/ContextTesting.scala +++ b/kamon-testkit/src/main/scala/kamon/testkit/ContextTesting.scala @@ -11,3 +11,5 @@ trait ContextTesting { } object ContextTesting extends ContextTesting + + diff --git a/kamon-testkit/src/main/scala/kamon/testkit/SimpleStringCodec.scala b/kamon-testkit/src/main/scala/kamon/testkit/SimpleStringCodec.scala new file mode 100644 index 00000000..f1d8cb14 --- /dev/null +++ b/kamon-testkit/src/main/scala/kamon/testkit/SimpleStringCodec.scala @@ -0,0 +1,42 @@ +package kamon.testkit + +import java.nio.ByteBuffer + +import kamon.context.{Codecs, Context, TextMap} + +object SimpleStringCodec { + final class Headers extends Codecs.ForEntry[TextMap] { + private val dataKey = "X-String-Value" + + override def encode(context: Context): TextMap = { + val textMap = TextMap.Default() + context.get(ContextTesting.StringBroadcastKey).foreach { value => + textMap.put(dataKey, value) + } + + textMap + } + + override def decode(carrier: TextMap, context: Context): Context = { + carrier.get(dataKey) match { + case value @ Some(_) => context.withKey(ContextTesting.StringBroadcastKey, value) + case None => context + } + } + } + + final class Binary extends Codecs.ForEntry[ByteBuffer] { + val emptyBuffer: ByteBuffer = ByteBuffer.allocate(0) + + override def encode(context: Context): ByteBuffer = { + context.get(ContextTesting.StringBroadcastKey) match { + case Some(value) => ByteBuffer.wrap(value.getBytes) + case None => emptyBuffer + } + } + + override def decode(carrier: ByteBuffer, context: Context): Context = { + context.withKey(ContextTesting.StringBroadcastKey, Some(new String(carrier.array()))) + } + } +} |