From acd725733d57d4db04f4564a8f616144a6dc1d3d Mon Sep 17 00:00:00 2001 From: Cory G Watson Date: Mon, 19 Sep 2011 17:29:55 -0500 Subject: [PATCH 1/2] Add clearCounter or clearing a specific counter. --- .../scala/com/twitter/ostrich/stats/StatsCollection.scala | 4 ++++ .../com/twitter/ostrich/stats/StatsCollectionSpec.scala | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala b/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala index 3ec38752..aedbadbc 100644 --- a/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala +++ b/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala @@ -134,6 +134,10 @@ class StatsCollection extends StatsProvider with JsonSerializable { counter } + def clearCounter(name: String) = { + counterMap.remove(name); + } + protected def newCounter(name: String) = { new Counter() } diff --git a/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala b/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala index c0044335..1c38102e 100644 --- a/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala +++ b/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala @@ -74,6 +74,14 @@ object StatsCollectionSpec extends Specification { collection.incr("widgets", -1) collection.getCounters() mustEqual Map("widgets" -> 2) } + + "clearCounter" in { + collection.getCounter("smellyfeet") + collection.incr("smellyfeet", 1) + collection.getCounters() mustEqual Map("smellyfeet" -> 1) + collection.clearCounter("smellyfeet") + collection.getCounters() mustEqual Map() + } } "metrics" in { From fd867cbbf5db28259bdf022a4abad753541b3df2 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 20 Sep 2011 00:15:13 -0700 Subject: [PATCH 2/2] rename to removeCounter --- .../com/twitter/ostrich/stats/StatsCollection.scala | 4 ++-- .../twitter/ostrich/stats/StatsCollectionSpec.scala | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala b/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala index aedbadbc..50df9bc5 100644 --- a/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala +++ b/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala @@ -134,8 +134,8 @@ class StatsCollection extends StatsProvider with JsonSerializable { counter } - def clearCounter(name: String) = { - counterMap.remove(name); + def removeCounter(name: String) { + counterMap.remove(name) } protected def newCounter(name: String) = { diff --git a/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala b/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala index 1c38102e..63ab982c 100644 --- a/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala +++ b/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala @@ -74,13 +74,13 @@ object StatsCollectionSpec extends Specification { collection.incr("widgets", -1) collection.getCounters() mustEqual Map("widgets" -> 2) } - + "clearCounter" in { - collection.getCounter("smellyfeet") - collection.incr("smellyfeet", 1) - collection.getCounters() mustEqual Map("smellyfeet" -> 1) - collection.clearCounter("smellyfeet") - collection.getCounters() mustEqual Map() + collection.getCounter("smellyfeet") + collection.incr("smellyfeet", 1) + collection.getCounters() mustEqual Map("smellyfeet" -> 1) + collection.removeCounter("smellyfeet") + collection.getCounters() mustEqual Map() } }