diff options
author | Diego <diegolparra@gmail.com> | 2014-05-07 22:45:34 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-05-07 22:45:34 -0300 |
commit | 1704a8515a73a806e594e980bfeee25ce36d3bae (patch) | |
tree | 5cf9d3f7da0a63e1ee232c30692e6d0e2a2c1521 /kamon-core/src | |
parent | f08cb7395f1b18cd473d876fa862bfdebe61788c (diff) | |
download | Kamon-1704a8515a73a806e594e980bfeee25ce36d3bae.tar.gz Kamon-1704a8515a73a806e594e980bfeee25ce36d3bae.tar.bz2 Kamon-1704a8515a73a806e594e980bfeee25ce36d3bae.zip |
= core: fixed ActorMetricsSpec
Diffstat (limited to 'kamon-core/src')
3 files changed, 25 insertions, 25 deletions
diff --git a/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala b/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala index 7766b3a1..9ef43bbe 100644 --- a/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala +++ b/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala @@ -24,7 +24,7 @@ import kamon.trace._ import kamon.metrics.{ ActorMetrics, Metrics } import kamon.Kamon import kamon.metrics.ActorMetrics.ActorMetricRecorder -import kamon.metrics.instruments.counter.{ Counter, MinMaxCounter } +import kamon.metrics.instruments.counter.MinMaxCounter @Aspect class BehaviourInvokeTracing { @@ -114,7 +114,7 @@ class BehaviourInvokeTracing { trait ActorCellMetrics { var metricIdentity: ActorMetrics = _ var actorMetricsRecorder: Option[ActorMetricRecorder] = _ - val queueSize: Counter = MinMaxCounter() + val queueSize = MinMaxCounter() } @Aspect diff --git a/kamon-core/src/main/scala/kamon/metrics/instruments/counter/MinMaxCounter.scala b/kamon-core/src/main/scala/kamon/metrics/instruments/counter/MinMaxCounter.scala index 052c7bcd..ed83f4bc 100644 --- a/kamon-core/src/main/scala/kamon/metrics/instruments/counter/MinMaxCounter.scala +++ b/kamon-core/src/main/scala/kamon/metrics/instruments/counter/MinMaxCounter.scala @@ -19,13 +19,7 @@ import java.lang.Math._ import jsr166e.LongMaxUpdater import kamon.util.PaddedAtomicLong -sealed trait Counter { - def increment(value: Long = 1L): Unit - def decrement(value: Long = 1L): Unit - def collect(): (Long, Long, Long) -} - -class MinMaxCounter extends Counter { +class MinMaxCounter { private val min = new LongMaxUpdater private val max = new LongMaxUpdater private val sum = new PaddedAtomicLong @@ -53,5 +47,5 @@ class MinMaxCounter extends Counter { } object MinMaxCounter { - def apply(): Counter = new MinMaxCounter() + def apply() = new MinMaxCounter() } diff --git a/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala b/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala index 2144bd55..0f0bb475 100644 --- a/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala +++ b/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala @@ -15,9 +15,9 @@ package kamon.metrics -import org.scalatest.{ WordSpecLike, Matchers } -import akka.testkit.{ TestProbe, TestKitBase } -import akka.actor.{ ActorRef, Actor, Props, ActorSystem } +import org.scalatest.{WordSpecLike, Matchers} +import akka.testkit.{TestProbe, TestKitBase} +import akka.actor.{ActorRef, Actor, Props, ActorSystem} import com.typesafe.config.ConfigFactory import scala.concurrent.duration._ import kamon.Kamon @@ -87,9 +87,10 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers { // process the tick in which the actor is stalled. val stalledTickMetrics = expectActorMetrics("user/tracked-mailbox-size-queueing-up", metricsListener, 2 seconds) - stalledTickMetrics.mailboxSize.numberOfMeasurements should equal(1) + stalledTickMetrics.mailboxSize.numberOfMeasurements should equal(31) // only the automatic last-value recording should be taken, and includes the message being currently processed. - stalledTickMetrics.mailboxSize.measurements should contain only (Measurement(10, 1)) + stalledTickMetrics.mailboxSize.measurements should contain only (Measurement(0, 10), Measurement(10, 21)) + stalledTickMetrics.mailboxSize.min should equal(0) stalledTickMetrics.mailboxSize.max should equal(10) stalledTickMetrics.processingTime.numberOfMeasurements should be(0L) stalledTickMetrics.timeInMailbox.numberOfMeasurements should be(0L) @@ -101,19 +102,20 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers { afterStallTickMetrics.processingTime.max should be(2500.milliseconds.toNanos +- 100.milliseconds.toNanos) afterStallTickMetrics.timeInMailbox.max should be(2500.milliseconds.toNanos +- 100.milliseconds.toNanos) } - } - "track the number of errors" in new ErrorActorFixture { - val (error, metricsListener) = failedActor("tracked-errors") + "track the number of errors" in new ErrorActorFixture { + val (error, metricsListener) = failedActor("tracked-errors") - for (_ ← 1 to 5) { - error ! Error - } + for (_ ← 1 to 5) { + error ! Error + } - val actorMetrics = expectActorMetrics("user/tracked-errors", metricsListener, 3 seconds) - actorMetrics.errorCounter.numberOfMeasurements should be(5L) + val actorMetrics = expectActorMetrics("user/tracked-errors", metricsListener, 3 seconds) + actorMetrics.errorCounter.numberOfMeasurements should be(5L) + } } + def expectActorMetrics(actorPath: String, listener: TestProbe, waitTime: FiniteDuration): ActorMetricSnapshot = { val tickSnapshot = within(waitTime) { listener.expectMsgType[TickMetricSnapshot] @@ -148,21 +150,25 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers { (actor, metricsListener) } } + } class DelayableActor extends Actor { def receive = { case Delay(time) ⇒ Thread.sleep(time.toMillis) - case Discard ⇒ + case Discard ⇒ } } class FailedActor extends Actor { def receive = { - case Error ⇒ 1 / 0 + case Error ⇒ 1 / 0 case Discard ⇒ } } + case object Discard + case class Delay(time: FiniteDuration) + case class Error() |