diff options
Diffstat (limited to 'kamon-trace/src/test/scala/kamon')
7 files changed, 0 insertions, 482 deletions
diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala deleted file mode 100644 index 89742651..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala +++ /dev/null @@ -1,51 +0,0 @@ -/* =================================================== - * Copyright © 2013 the kamon project <http://kamon.io/> - * - * 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.trace.instrumentation - -import akka.testkit.TestKit -import org.scalatest.{ Inspectors, Matchers, WordSpecLike } -import akka.actor.{ Props, ActorLogging, Actor, ActorSystem } -import akka.event.Logging.{ LogEvent } -import kamon.trace.{ ContextAware, TraceContext, Trace } - -class ActorLoggingSpec extends TestKit(ActorSystem("actor-logging-spec")) with WordSpecLike with Matchers with Inspectors { - - "the ActorLogging instrumentation" should { - "attach the TraceContext (if available) to log events" in { - val testTraceContext = Some(TraceContext(Actor.noSender, 1)) - val loggerActor = system.actorOf(Props[LoggerActor]) - system.eventStream.subscribe(testActor, classOf[LogEvent]) - - Trace.withContext(testTraceContext) { - loggerActor ! "info" - } - - fishForMessage() { - case event: LogEvent if event.message.toString contains "TraceContext =>" ⇒ - val ctxInEvent = event.asInstanceOf[ContextAware].traceContext - ctxInEvent === testTraceContext - - case event: LogEvent ⇒ false - } - } - } -} - -class LoggerActor extends Actor with ActorLogging { - def receive = { - case "info" ⇒ log.info("TraceContext => {}", Trace.context()) - } -} diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala deleted file mode 100644 index 89251bf4..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala +++ /dev/null @@ -1,84 +0,0 @@ -/* =================================================== - * Copyright © 2013 the kamon project <http://kamon.io/> - * - * 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.trace.instrumentation - -import org.scalatest.{ WordSpecLike, Matchers } -import akka.actor.{ ActorRef, Actor, Props, ActorSystem } - -import akka.testkit.{ ImplicitSender, TestKit } -import kamon.trace.Trace -import akka.pattern.{ pipe, ask } -import akka.util.Timeout -import scala.concurrent.duration._ -import scala.concurrent.{ Await, Future } -import akka.routing.RoundRobinRouter -import kamon.trace.TraceContext - -class ActorMessagePassingTracingSpec extends TestKit(ActorSystem("actor-message-passing-tracing-spec")) with WordSpecLike with ImplicitSender { - implicit val executionContext = system.dispatcher - - "the message passing instrumentation" should { - "propagate the TraceContext using bang" in new TraceContextEchoFixture { - Trace.withContext(testTraceContext) { - ctxEchoActor ! "test" - } - - expectMsg(testTraceContext) - } - - "propagate the TraceContext using tell" in new TraceContextEchoFixture { - Trace.withContext(testTraceContext) { - ctxEchoActor.tell("test", testActor) - } - - expectMsg(testTraceContext) - } - - "propagate the TraceContext using ask" in new TraceContextEchoFixture { - implicit val timeout = Timeout(1 seconds) - Trace.withContext(testTraceContext) { - // The pipe pattern use Futures internally, so FutureTracing test should cover the underpinnings of it. - (ctxEchoActor ? "test") pipeTo (testActor) - } - - expectMsg(testTraceContext) - } - - "propagate the TraceContext to actors behind a router" in new RoutedTraceContextEchoFixture { - Trace.withContext(testTraceContext) { - ctxEchoActor ! "test" - } - - expectMsg(testTraceContext) - } - } - - trait TraceContextEchoFixture { - val testTraceContext = Some(Trace.newTraceContext("")) - val ctxEchoActor = system.actorOf(Props[TraceContextEcho]) - } - - trait RoutedTraceContextEchoFixture extends TraceContextEchoFixture { - override val ctxEchoActor = system.actorOf(Props[TraceContextEcho].withRouter(RoundRobinRouter(nrOfInstances = 1))) - } -} - -class TraceContextEcho extends Actor { - def receive = { - case msg: String ⇒ sender ! Trace.context() - } -} - diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorSystemMessagePassingInstrumentationSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorSystemMessagePassingInstrumentationSpec.scala deleted file mode 100644 index 7d539370..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/ActorSystemMessagePassingInstrumentationSpec.scala +++ /dev/null @@ -1,165 +0,0 @@ -package kamon.trace.instrumentation - -import akka.testkit.{ ImplicitSender, TestKit } -import akka.actor._ -import org.scalatest.WordSpecLike -import kamon.trace.Trace -import scala.util.control.NonFatal -import akka.actor.SupervisorStrategy.{ Escalate, Stop, Restart, Resume } -import scala.concurrent.duration._ - -class ActorSystemMessagePassingInstrumentationSpec extends TestKit(ActorSystem("actor-message-passing-tracing-spec")) with WordSpecLike with ImplicitSender { - implicit val executionContext = system.dispatcher - - "the system message passing instrumentation" should { - "keep the TraceContext while processing the Create message in top level actors" in new TraceContextFixture { - Trace.withContext(testTraceContext) { - system.actorOf(Props(new Actor { - - testActor ! Trace.context() - - def receive: Actor.Receive = { case any ⇒ } - })) - } - - expectMsg(testTraceContext) - } - - "keep the TraceContext while processing the Create message in non top level actors" in new TraceContextFixture { - Trace.withContext(testTraceContext) { - system.actorOf(Props(new Actor { - def receive: Actor.Receive = { - case any ⇒ - context.actorOf(Props(new Actor { - - testActor ! Trace.context() - - def receive: Actor.Receive = { case any ⇒ } - })) - } - })) ! "any" - } - - expectMsg(testTraceContext) - } - - "keep the TraceContext in the supervision cycle" when { - "the actor is resumed" in new TraceContextFixture { - val supervisor = supervisorWithDirective(Resume) - - Trace.withContext(testTraceContext) { - supervisor ! "fail" - } - - expectMsg(testTraceContext) // From the parent executing the supervision strategy - - // Ensure we didn't tie the actor with the context - supervisor ! "context" - expectMsg(None) - } - - "the actor is restarted" in new TraceContextFixture { - val supervisor = supervisorWithDirective(Restart, sendPreRestart = true, sendPostRestart = true) - - Trace.withContext(testTraceContext) { - supervisor ! "fail" - } - - expectMsg(testTraceContext) // From the parent executing the supervision strategy - expectMsg(testTraceContext) // From the preRestart hook - expectMsg(testTraceContext) // From the postRestart hook - - // Ensure we didn't tie the actor with the context - supervisor ! "context" - expectMsg(None) - } - - "the actor is stopped" in new TraceContextFixture { - val supervisor = supervisorWithDirective(Stop, sendPostStop = true) - - Trace.withContext(testTraceContext) { - supervisor ! "fail" - } - - expectMsg(testTraceContext) // From the parent executing the supervision strategy - expectMsg(testTraceContext) // From the postStop hook - expectNoMsg(1 second) - } - - "the failure is escalated" in new TraceContextFixture { - val supervisor = supervisorWithDirective(Escalate, sendPostStop = true) - - Trace.withContext(testTraceContext) { - supervisor ! "fail" - } - - expectMsg(testTraceContext) // From the parent executing the supervision strategy - expectMsg(testTraceContext) // From the grandparent executing the supervision strategy - expectMsg(testTraceContext) // From the postStop hook in the child - expectMsg(testTraceContext) // From the postStop hook in the parent - expectNoMsg(1 second) - } - } - } - - def supervisorWithDirective(directive: SupervisorStrategy.Directive, sendPreRestart: Boolean = false, sendPostRestart: Boolean = false, - sendPostStop: Boolean = false, sendPreStart: Boolean = false): ActorRef = { - class GrandParent extends Actor { - val child = context.actorOf(Props(new Parent)) - - override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() { - case NonFatal(throwable) ⇒ testActor ! Trace.context(); Stop - } - - def receive = { - case any ⇒ child forward any - } - } - - class Parent extends Actor { - val child = context.actorOf(Props(new Child)) - - override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() { - case NonFatal(throwable) ⇒ testActor ! Trace.context(); directive - } - - def receive: Actor.Receive = { - case any ⇒ child forward any - } - - override def postStop(): Unit = { - if (sendPostStop) testActor ! Trace.context() - super.postStop() - } - } - - class Child extends Actor { - def receive = { - case "fail" ⇒ 1 / 0 - case "context" ⇒ sender ! Trace.context() - } - - override def preRestart(reason: Throwable, message: Option[Any]): Unit = { - if (sendPreRestart) testActor ! Trace.context() - super.preRestart(reason, message) - } - - override def postRestart(reason: Throwable): Unit = { - if (sendPostRestart) testActor ! Trace.context() - super.postRestart(reason) - } - - override def postStop(): Unit = { - if (sendPostStop) testActor ! Trace.context() - super.postStop() - } - - override def preStart(): Unit = { - if (sendPreStart) testActor ! Trace.context() - super.preStart() - } - } - - system.actorOf(Props(new GrandParent)) - } -} diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala deleted file mode 100644 index 9df67391..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/AskPatternTracingSpec.scala +++ /dev/null @@ -1,59 +0,0 @@ -/* =================================================== - * Copyright © 2013 the kamon project <http://kamon.io/> - * - * 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.trace.instrumentation - -import akka.testkit.TestKit -import akka.actor.{ Props, Actor, ActorSystem } -import org.scalatest.{ Matchers, WordSpecLike } -import akka.event.Logging.Warning -import scala.concurrent.duration._ -import akka.pattern.ask -import akka.util.Timeout -import kamon.trace.{ Trace, ContextAware } -import org.scalatest.OptionValues._ - -class AskPatternTracingSpec extends TestKit(ActorSystem("ask-pattern-tracing-spec")) with WordSpecLike with Matchers { - - "the AskPatternTracing" should { - "log a warning with a stack trace and TraceContext taken from the moment the ask was triggered" in new TraceContextFixture { - implicit val ec = system.dispatcher - implicit val timeout = Timeout(10 milliseconds) - val noReply = system.actorOf(Props[NoReply]) - system.eventStream.subscribe(testActor, classOf[Warning]) - - within(500 milliseconds) { - val initialCtx = Trace.withContext(testTraceContext) { - noReply ? "hello" - Trace.context() - } - - val warn = expectMsgPF() { - case warn: Warning if warn.message.toString.contains("Timeout triggered for ask pattern") ⇒ warn - } - val capturedCtx = warn.asInstanceOf[ContextAware].traceContext - - capturedCtx should be('defined) - capturedCtx should equal(initialCtx) - } - } - } -} - -class NoReply extends Actor { - def receive = { - case any ⇒ - } -} diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala deleted file mode 100644 index a5554836..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/FutureTracingSpec.scala +++ /dev/null @@ -1,62 +0,0 @@ -/* =================================================== - * Copyright © 2013 the kamon project <http://kamon.io/> - * - * 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.trace.instrumentation - -import scala.concurrent.{ ExecutionContext, Await, Promise, Future } -import org.scalatest.{ Matchers, OptionValues, WordSpec } -import org.scalatest.concurrent.{ ScalaFutures, PatienceConfiguration } -import java.util.UUID -import scala.util.{ Random, Success } -import scala.concurrent.duration._ -import java.util.concurrent.TimeUnit -import akka.actor.{ Actor, ActorSystem } -import kamon.trace.{ Trace, TraceContext } - -class FutureTracingSpec extends WordSpec with Matchers with ScalaFutures with PatienceConfiguration with OptionValues { - - implicit val execContext = ExecutionContext.Implicits.global - - "a Future created with FutureTracing" should { - "capture the TraceContext available when created" which { - "must be available when executing the future's body" in new TraceContextFixture { - var future: Future[Option[TraceContext]] = _ - - Trace.withContext(testTraceContext) { - future = Future(Trace.context) - } - - whenReady(future)(ctxInFuture ⇒ - ctxInFuture should equal(testTraceContext)) - } - - "must be available when executing callbacks on the future" in new TraceContextFixture { - var future: Future[Option[TraceContext]] = _ - - Trace.withContext(testTraceContext) { - future = Future("Hello Kamon!") - // The TraceContext is expected to be available during all intermediate processing. - .map(_.length) - .flatMap(len ⇒ Future(len.toString)) - .map(s ⇒ Trace.context()) - } - - whenReady(future)(ctxInFuture ⇒ - ctxInFuture should equal(testTraceContext)) - } - } - } -} - diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/TraceAggregatorSpec.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/TraceAggregatorSpec.scala deleted file mode 100644 index 3b32f3ac..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/TraceAggregatorSpec.scala +++ /dev/null @@ -1,51 +0,0 @@ -/* =================================================== - * Copyright © 2013 the kamon project <http://kamon.io/> - * - * 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.trace.instrumentation - -import org.scalatest.{ WordSpecLike, WordSpec } -import akka.testkit.{ TestKitBase, TestKit } -import akka.actor.ActorSystem -import scala.concurrent.duration._ -import kamon.trace.UowTracing.{ Finish, Rename, Start } -import kamon.trace.{ UowTrace, UowTraceAggregator } - -class TraceAggregatorSpec extends TestKit(ActorSystem("TraceAggregatorSpec")) with WordSpecLike { - - "a TraceAggregator" should { - "send a UowTrace message out after receiving a Finish message" in new AggregatorFixture { - within(1 second) { - aggregator ! Start(1, "/accounts") - aggregator ! Finish(1) - - //expectMsg(UowTrace("UNKNOWN", Seq(Start(1, "/accounts"), Finish(1)))) - } - } - - "change the uow name after receiving a Rename message" in new AggregatorFixture { - within(1 second) { - aggregator ! Start(1, "/accounts") - aggregator ! Rename(1, "test-uow") - aggregator ! Finish(1) - - //expectMsg(UowTrace("test-uow", Seq(Start(1, "/accounts"), Finish(1)))) - } - } - } - - trait AggregatorFixture { - val aggregator = system.actorOf(UowTraceAggregator.props(testActor, 10 seconds)) - } -} diff --git a/kamon-trace/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala b/kamon-trace/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala deleted file mode 100644 index 62f7ec84..00000000 --- a/kamon-trace/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala +++ /dev/null @@ -1,10 +0,0 @@ -package kamon.trace.instrumentation - -import scala.util.Random -import kamon.trace.TraceContext -import akka.actor.Actor - -trait TraceContextFixture { - val random = new Random(System.nanoTime) - val testTraceContext = Some(TraceContext(Actor.noSender, random.nextInt)) -}
\ No newline at end of file |