From 04550ce1daff2b3d13aa85931686a303bf93fbd8 Mon Sep 17 00:00:00 2001 From: Diego Date: Sun, 9 Mar 2014 15:01:51 -0300 Subject: Play Integration with: X-Trace-Token, WebExternal Time and Error publishing in Akka EventStream --- .../kamon/play/RequestInstrumentationSpec.scala | 14 ++++++------ .../scala/kamon/play/WSInstrumentationSpec.scala | 16 +++++-------- .../FakeRequestIntrumentation.scala | 26 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala (limited to 'kamon-play/src/test/scala/kamon') diff --git a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala index 2dce39f8..0c4ac57b 100644 --- a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala @@ -1,5 +1,5 @@ /* =================================================== - * Copyright © 2013 2014 the kamon project + * Copyright © 2013-2014 the kamon project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ class RequestInstrumentationSpec extends PlaySpecification { private val traceTokenValue = "kamon-trace-token-test" private val traceTokenHeaderName = "X-Trace-Token" private val expectedToken = Some(traceTokenValue) - private val traceTokenHeader = (traceTokenHeaderName -> traceTokenValue) + private val traceTokenHeader = traceTokenHeaderName -> traceTokenValue "the Request instrumentation" should { "respond to the asyncResult action with X-Trace-Token" in new WithServer(appWithRoutes) { @@ -81,28 +81,28 @@ class RequestInstrumentationSpec extends PlaySpecification { header(traceTokenHeaderName, result) must equalTo(expectedToken) } - "respond to the async action with X-Trace-Token" in new WithServer(appWithRoutes) { + "respond to the Async Action with X-Trace-Token" in new WithServer(appWithRoutes) { val Some(result) = route(FakeRequest(GET, "/async").withHeaders(traceTokenHeader)) header(traceTokenHeaderName, result) must equalTo(expectedToken) } - "respond to the notFound action with X-Trace-Token" in new WithServer(appWithRoutes) { + "respond to the NotFound Action with X-Trace-Token" in new WithServer(appWithRoutes) { val Some(result) = route(FakeRequest(GET, "/notFound").withHeaders(traceTokenHeader)) header(traceTokenHeaderName, result) must equalTo(expectedToken) } - "respond to the default action with X-Trace-Token" in new WithServer(appWithRoutes) { + "respond to the Default Action with X-Trace-Token" in new WithServer(appWithRoutes) { val Some(result) = route(FakeRequest(GET, "/default").withHeaders(traceTokenHeader)) header(traceTokenHeaderName, result) must equalTo(expectedToken) } - "respond to the redirect action with X-Trace-Token" in new WithServer(appWithRoutes) { + "respond to the Redirect Action with X-Trace-Token" in new WithServer(appWithRoutes) { val Some(result) = route(FakeRequest(GET, "/redirect").withHeaders(traceTokenHeader)) header("Location", result) must equalTo(Some("/redirected")) header(traceTokenHeaderName, result) must equalTo(expectedToken) } - "respond to the async action with X-Trace-Token and the renamed trace" in new WithServer(appWithRoutes) { + "respond to the Async Action with X-Trace-Token and the renamed trace" in new WithServer(appWithRoutes) { val Some(result) = route(FakeRequest(GET, "/async-renamed").withHeaders(traceTokenHeader)) header(traceTokenHeaderName, result) must equalTo(expectedToken) } diff --git a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala index 2cebfe42..3b8a5492 100644 --- a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala @@ -17,25 +17,22 @@ package kamon.play import play.api.test._ -import play.api.mvc.{ Results, Action } +import play.api.mvc.Action import play.api.mvc.Results.Ok import scala.Some import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future import org.junit.runner.RunWith import org.specs2.runner.JUnitRunner -import play.api.mvc.AsyncResult import play.api.test.FakeApplication -import kamon.play.action.TraceName import play.api.libs.ws.WS +import scala.util._ @RunWith(classOf[JUnitRunner]) class WSInstrumentationSpec extends PlaySpecification { System.setProperty("config.file", "./kamon-play/src/test/resources/conf/application.conf") val appWithRoutes = FakeApplication(withRoutes = { - case ("GET", "/async") ⇒ Action.async { WS.url("http://www.google.com").get().map { @@ -46,14 +43,13 @@ class WSInstrumentationSpec extends PlaySpecification { }) "the WS instrumentation" should { - "respond to the async action" in new WithServer(appWithRoutes) { + "respond to the Async Action and complete the WS request" in new WithServer(appWithRoutes) { val Some(result) = route(FakeRequest(GET, "/async")) - println("-902425309-53095-5 " + result) result.onComplete { - case scala.util.Success(r) ⇒ println(r) - case scala.util.Failure(t) ⇒ println(t) + case Success(result) ⇒ result.header.status must equalTo(200) + case Failure(throwable) ⇒ failure(throwable.getMessage) } - Thread.sleep(3000) + Thread.sleep(2000) //wait to complete the future } } } \ No newline at end of file diff --git a/kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala b/kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala new file mode 100644 index 00000000..55b72908 --- /dev/null +++ b/kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala @@ -0,0 +1,26 @@ +/* =================================================== + * Copyright © 2013-2014 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ + +package kamon.play.instrumentation + +import org.aspectj.lang.annotation.{ DeclareMixin, Aspect } +import kamon.trace.TraceContextAware + +@Aspect +class FakeRequestIntrumentation { + @DeclareMixin("play.api.test.FakeRequest") + def mixinContextAwareNewRequest: TraceContextAware = TraceContextAware.default +} -- cgit v1.2.3