diff options
author | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-05 18:38:39 -0300 |
---|---|---|
committer | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-05 18:38:39 -0300 |
commit | 26003feac484c971abf7639dc3adb628c5f118c3 (patch) | |
tree | c22effcf90aea23af6ce23beff4735c7de59131a /kamon-core/src/test/scala | |
parent | 84711adba09c64b75369f8b801819a90198238c6 (diff) | |
download | Kamon-26003feac484c971abf7639dc3adb628c5f118c3.tar.gz Kamon-26003feac484c971abf7639dc3adb628c5f118c3.tar.bz2 Kamon-26003feac484c971abf7639dc3adb628c5f118c3.zip |
basic separation of concerns between sub-projects
Diffstat (limited to 'kamon-core/src/test/scala')
7 files changed, 0 insertions, 359 deletions
diff --git a/kamon-core/src/test/scala/ExtraSpec.scala b/kamon-core/src/test/scala/ExtraSpec.scala deleted file mode 100644 index b8dc053d..00000000 --- a/kamon-core/src/test/scala/ExtraSpec.scala +++ /dev/null @@ -1,34 +0,0 @@ -import akka.actor.ActorSystem -import akka.testkit.TestKit -import org.scalatest.WordSpecLike -import shapeless._ - -class ExtraSpec extends TestKit(ActorSystem("ExtraSpec")) with WordSpecLike { - - "the Extra pattern helper" should { - "be constructed from a finite number of types" in { - Extra.expecting[String :: Int :: HNil].as[Person] - } - } - - case class Person(name: String, age: Int) -} - -/** - * Desired Features: - * 1. Expect messages of different types, apply a function and forward to some other. - */ - -object Extra { - def expecting[T <: HList] = new Object { - def as[U <: Product] = ??? - } -} - -/* -extra of { - expect[A] in { actor ! msg} - expect[A] in { actor ! msg} -} as (A, A) pipeTo (z)*/ - - diff --git a/kamon-core/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala b/kamon-core/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala deleted file mode 100644 index cdfa2813..00000000 --- a/kamon-core/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala +++ /dev/null @@ -1,94 +0,0 @@ -package akka.instrumentation - -import org.scalatest.{WordSpecLike, Matchers} -import akka.actor.{ActorRef, Actor, Props, ActorSystem} - -import akka.testkit.{ImplicitSender, TestKit} -import kamon.{Tracer} -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 ActorInstrumentationSpec extends TestKit(ActorSystem("ActorInstrumentationSpec")) with WordSpecLike with Matchers with ImplicitSender { - implicit val executionContext = system.dispatcher - - "an instrumented actor ref" when { - "used inside the context of a transaction" should { - "propagate the trace context using bang" in new TraceContextEchoFixture { - echo ! "test" - - expectMsg(Some(testTraceContext)) - } - - "propagate the trace context using tell" in new TraceContextEchoFixture { - echo.tell("test", testActor) - - expectMsg(Some(testTraceContext)) - } - - "propagate the trace context using ask" in new TraceContextEchoFixture { - implicit val timeout = Timeout(1 seconds) - (echo ? "test") pipeTo(testActor) - - expectMsg(Some(testTraceContext)) - } - - "propagate the trace context to actors behind a router" in new RoutedTraceContextEchoFixture { - val contexts: Seq[Option[TraceContext]] = for(_ <- 1 to 10) yield Some(tellWithNewContext(echo, "test")) - - expectMsgAllOf(contexts: _*) - } - - /*"propagate with many asks" in { - val echo = system.actorOf(Props[TraceContextEcho]) - val iterations = 50000 - implicit val timeout = Timeout(10 seconds) - - val futures = for(_ <- 1 to iterations) yield { - Tracer.start - val result = (echo ? "test") - Tracer.clear - - result - } - - val allResults = Await.result(Future.sequence(futures), 10 seconds) - assert(iterations == allResults.collect { - case Some(_) => 1 - }.sum) - }*/ - } - } - - trait TraceContextEchoFixture { - val testTraceContext = Tracer.newTraceContext() - val echo = system.actorOf(Props[TraceContextEcho]) - - Tracer.set(testTraceContext) - } - - trait RoutedTraceContextEchoFixture extends TraceContextEchoFixture { - override val echo = system.actorOf(Props[TraceContextEcho].withRouter(RoundRobinRouter(nrOfInstances = 10))) - - def tellWithNewContext(target: ActorRef, message: Any): TraceContext = { - val context = Tracer.newTraceContext() - Tracer.set(context) - - target ! message - context - } - } - -} - -class TraceContextEcho extends Actor { - def receive = { - case msg: String ⇒ sender ! Tracer.context() - } -} - - diff --git a/kamon-core/src/test/scala/kamon/instrumentation/ActorSystemInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/ActorSystemInstrumentationSpec.scala deleted file mode 100644 index 1eab6355..00000000 --- a/kamon-core/src/test/scala/kamon/instrumentation/ActorSystemInstrumentationSpec.scala +++ /dev/null @@ -1,22 +0,0 @@ -package kamon.instrumentation - -import org.scalatest.{Matchers, WordSpec} -import akka.actor.ActorSystem -import kamon.Kamon - -class ActorSystemInstrumentationSpec extends WordSpec with Matchers { - - // TODO: Selection filters to exclude unwanted actor systems. Read from configuration. - - "the actor system instrumentation" should { - "register all actor systems created" in { - val as1 = ActorSystem("as1") - val as2 = ActorSystem("as2") - - - Kamon.Metric.actorSystem("as1") should not be (None) - Kamon.Metric.actorSystem("as2") should not be (None) - Kamon.Metric.actorSystem("unknown") should be (None) - } - } -} diff --git a/kamon-core/src/test/scala/kamon/instrumentation/DispatcherInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/DispatcherInstrumentationSpec.scala deleted file mode 100644 index 89ef61f3..00000000 --- a/kamon-core/src/test/scala/kamon/instrumentation/DispatcherInstrumentationSpec.scala +++ /dev/null @@ -1,34 +0,0 @@ -package kamon.instrumentation - -import org.scalatest.{Matchers, WordSpec} -import akka.actor.{Actor, Props, ActorSystem} -import kamon.metric.MetricDirectory -import kamon.Kamon - -class DispatcherInstrumentationSpec extends WordSpec with Matchers{ - - - "the dispatcher instrumentation" should { - "instrument a dispatcher that belongs to a non-filtered actor system" in new SingleDispatcherActorSystem { - val x = Kamon.Metric.actorSystem("single-dispatcher").get.dispatchers - (1 to 10).foreach(actor ! _) - - val active = x.get("akka.actor.default-dispatcher").get.activeThreadCount.snapshot - println("Active max: "+active.max) - println("Active min: "+active.min) - - } - } - - - trait SingleDispatcherActorSystem { - val actorSystem = ActorSystem("single-dispatcher") - val actor = actorSystem.actorOf(Props(new Actor { - def receive = { - case a => sender ! a; - } - })) - - } -} - diff --git a/kamon-core/src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala deleted file mode 100644 index cc55ec92..00000000 --- a/kamon-core/src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala +++ /dev/null @@ -1,53 +0,0 @@ -package kamon.instrumentation - -import org.scalatest.WordSpec -import com.codahale.metrics.{ExponentiallyDecayingReservoir, Histogram} -import java.util.concurrent.ConcurrentLinkedQueue -import akka.dispatch.{UnboundedMessageQueueSemantics, QueueBasedMessageQueue, Envelope} -import java.util.Queue -import akka.actor.{ActorSystem, Actor} - -class MessageQueueInstrumentationSpec(val actorSystem: ActorSystem) extends WordSpec { - def this() = this(ActorSystem("MessageQueueInstrumentationSpec")) - - - /*"A MonitoredMessageQueue" should { - "update the related histogram when a message is enqueued" in { - new PopulatedMessageQueueFixture { - - assert(histogram.getSnapshot.getMax === 0) - - for(i <- 1 to 3) { enqueueDummyMessage } - - assert(histogram.getCount === 3) - assert(histogram.getSnapshot.getMax === 3) - assert(histogram.getSnapshot.getMin === 1) - } - } - - "update the related histogram when a message is dequeued" in { - new PopulatedMessageQueueFixture { - for(i <- 1 to 3) { enqueueDummyMessage } - assert(histogram.getSnapshot.getMax === 3) - - messageQueue.dequeue() - messageQueue.dequeue() - - assert(histogram.getCount === 5) - assert(histogram.getSnapshot.getMax === 3) - assert(histogram.getSnapshot.getMin === 1) - } - } - } - - trait PopulatedMessageQueueFixture { - - val histogram = new Histogram(new ExponentiallyDecayingReservoir()) -/* val delegate = new ConcurrentLinkedQueue[Envelope]() with QueueBasedMessageQueue with UnboundedMessageQueueSemantics { - final def queue: Queue[Envelope] = this - }*/ - val messageQueue = new MonitoredMessageQueue(delegate, histogram) - - def enqueueDummyMessage = messageQueue.enqueue(Actor.noSender, Envelope("", Actor.noSender, actorSystem)) - }*/ -} diff --git a/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala deleted file mode 100644 index 570f64dd..00000000 --- a/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala +++ /dev/null @@ -1,86 +0,0 @@ -package kamon.instrumentation - -import scala.concurrent.{Await, Promise, Future} -import org.scalatest.{Matchers, OptionValues, WordSpec} -import org.scalatest.concurrent.{ScalaFutures, PatienceConfiguration} -import kamon.{Tracer, Kamon} -import java.util.UUID -import scala.util.Success -import scala.concurrent.duration._ -import java.util.concurrent.TimeUnit -import akka.actor.ActorSystem -import kamon.trace.TraceContext - - -class RunnableInstrumentationSpec extends WordSpec with Matchers with ScalaFutures with PatienceConfiguration with OptionValues { - - "a instrumented runnable" when { - "created in a thread that does have a TraceContext" must { - "preserve the TraceContext" which { - "should be available during the run method execution" in new FutureWithContextFixture { - - whenReady(futureWithContext) { result => - result.value should equal(testContext) - } - } - - "should be available during the execution of onComplete callbacks" in new FutureWithContextFixture { - - val onCompleteContext = Promise[Option[TraceContext]]() - - Tracer.traceContext.withValue(Some(testContext)) { - futureWithContext.onComplete({ - case _ => println("Completing second promise from: "+Thread.currentThread().getName + " With Context: " + Tracer.traceContext.value); onCompleteContext.complete(Success(Tracer.traceContext.value)) - }) - } - - whenReady(onCompleteContext.future) { result => - result should equal(Some(testContext)) - } - } - } - } - - "created in a thread that doest have a TraceContext" must { - "not capture any TraceContext for the body execution" in new FutureWithoutContextFixture{ - whenReady(futureWithoutContext) { result => - result should equal(None) - } - } - - "not make any TraceContext available during the onComplete callback" in new FutureWithoutContextFixture { - val onCompleteContext = Promise[Option[TraceContext]]() - - futureWithoutContext.onComplete { - case _ => onCompleteContext.complete(Success(Tracer.traceContext.value)) - } - - whenReady(onCompleteContext.future) { result => - result should equal(None) - } - } - } - } - - - /** - * We are using Futures for the test since they exercise Runnables in the back and also resemble the real use case we have. - */ - implicit val testActorSystem = ActorSystem("test-actorsystem") - implicit val execContext = testActorSystem.dispatcher - - class FutureWithContextFixture { - val testContext = TraceContext() - - var futureWithContext: Future[Option[TraceContext]] = _ - Tracer.traceContext.withValue(Some(testContext)) { - futureWithContext = Future { Tracer.traceContext.value } - } - } - - trait FutureWithoutContextFixture { - val futureWithoutContext = Future { Tracer.traceContext.value } - } -} - - diff --git a/kamon-core/src/test/scala/kamon/trace/TraceAggregatorSpec.scala b/kamon-core/src/test/scala/kamon/trace/TraceAggregatorSpec.scala deleted file mode 100644 index 60b5f06d..00000000 --- a/kamon-core/src/test/scala/kamon/trace/TraceAggregatorSpec.scala +++ /dev/null @@ -1,36 +0,0 @@ -package kamon.trace - -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} - -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() - aggregator ! Finish() - - expectMsg(UowTrace("UNKNOWN", Seq(Start(), Finish()))) - } - } - - "change the uow name after receiving a Rename message" in new AggregatorFixture { - within(1 second) { - aggregator ! Start() - aggregator ! Rename("test-uow") - aggregator ! Finish() - - expectMsg(UowTrace("test-uow", Seq(Start(), Finish()))) - } - } - } - - - trait AggregatorFixture { - val aggregator = system.actorOf(UowTraceAggregator.props(testActor, 10 seconds)) - } -} |