aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-06-11 16:03:53 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-06-11 16:03:53 +0200
commit2fdd0125c48a703bd44ff93072c859b4fc65b766 (patch)
treeaa6a9022a9b093a8120213c152252b75e25e3b80 /kamon-core/src/test
parent942562d452bc1aa64ea6787702c47286c597a186 (diff)
downloadKamon-2fdd0125c48a703bd44ff93072c859b4fc65b766.tar.gz
Kamon-2fdd0125c48a703bd44ff93072c859b4fc65b766.tar.bz2
Kamon-2fdd0125c48a703bd44ff93072c859b4fc65b766.zip
use java.util.Duration
Diffstat (limited to 'kamon-core/src/test')
-rw-r--r--kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala (renamed from kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala)24
-rw-r--r--kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala16
-rw-r--r--kamon-core/src/test/scala/kamon/testkit/DefaultInstrumentFactory.scala28
3 files changed, 26 insertions, 42 deletions
diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala
index b4e3fe96..d742b54f 100644
--- a/kamon-core/src/test/scala/kamon/metric/instrument/CounterSpec.scala
+++ b/kamon-core/src/test/scala/kamon/metric/instrument/LongAdderCounterSpec.scala
@@ -13,15 +13,15 @@
* =========================================================================================
*/
-package kamon.metric.instrument
+package kamon
+package metric
-import kamon.testkit.DefaultInstrumentFactory
+import kamon.util.MeasurementUnit
import org.scalatest.{Matchers, WordSpec}
-class CounterSpec extends WordSpec with Matchers with DefaultInstrumentFactory {
-
- "a Counter" should {
+class LongAdderCounterSpec extends WordSpec with Matchers {
+ "a LongAdderCounter" should {
"allow unit and bundled increments" in {
val counter = buildCounter("unit-increments")
counter.increment()
@@ -40,7 +40,7 @@ class CounterSpec extends WordSpec with Matchers with DefaultInstrumentFactory {
counter.snapshot().value shouldBe 300
}
- "reset the internal state to zero after taking snapshots" in {
+ "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)
@@ -48,5 +48,17 @@ class CounterSpec extends WordSpec with Matchers with DefaultInstrumentFactory {
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
diff --git a/kamon-core/src/test/scala/kamon/testkit/DefaultInstrumentFactory.scala b/kamon-core/src/test/scala/kamon/testkit/DefaultInstrumentFactory.scala
deleted file mode 100644
index 0778a3bc..00000000
--- a/kamon-core/src/test/scala/kamon/testkit/DefaultInstrumentFactory.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-/* =========================================================================================
- * Copyright © 2013-2017 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.testkit
-
-import com.typesafe.config.ConfigFactory
-import kamon.metric.InstrumentFactory
-import kamon.util.MeasurementUnit
-import scala.concurrent.duration._
-
-trait DefaultInstrumentFactory {
- val instrumentFactory: InstrumentFactory = InstrumentFactory.fromConfig(ConfigFactory.load())
-
- def buildCounter(name: String) = instrumentFactory.buildCounter(name, Map.empty, MeasurementUnit.none)
- def buildMinMaxCounter(name: String) = instrumentFactory.buildMinMaxCounter(None, Some(1 hour))(name, Map.empty, MeasurementUnit.none)
-}