diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-06-11 17:04:16 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-06-11 17:04:16 +0200 |
commit | e9d2636be0a75bffacf0e48fc1b26d54207b18e7 (patch) | |
tree | 07de412a75f78031673e2e1d957d68e8e8dd55e5 /kamon-core/src/test/scala | |
parent | 2fdd0125c48a703bd44ff93072c859b4fc65b766 (diff) | |
download | Kamon-e9d2636be0a75bffacf0e48fc1b26d54207b18e7.tar.gz Kamon-e9d2636be0a75bffacf0e48fc1b26d54207b18e7.tar.bz2 Kamon-e9d2636be0a75bffacf0e48fc1b26d54207b18e7.zip |
add HistogramSpec, move counter and mmcounter specs
Diffstat (limited to 'kamon-core/src/test/scala')
-rw-r--r-- | kamon-core/src/test/scala/kamon/metric/HistogramSpec.scala | 69 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/metric/LongAdderCounterSpec.scala (renamed from kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala) | 3 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/metric/MinMaxCounterSpec.scala (renamed from kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala) | 3 |
3 files changed, 71 insertions, 4 deletions
diff --git a/kamon-core/src/test/scala/kamon/metric/HistogramSpec.scala b/kamon-core/src/test/scala/kamon/metric/HistogramSpec.scala new file mode 100644 index 00000000..ee0de53b --- /dev/null +++ b/kamon-core/src/test/scala/kamon/metric/HistogramSpec.scala @@ -0,0 +1,69 @@ +package kamon.metric + +import kamon.Kamon +import org.scalatest.{Matchers, WordSpec} +import kamon.util.MeasurementUnit._ + + +class HistogramSpec extends WordSpec with Matchers { + import HistogramTestHelper.HistogramMetricSyntax + + "a Histogram" should { + "record values and reset internal state when a snapshot is taken" in { + val histogram = Kamon.histogram("test", unit = time.nanoseconds) + histogram.record(100) + histogram.record(150, 998) + histogram.record(200) + + val distribution = histogram.distribution() + distribution.min shouldBe(100) + distribution.max shouldBe(200) + distribution.count shouldBe(1000) + distribution.buckets.length shouldBe 3 + distribution.buckets.map(b => (b.value, b.frequency)) should contain.allOf( + (100 -> 1), + (150 -> 998), + (200 -> 1) + ) + + val emptyDistribution = histogram.distribution() + emptyDistribution.min shouldBe(0) + emptyDistribution.max shouldBe(0) + emptyDistribution.count shouldBe(0) + emptyDistribution.buckets.length shouldBe 0 + } + + "[private api] record values and optionally keep the internal state when a snapshot is taken" in { + val histogram = Kamon.histogram("test", unit = time.nanoseconds) + histogram.record(100) + histogram.record(150, 998) + histogram.record(200) + + val distribution = { + histogram.distribution(resetState = false) // first one gets discarded + histogram.distribution(resetState = false) + } + + distribution.min shouldBe(100) + distribution.max shouldBe(200) + distribution.count shouldBe(1000) + distribution.buckets.length shouldBe 3 + distribution.buckets.map(b => (b.value, b.frequency)) should contain.allOf( + (100 -> 1), + (150 -> 998), + (200 -> 1) + ) + } + } +} + +object HistogramTestHelper { + + implicit class HistogramMetricSyntax(metric: HistogramMetric) { + def distribution(resetState: Boolean = true): Distribution = + metric.refine(Map.empty[String, String]) match { + case h: AtomicHdrHistogram => h.snapshot(resetState).distribution + case h: HdrHistogram => h.snapshot(resetState).distribution + } + } +} diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala b/kamon-core/src/test/scala/kamon/metric/LongAdderCounterSpec.scala index d742b54f..226b8f43 100644 --- a/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/LongAdderCounterSpec.scala @@ -13,8 +13,7 @@ * ========================================================================================= */ -package kamon -package metric +package kamon.metric import kamon.util.MeasurementUnit import org.scalatest.{Matchers, WordSpec} diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala b/kamon-core/src/test/scala/kamon/metric/MinMaxCounterSpec.scala index a21bcc96..062ae99d 100644 --- a/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/MinMaxCounterSpec.scala @@ -14,11 +14,10 @@ */ -package kamon.metric.instrument +package kamon.metric import java.time.Duration -import kamon.metric.{AtomicHdrHistogram, Bucket, DynamicRange, SimpleMinMaxCounter} import kamon.util.MeasurementUnit import org.scalatest.{Matchers, WordSpec} |