diff options
author | Ivan Topolnak <itopolnak@despegar.com> | 2014-03-07 18:08:01 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-03-11 21:14:53 -0300 |
commit | 54f37293b1faac5355c26a298db6b858114bc659 (patch) | |
tree | 14a4a6e156d163925664753d990f7d5bbe4b4084 /kamon-core/src/test/scala/kamon/metrics/TickMetricSnapshotBufferSpec.scala | |
parent | 60f8dd3be4593cb55e5c4023b7041ad94f6b8c8a (diff) | |
download | Kamon-54f37293b1faac5355c26a298db6b858114bc659.tar.gz Kamon-54f37293b1faac5355c26a298db6b858114bc659.tar.bz2 Kamon-54f37293b1faac5355c26a298db6b858114bc659.zip |
multiple fixes to the custom metrics collection facilities
Diffstat (limited to 'kamon-core/src/test/scala/kamon/metrics/TickMetricSnapshotBufferSpec.scala')
-rw-r--r-- | kamon-core/src/test/scala/kamon/metrics/TickMetricSnapshotBufferSpec.scala | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/metrics/TickMetricSnapshotBufferSpec.scala b/kamon-core/src/test/scala/kamon/metrics/TickMetricSnapshotBufferSpec.scala new file mode 100644 index 00000000..33200e2d --- /dev/null +++ b/kamon-core/src/test/scala/kamon/metrics/TickMetricSnapshotBufferSpec.scala @@ -0,0 +1,81 @@ +/* + * ========================================================================================= + * 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.metrics + +import org.scalatest.{ Matchers, WordSpecLike } +import akka.testkit.TestKit +import akka.actor.ActorSystem +import scala.concurrent.duration._ +import kamon.metrics.Subscriptions.TickMetricSnapshot +import kamon.metrics.MetricSnapshot.Measurement + +class TickMetricSnapshotBufferSpec extends TestKit(ActorSystem("tick-metric-snapshot-buffer")) with WordSpecLike with Matchers { + + "the TickMetricSnapshotBuffer" should { + "merge TickMetricSnapshots received until the flush timeout is reached and fix the from/to fields" in new SnapshotFixtures { + val buffer = system.actorOf(TickMetricSnapshotBuffer.props(3 seconds, testActor)) + + buffer ! firstEmpty + buffer ! secondEmpty + buffer ! thirdEmpty + + within(2 seconds)(expectNoMsg()) + val mergedSnapshot = expectMsgType[TickMetricSnapshot] + + mergedSnapshot.from should equal(1000) + mergedSnapshot.to should equal(4000) + mergedSnapshot.metrics should be('empty) + } + + "merge empty and non-empty snapshots" in new SnapshotFixtures { + val buffer = system.actorOf(TickMetricSnapshotBuffer.props(3 seconds, testActor)) + + buffer ! firstNonEmpty + buffer ! secondNonEmpty + buffer ! thirdEmpty + + within(2 seconds)(expectNoMsg()) + val mergedSnapshot = expectMsgType[TickMetricSnapshot] + + mergedSnapshot.from should equal(1000) + mergedSnapshot.to should equal(4000) + mergedSnapshot.metrics should not be ('empty) + + val testMetricSnapshot = mergedSnapshot.metrics(CustomMetric("test-metric")).metrics(CustomMetric.RecordedValues) + testMetricSnapshot.min should equal(1) + testMetricSnapshot.max should equal(10) + testMetricSnapshot.numberOfMeasurements should equal(35) + testMetricSnapshot.measurements should contain allOf (Measurement(1, 10), Measurement(4, 9), Measurement(10, 16)) + + } + } + + trait SnapshotFixtures { + val firstEmpty = TickMetricSnapshot(1000, 2000, Map.empty) + val secondEmpty = TickMetricSnapshot(2000, 3000, Map.empty) + val thirdEmpty = TickMetricSnapshot(3000, 4000, Map.empty) + + val firstNonEmpty = TickMetricSnapshot(1000, 2000, + Map((CustomMetric("test-metric") -> SimpleGroupSnapshot(Map(CustomMetric.RecordedValues -> MetricSnapshot(20, Scale.Unit, Vector(Measurement(1, 10), Measurement(10, 10)))))))) + + val secondNonEmpty = TickMetricSnapshot(1000, 2000, + Map((CustomMetric("test-metric") -> SimpleGroupSnapshot(Map(CustomMetric.RecordedValues -> MetricSnapshot(15, Scale.Unit, Vector(Measurement(4, 9), Measurement(10, 6)))))))) + + } + + case class SimpleGroupSnapshot(metrics: Map[MetricIdentity, MetricSnapshotLike]) extends MetricGroupSnapshot +} |