Permalink
Browse files

Added CounterMetric#clear().

  • Loading branch information...
1 parent 2833615 commit 8865a13d648a5245f8048bf4a7166ee2a1b61798 @codahale codahale committed Mar 23, 2011
@@ -8,7 +8,7 @@
* @author coda
*/
public class CounterMetric implements Metric {
- private final AtomicLong count = new AtomicLong();
+ private final AtomicLong count = new AtomicLong(0);
/**
* Increment the counter by one.
@@ -50,4 +50,11 @@ public void dec(long n) {
public long count() {
return count.get();
}
+
+ /**
+ * Resets the counter to 0.
+ */
+ public void clear() {
+ count.set(0);
+ }
}
@@ -34,6 +34,13 @@ object CounterMetricSpec extends Spec {
counter.count must beEqualTo(-3)
}
+
+ def `should be zero after being cleared` {
+ counter.inc(3)
+ counter.clear()
+
+ counter.count must beEqualTo(0)
+ }
}
}

0 comments on commit 8865a13

Please sign in to comment.