From 2b7367ae5687f34580b05ee5ea95d01ea30b95b5 Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 10 Nov 2017 10:59:00 -0300 Subject: add test for Metric::refine(java.util.Map) --- .../test/scala/kamon/metric/MetricLookupSpec.scala | 28 ++++++++++++++++++++++ .../src/test/scala/kamon/metric/TimerSpec.scala | 22 ++++++++--------- 2 files changed, 39 insertions(+), 11 deletions(-) (limited to 'kamon-core-tests/src/test') diff --git a/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala index 64ae1514..bcf703bd 100644 --- a/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala +++ b/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala @@ -15,6 +15,8 @@ package kamon.metric +import java.util.Collections.{singletonMap => javaMap} + import kamon.Kamon import org.scalatest.{Matchers, WordSpec} @@ -72,6 +74,32 @@ class MetricLookupSpec extends WordSpec with Matchers { minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterTwo) } } + + "refine a metric with java tags and" should { + "always return the same histogram for a set of tags" in { + val histogramOne = Kamon.histogram("histogram-lookup").refine(javaMap("tag", "value")) + val histogramTwo = Kamon.histogram("histogram-lookup").refine(javaMap("tag", "value")) + histogramOne shouldBe theSameInstanceAs(histogramTwo) + } + + "always return the same counter for a set of tags" in { + val counterOne = Kamon.counter("counter-lookup").refine(javaMap("tag", "value")) + val counterTwo = Kamon.counter("counter-lookup").refine(javaMap("tag", "value")) + counterOne shouldBe theSameInstanceAs(counterTwo) + } + + "always return the same gauge for a set of tags" in { + val gaugeOne = Kamon.gauge("gauge-lookup").refine(javaMap("tag", "value")) + val gaugeTwo = Kamon.gauge("gauge-lookup").refine(javaMap("tag", "value")) + gaugeOne shouldBe theSameInstanceAs(gaugeTwo) + } + + "always return the same min-max-counter for a set of tags" in { + val minMaxCounterOne = Kamon.minMaxCounter("min-max-counter-lookup").refine(javaMap("tag", "value")) + val minMaxCounterTwo = Kamon.minMaxCounter("min-max-counter-lookup").refine(javaMap("tag", "value")) + minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterTwo) + } + } } } diff --git a/kamon-core-tests/src/test/scala/kamon/metric/TimerSpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/TimerSpec.scala index 1d439b3a..834c38e5 100644 --- a/kamon-core-tests/src/test/scala/kamon/metric/TimerSpec.scala +++ b/kamon-core-tests/src/test/scala/kamon/metric/TimerSpec.scala @@ -29,7 +29,7 @@ class TimerSpec extends WordSpec with Matchers { timer.start().stop() timer.start().stop() - timer.distribution().count shouldBe(3) + timer.distribution().count shouldBe 3 } "ensure that a started timer can only be stopped once" in { @@ -39,7 +39,7 @@ class TimerSpec extends WordSpec with Matchers { startedTimer.stop() startedTimer.stop() - timer.distribution().count shouldBe(1) + timer.distribution().count shouldBe 1 } @@ -50,20 +50,20 @@ class TimerSpec extends WordSpec with Matchers { timer.record(200) val distribution = timer.distribution() - distribution.min shouldBe(100) - distribution.max shouldBe(200) - distribution.count shouldBe(1000) + 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) + 100 -> 1, + 150 -> 998, + 200 -> 1 ) val emptyDistribution = timer.distribution() - emptyDistribution.min shouldBe(0) - emptyDistribution.max shouldBe(0) - emptyDistribution.count shouldBe(0) + emptyDistribution.min shouldBe 0 + emptyDistribution.max shouldBe 0 + emptyDistribution.count shouldBe 0 emptyDistribution.buckets.length shouldBe 0 } } -- cgit v1.2.3 From 2fed24c227af6cd16aa517615f237977dd1a447b Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 10 Nov 2017 11:17:50 -0300 Subject: minor refactor in MetricLookupSpec --- .../test/scala/kamon/metric/MetricLookupSpec.scala | 37 +++++++--------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'kamon-core-tests/src/test') diff --git a/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala index bcf703bd..4df2397b 100644 --- a/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala +++ b/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala @@ -53,53 +53,38 @@ class MetricLookupSpec extends WordSpec with Matchers { "always return the same histogram for a set of tags" in { val histogramOne = Kamon.histogram("histogram-lookup").refine("tag" -> "value") val histogramTwo = Kamon.histogram("histogram-lookup").refine("tag" -> "value") + val histogramThree = Kamon.histogram("histogram-lookup").refine(javaMap("tag", "value")) + histogramOne shouldBe theSameInstanceAs(histogramTwo) + histogramOne shouldBe theSameInstanceAs(histogramThree) } "always return the same counter for a set of tags" in { val counterOne = Kamon.counter("counter-lookup").refine("tag" -> "value") val counterTwo = Kamon.counter("counter-lookup").refine("tag" -> "value") + val counterThree = Kamon.counter("counter-lookup").refine(javaMap("tag", "value")) + counterOne shouldBe theSameInstanceAs(counterTwo) + counterOne shouldBe theSameInstanceAs(counterThree) } "always return the same gauge for a set of tags" in { val gaugeOne = Kamon.gauge("gauge-lookup").refine("tag" -> "value") val gaugeTwo = Kamon.gauge("gauge-lookup").refine("tag" -> "value") + val gaugeThree = Kamon.gauge("gauge-lookup").refine(javaMap("tag", "value")) + gaugeOne shouldBe theSameInstanceAs(gaugeTwo) + gaugeOne shouldBe theSameInstanceAs(gaugeThree) } "always return the same min-max-counter for a set of tags" in { val minMaxCounterOne = Kamon.minMaxCounter("min-max-counter-lookup").refine("tag" -> "value") val minMaxCounterTwo = Kamon.minMaxCounter("min-max-counter-lookup").refine("tag" -> "value") - minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterTwo) - } - } - - "refine a metric with java tags and" should { - "always return the same histogram for a set of tags" in { - val histogramOne = Kamon.histogram("histogram-lookup").refine(javaMap("tag", "value")) - val histogramTwo = Kamon.histogram("histogram-lookup").refine(javaMap("tag", "value")) - histogramOne shouldBe theSameInstanceAs(histogramTwo) - } + val minMaxCounterThree = Kamon.minMaxCounter("min-max-counter-lookup").refine(javaMap("tag", "value")) - "always return the same counter for a set of tags" in { - val counterOne = Kamon.counter("counter-lookup").refine(javaMap("tag", "value")) - val counterTwo = Kamon.counter("counter-lookup").refine(javaMap("tag", "value")) - counterOne shouldBe theSameInstanceAs(counterTwo) - } - - "always return the same gauge for a set of tags" in { - val gaugeOne = Kamon.gauge("gauge-lookup").refine(javaMap("tag", "value")) - val gaugeTwo = Kamon.gauge("gauge-lookup").refine(javaMap("tag", "value")) - gaugeOne shouldBe theSameInstanceAs(gaugeTwo) - } - - "always return the same min-max-counter for a set of tags" in { - val minMaxCounterOne = Kamon.minMaxCounter("min-max-counter-lookup").refine(javaMap("tag", "value")) - val minMaxCounterTwo = Kamon.minMaxCounter("min-max-counter-lookup").refine(javaMap("tag", "value")) minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterTwo) + minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterThree) } } } - } -- cgit v1.2.3