From 0ce3f4c0e8eb7dfd4aadd8300880e001a9a9bb8d Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 9 May 2014 18:23:21 -0300 Subject: + play: removed default dispatchers to kamon default dispatcher and refactor test in WSInstrumentationSpec --- .../scala/kamon/play/WSInstrumentationSpec.scala | 52 +++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'kamon-play/src/test/scala/kamon/play') diff --git a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala index 4b31fb25..0c3783bb 100644 --- a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala @@ -19,25 +19,67 @@ package kamon.play import play.api.mvc.Action import play.api.mvc.Results.Ok import play.api.libs.ws.WS -import org.scalatestplus.play.{ OneServerPerSuite, PlaySpec } +import org.scalatestplus.play.OneServerPerSuite import play.api.test._ import play.api.test.Helpers._ +import akka.actor.ActorSystem +import akka.testkit.{ TestKitBase, TestProbe } -class WSInstrumentationSpec extends PlaySpec with OneServerPerSuite { +import com.typesafe.config.ConfigFactory +import org.scalatest.{ Matchers, WordSpecLike } +import kamon.Kamon +import kamon.metrics.{ TraceMetrics, Metrics } +import kamon.metrics.Subscriptions.TickMetricSnapshot +import kamon.metrics.TraceMetrics.ElapsedTime + +class WSInstrumentationSpec extends TestKitBase with WordSpecLike with Matchers with OneServerPerSuite { System.setProperty("config.file", "./kamon-play/src/test/resources/conf/application.conf") + import scala.collection.immutable.StringLike._ + implicit lazy val system: ActorSystem = ActorSystem("play-ws-instrumentation-spec", ConfigFactory.parseString( + """ + |akka { + | loglevel = ERROR + |} + | + |kamon { + | metrics { + | tick-interval = 2 seconds + | + | filters = [ + | { + | trace { + | includes = [ "*" ] + | excludes = [] + | } + | } + | ] + | } + |} + """.stripMargin)) + implicit override lazy val app = FakeApplication(withRoutes = { case ("GET", "/async") ⇒ Action { Ok("ok") } }) "the WS instrumentation" should { "respond to the Async Action and complete the WS request" in { - val response = await(WS.url("http://localhost:19001/async").get()) - response.status mustBe (OK) + val metricListener = TestProbe() + Kamon(Metrics)(system).subscribe(TraceMetrics, "*", metricListener.ref, permanently = true) + metricListener.expectMsgType[TickMetricSnapshot] + + val response = await(WS.url("http://localhost:19001/async").get()) + response.status should be(OK) - //Thread.sleep(2000) //wait to complete the future + // val tickSnapshot = metricListener.expectMsgType[TickMetricSnapshot] + // val traceMetrics = tickSnapshot.metrics.find { case (k, v) ⇒ k.name.contains("async") } map (_._2.metrics) + // traceMetrics should not be empty + // + // traceMetrics map { metrics ⇒ + // metrics(ElapsedTime).numberOfMeasurements should be(1L) + // } } } } \ No newline at end of file -- cgit v1.2.3