aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorIvan Topolnak <ivantopo@gmail.com>2013-06-14 18:33:23 -0300
committerIvan Topolnak <ivantopo@gmail.com>2013-06-14 18:33:23 -0300
commit658bdd03a3b549cf7225197388e1e18b01723f1f (patch)
treec88228d013324519d29aad6edebaa1fd65145c28 /src/test
parent80725fd14a728c6afcc9d8b3ac7c4bd10e8bd05e (diff)
downloadKamon-658bdd03a3b549cf7225197388e1e18b01723f1f.tar.gz
Kamon-658bdd03a3b549cf7225197388e1e18b01723f1f.tar.bz2
Kamon-658bdd03a3b549cf7225197388e1e18b01723f1f.zip
minor cleanup, still working in metrics
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala19
-rw-r--r--src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala53
-rw-r--r--src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala2
-rw-r--r--src/test/scala/kamon/instrumentation/ScalaFuturesSupport.scala (renamed from src/test/scala/kamon/instrumentation/ScalaFutures.scala)2
4 files changed, 66 insertions, 10 deletions
diff --git a/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala b/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala
index c3606d23..15e967f2 100644
--- a/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala
+++ b/src/test/scala/akka/instrumentation/ActorInstrumentationSpec.scala
@@ -5,10 +5,11 @@ import org.scalatest.matchers.{ShouldMatchers, MustMatchers}
import akka.actor.{Actor, Props, ActorSystem}
import kamon.metric.Metrics._
import scala.collection.JavaConverters._
+import akka.testkit.TestActorRef
class ActorInstrumentationSpec extends WordSpec with MustMatchers with ShouldMatchers {
- val system = ActorSystem()
+ implicit val system = ActorSystem()
import system._
val echoRef = actorOf(Props(new EchoActor), "Echo-Actor")
@@ -18,16 +19,18 @@ class ActorInstrumentationSpec extends WordSpec with MustMatchers with ShouldMat
"an instrumented Actor" should {
"send a message and record a metric on the Metrics Registry with the number of sent messages" in {
+ val echoActor = TestActorRef[EchoActor]
+
+
+
(1 to totalMessages).foreach {x:Int =>
- echoRef ! s"Message ${x}"
+ echoActor ! s"Message ${x}"
}
- //to ensure that all messages was received
- Thread.sleep(1000)
-
- val messages = registry.getMeters.asScala.get(meterForEchoActor).get.getCount
+ println("After all")
+ //val messages = registry.getMeters.asScala.get(meterForEchoActor).get.getCount
- messages should equal(totalMessages)
+ //messages should equal(totalMessages)
}
}
@@ -35,7 +38,7 @@ class ActorInstrumentationSpec extends WordSpec with MustMatchers with ShouldMat
class EchoActor extends Actor {
def receive = {
- case msg ⇒ sender ! msg
+ case msg ⇒ println("SOME"); sender ! msg
}
}
diff --git a/src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala b/src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala
new file mode 100644
index 00000000..d672b975
--- /dev/null
+++ b/src/test/scala/kamon/instrumentation/MessageQueueInstrumentationSpec.scala
@@ -0,0 +1,53 @@
+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/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala b/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
index 4fe9e617..359766b6 100644
--- a/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
+++ b/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala
@@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit
import akka.actor.ActorSystem
-class RunnableInstrumentationSpec extends WordSpec with MustMatchers with ScalaFutures with PatienceConfiguration with OptionValues {
+class RunnableInstrumentationSpec extends WordSpec with MustMatchers with ScalaFuturesSupport with PatienceConfiguration with OptionValues {
"a instrumented runnable" when {
"created in a thread that does have a TraceContext" must {
diff --git a/src/test/scala/kamon/instrumentation/ScalaFutures.scala b/src/test/scala/kamon/instrumentation/ScalaFuturesSupport.scala
index 169b709c..cc87a7c8 100644
--- a/src/test/scala/kamon/instrumentation/ScalaFutures.scala
+++ b/src/test/scala/kamon/instrumentation/ScalaFuturesSupport.scala
@@ -6,7 +6,7 @@ import scala.util.{Failure, Success}
import org.scalatest.concurrent.Futures
import java.util.concurrent.TimeUnit
-trait ScalaFutures extends Futures {
+trait ScalaFuturesSupport extends Futures {
implicit def scalaFutureToFutureConcept[T](future: Future[T]): FutureConcept[T] = new FutureConcept[T] {
def eitherValue: Option[Either[Throwable, T]] = {
if(!future.isCompleted)