diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-01-12 01:45:27 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-01-24 23:19:01 +0100 |
commit | 485abe569d23bccf2d263c82b43e59464dc7e834 (patch) | |
tree | 34dd5129afe4c4705ce80830caf8d5e48212ce39 /kamon-core/src/test/scala/kamon/testkit | |
parent | 61089a75240f5cc21b056087f1d633dd31981c61 (diff) | |
download | Kamon-485abe569d23bccf2d263c82b43e59464dc7e834.tar.gz Kamon-485abe569d23bccf2d263c82b43e59464dc7e834.tar.bz2 Kamon-485abe569d23bccf2d263c82b43e59464dc7e834.zip |
! all: improve the metric recorders infrastructure
Diffstat (limited to 'kamon-core/src/test/scala/kamon/testkit')
-rw-r--r-- | kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala b/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala new file mode 100644 index 00000000..20fc3ed5 --- /dev/null +++ b/kamon-core/src/test/scala/kamon/testkit/BaseKamonSpec.scala @@ -0,0 +1,34 @@ +package kamon.testkit + +import akka.testkit.{ ImplicitSender, TestKitBase } +import akka.actor.ActorSystem +import com.typesafe.config.{ Config, ConfigFactory } +import kamon.Kamon +import kamon.metric.{ SubscriptionsDispatcher, EntitySnapshot, MetricsExtensionImpl } +import kamon.trace.TraceContext +import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike } + +abstract class BaseKamonSpec(actorSystemName: String) extends TestKitBase with WordSpecLike with Matchers with ImplicitSender with BeforeAndAfterAll { + lazy val kamon = Kamon(actorSystemName, config) + lazy val collectionContext = kamon.metrics.buildDefaultCollectionContext + implicit lazy val system: ActorSystem = kamon.actorSystem + + def config: Config = + ConfigFactory.load() + + def newContext(name: String): TraceContext = + kamon.tracer.newContext(name) + + def newContext(name: String, token: String): TraceContext = + kamon.tracer.newContext(name, token) + + def takeSnapshotOf(name: String, category: String): EntitySnapshot = { + val recorder = kamon.metrics.find(name, category).get + recorder.collect(collectionContext) + } + + def flushSubscriptions(): Unit = + system.actorSelection("/user/kamon/subscriptions-dispatcher") ! SubscriptionsDispatcher.Tick + + override protected def afterAll(): Unit = system.shutdown() +} |