From 2fdd0125c48a703bd44ff93072c859b4fc65b766 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Sun, 11 Jun 2017 16:03:53 +0200 Subject: use java.util.Duration --- .../kamon/metric/instrument/CounterSpec.scala | 52 ------------------ .../metric/instrument/LongAdderCounterSpec.scala | 64 ++++++++++++++++++++++ .../metric/instrument/MinMaxCounterSpec.scala | 16 +++--- 3 files changed, 72 insertions(+), 60 deletions(-) delete mode 100644 kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala create mode 100644 kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala (limited to 'kamon-core/src/test/scala/kamon/metric') diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala deleted file mode 100644 index b4e3fe96..00000000 --- a/kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala +++ /dev/null @@ -1,52 +0,0 @@ -/* ========================================================================================= - * Copyright © 2013-2017 the kamon project - * - * 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.metric.instrument - -import kamon.testkit.DefaultInstrumentFactory -import org.scalatest.{Matchers, WordSpec} - -class CounterSpec extends WordSpec with Matchers with DefaultInstrumentFactory { - - "a Counter" should { - - "allow unit and bundled increments" in { - val counter = buildCounter("unit-increments") - counter.increment() - counter.increment() - counter.increment(40) - - counter.snapshot().value shouldBe 42 - } - - "warn the user and ignore attempts to decrement the counter" in { - val counter = buildCounter("attempt-to-decrement") - counter.increment(100) - counter.increment(100) - counter.increment(100) - - counter.snapshot().value shouldBe 300 - } - - "reset the internal state to zero after taking snapshots" in { - val counter = buildCounter("reset-after-snapshot") - counter.increment() - counter.increment(10) - - counter.snapshot().value shouldBe 11 - counter.snapshot().value shouldBe 0 - } - } -} diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala new file mode 100644 index 00000000..d742b54f --- /dev/null +++ b/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala @@ -0,0 +1,64 @@ +/* ========================================================================================= + * Copyright © 2013-2017 the kamon project + * + * 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 +package metric + +import kamon.util.MeasurementUnit +import org.scalatest.{Matchers, WordSpec} + +class LongAdderCounterSpec extends WordSpec with Matchers { + + "a LongAdderCounter" should { + "allow unit and bundled increments" in { + val counter = buildCounter("unit-increments") + counter.increment() + counter.increment() + counter.increment(40) + + counter.snapshot().value shouldBe 42 + } + + "warn the user and ignore attempts to decrement the counter" in { + val counter = buildCounter("attempt-to-decrement") + counter.increment(100) + counter.increment(100) + counter.increment(100) + + counter.snapshot().value shouldBe 300 + } + + "reset the internal state to zero after taking snapshots as a default behavior" in { + val counter = buildCounter("reset-after-snapshot") + counter.increment() + counter.increment(10) + + counter.snapshot().value shouldBe 11 + counter.snapshot().value shouldBe 0 + } + + "optionally leave the internal state unchanged" in { + val counter = buildCounter("reset-after-snapshot") + counter.increment() + counter.increment(10) + + counter.snapshot(resetState = false).value shouldBe 11 + counter.snapshot(resetState = false).value shouldBe 11 + } + } + + def buildCounter(name: String, tags: Map[String, String] = Map.empty, unit: MeasurementUnit = MeasurementUnit.none): LongAdderCounter = + new LongAdderCounter(name, tags, unit) +} diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala index b4c11dc2..a21bcc96 100644 --- a/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala @@ -16,16 +16,17 @@ package kamon.metric.instrument -import kamon.metric.Bucket -import kamon.testkit.DefaultInstrumentFactory +import java.time.Duration + +import kamon.metric.{AtomicHdrHistogram, Bucket, DynamicRange, SimpleMinMaxCounter} +import kamon.util.MeasurementUnit import org.scalatest.{Matchers, WordSpec} case class TemporalBucket(value: Long, frequency: Long) extends Bucket -class MinMaxCounterSpec extends WordSpec with Matchers with DefaultInstrumentFactory { +class MinMaxCounterSpec extends WordSpec with Matchers { "a MinMaxCounter" should { - "track ascending tendencies" in { val mmCounter = buildMinMaxCounter("track-ascending") mmCounter.increment() @@ -50,7 +51,6 @@ class MinMaxCounterSpec extends WordSpec with Matchers with DefaultInstrumentFac mmCounter.sample() val snapshot = mmCounter.snapshot() - snapshot.distribution.min should be(0) snapshot.distribution.max should be(5) } @@ -60,18 +60,15 @@ class MinMaxCounterSpec extends WordSpec with Matchers with DefaultInstrumentFac mmCounter.increment(5) mmCounter.decrement(3) - mmCounter.sample() val firstSnapshot = mmCounter.snapshot() - firstSnapshot.distribution.min should be(0) firstSnapshot.distribution.max should be(5) mmCounter.sample() val secondSnapshot = mmCounter.snapshot() - secondSnapshot.distribution.min should be(2) secondSnapshot.distribution.max should be(2) } @@ -89,4 +86,7 @@ class MinMaxCounterSpec extends WordSpec with Matchers with DefaultInstrumentFac snapshot.distribution.max should be(0) } } + + def buildMinMaxCounter(name: String, tags: Map[String, String] = Map.empty, unit: MeasurementUnit = MeasurementUnit.none): SimpleMinMaxCounter = + new SimpleMinMaxCounter(name, tags, new AtomicHdrHistogram(name, tags, unit, dynamicRange = DynamicRange.Default), Duration.ofMillis(100)) } \ No newline at end of file -- cgit v1.2.3