diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-08-13 00:13:21 -0400 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-08-13 00:13:21 -0400 |
commit | d2a2d590abf0f287d5d07edc00970f4c6069d20e (patch) | |
tree | 60de0f32639c1807a649d80096f3260bff707c7f /kamon-core/src/test | |
parent | 0777a6ff7b6c11f8f4a4e89ac27287b1a18449de (diff) | |
download | Kamon-d2a2d590abf0f287d5d07edc00970f4c6069d20e.tar.gz Kamon-d2a2d590abf0f287d5d07edc00970f4c6069d20e.tar.bz2 Kamon-d2a2d590abf0f287d5d07edc00970f4c6069d20e.zip |
= core: ensure that MinMaxCounters never record values bellow zero, fixes #71
Diffstat (limited to 'kamon-core/src/test')
-rw-r--r-- | kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala | 40 |
1 files changed, 37 insertions, 3 deletions
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 cb03664c..2c11adc3 100644 --- a/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/instrument/MinMaxCounterSpec.scala @@ -17,14 +17,15 @@ package kamon.metric.instrument import java.nio.LongBuffer -import akka.actor.ActorSystem +import akka.actor._ +import akka.testkit.TestProbe import com.typesafe.config.ConfigFactory import kamon.metric.CollectionContext import kamon.metric.instrument.Histogram.MutableRecord import org.scalatest.{ Matchers, WordSpecLike } class MinMaxCounterSpec extends WordSpecLike with Matchers { - val system = ActorSystem("min-max-counter-spec") + implicit val system = ActorSystem("min-max-counter-spec") val minMaxCounterConfig = ConfigFactory.parseString( """ |refresh-interval = 1 hour @@ -83,7 +84,7 @@ class MinMaxCounterSpec extends WordSpecLike with Matchers { MutableRecord(2, 3)) // min, max and current } - "report zero as the min and current values if they current value fell bellow zero" in new MinMaxCounterFixture { + "report zero as the min and current values if the current value fell bellow zero" in new MinMaxCounterFixture { mmCounter.decrement(3) val snapshot = collectCounterSnapshot() @@ -93,6 +94,22 @@ class MinMaxCounterSpec extends WordSpecLike with Matchers { snapshot.recordsIterator.toStream should contain( MutableRecord(0, 3)) // min, max and current (even while current really is -3 } + + "never record values bellow zero in very busy situations" in new MinMaxCounterFixture { + val monitor = TestProbe() + val workers = for (workers ← 1 to 50) yield { + system.actorOf(Props(new MinMaxCounterUpdateActor(mmCounter, monitor.ref))) + } + + workers foreach (_ ! "increment") + for (refresh ← 1 to 1000) { + collectCounterSnapshot() + Thread.sleep(10) + } + + monitor.expectNoMsg() + workers foreach (_ ! PoisonPill) + } } trait MinMaxCounterFixture { @@ -106,3 +123,20 @@ class MinMaxCounterSpec extends WordSpecLike with Matchers { def collectCounterSnapshot(): Histogram.Snapshot = mmCounter.collect(collectionContext) } } + +class MinMaxCounterUpdateActor(mmc: MinMaxCounter, monitor: ActorRef) extends Actor { + val x = Array.ofDim[Int](4) + def receive = { + case "increment" ⇒ + mmc.increment() + self ! "decrement" + case "decrement" ⇒ + mmc.decrement() + self ! "increment" + try { + mmc.refreshValues() + } catch { + case _: IndexOutOfBoundsException ⇒ monitor ! "failed" + } + } +}
\ No newline at end of file |