aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test/scala
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-05-01 19:49:22 -0300
committerDiego <diegolparra@gmail.com>2014-05-01 19:49:22 -0300
commit2880da2f2d97813b05b2cd07c747cfa96dd812e0 (patch)
tree2fc5da910771aa3a40163b4dc4cd03839d46d9d9 /kamon-core/src/test/scala
parent77bb479f2b839d148e2f05f8911bae94f3170df1 (diff)
downloadKamon-2880da2f2d97813b05b2cd07c747cfa96dd812e0.tar.gz
Kamon-2880da2f2d97813b05b2cd07c747cfa96dd812e0.tar.bz2
Kamon-2880da2f2d97813b05b2cd07c747cfa96dd812e0.zip
! core: first implementetion of kamon counter intrument and actor errors metrics
Diffstat (limited to 'kamon-core/src/test/scala')
-rw-r--r--kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala31
-rw-r--r--kamon-core/src/test/scala/kamon/metrics/MetricSnapshotSpec.scala9
2 files changed, 38 insertions, 2 deletions
diff --git a/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala b/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala
index 61d15bc9..2144bd55 100644
--- a/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala
+++ b/kamon-core/src/test/scala/kamon/metrics/ActorMetricsSpec.scala
@@ -103,6 +103,17 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers {
}
}
+ "track the number of errors" in new ErrorActorFixture {
+ val (error, metricsListener) = failedActor("tracked-errors")
+
+ for (_ ← 1 to 5) {
+ error ! Error
+ }
+
+ 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]
@@ -124,6 +135,19 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers {
(actor, metricsListener)
}
}
+
+ trait ErrorActorFixture {
+ def failedActor(name: String): (ActorRef, TestProbe) = {
+ val actor = system.actorOf(Props[FailedActor], name)
+ val metricsListener = TestProbe()
+
+ Kamon(Metrics).subscribe(ActorMetrics, "user/" + name, metricsListener.ref, permanently = true)
+ // Wait for one empty snapshot before proceeding to the test.
+ metricsListener.expectMsgType[TickMetricSnapshot]
+
+ (actor, metricsListener)
+ }
+ }
}
class DelayableActor extends Actor {
@@ -133,5 +157,12 @@ class DelayableActor extends Actor {
}
}
+class FailedActor extends Actor {
+ def receive = {
+ case Error ⇒ 1 / 0
+ case Discard ⇒
+ }
+}
case object Discard
case class Delay(time: FiniteDuration)
+case class Error()
diff --git a/kamon-core/src/test/scala/kamon/metrics/MetricSnapshotSpec.scala b/kamon-core/src/test/scala/kamon/metrics/MetricSnapshotSpec.scala
index b4f33ec3..4d6ebc49 100644
--- a/kamon-core/src/test/scala/kamon/metrics/MetricSnapshotSpec.scala
+++ b/kamon-core/src/test/scala/kamon/metrics/MetricSnapshotSpec.scala
@@ -25,25 +25,28 @@ class MetricSnapshotSpec extends WordSpec with Matchers {
"support a max operation" in new SnapshotFixtures {
snapshotA.max should be(17)
snapshotB.max should be(10)
+ snapshotC.max should be(1)
}
"support a min operation" in new SnapshotFixtures {
snapshotA.min should be(1)
snapshotB.min should be(2)
+ snapshotC.min should be(1)
}
"be able to merge with other snapshot" in new SnapshotFixtures {
- val merged = snapshotA.merge(snapshotB)
+ val merged = snapshotA.merge(snapshotB).merge(snapshotC)
merged.min should be(1)
merged.max should be(17)
- merged.numberOfMeasurements should be(200)
+ merged.numberOfMeasurements should be(300)
merged.measurements.map(_.value) should contain inOrderOnly (1, 2, 4, 5, 7, 10, 17)
}
"be able to merge with empty snapshots" in new SnapshotFixtures {
snapshotA.merge(emptySnapshot) should be(snapshotA)
emptySnapshot.merge(snapshotA).merge(emptySnapshot) should be(snapshotA)
+ snapshotC.merge(emptySnapshot) should be(snapshotC)
}
}
@@ -63,5 +66,7 @@ class MetricSnapshotSpec extends WordSpec with Matchers {
Measurement(4, 48),
Measurement(5, 39),
Measurement(10, 7)))
+
+ val snapshotC = MetricSnapshot(InstrumentTypes.Counter, 100, Scale.Unit, Vector(Measurement(1, 100)))
}
}