Skip to content

Commit

Permalink
Implemented #139, and fixed a broken compilation issue in a test (not…
Browse files Browse the repository at this point in the history
… sure what's wrong with that test though... sorry)
  • Loading branch information
eranharel committed Nov 7, 2018
1 parent 208c07b commit 5accaee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion metrics-clojure-core/src/metrics/timers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [metrics.core :refer [default-registry metric-name]]
[metrics.utils :refer [get-percentiles desugared-title snapshot]])
(:import [com.codahale.metrics MetricRegistry Reservoir Timer Timer$Context]
java.util.concurrent.TimeUnit))
[java.util.concurrent TimeUnit]))


(defn ^com.codahale.metrics.Timer timer
Expand Down Expand Up @@ -120,6 +120,9 @@
[^Timer t ^clojure.lang.IFn f]
(.time t ^Callable f))

(defn update! [^Timer t ^long duration, ^TimeUnit unit]
(.update t duration unit))

(defn start
"Start a timer, returning the context object that will be used to
stop this particular instance."
Expand Down
13 changes: 11 additions & 2 deletions metrics-clojure-core/test/metrics/test/timers_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:require [metrics.core :as mc]
[metrics.timers :as mt]
[metrics.test.test-utils :refer :all]
[clojure.test :refer :all]))
[clojure.test :refer :all])
(:import [java.util.concurrent TimeUnit]))

(def ^:const expiration-delay 6000)

Expand All @@ -18,7 +19,7 @@

(let [reg (mc/new-registry)]
(mt/deftimer reg ["test" "timers" "deftimered"])
(mt/deftimer reg (mc/uniform-reservior) deftimered-3-arity)
(mt/deftimer reg (mc/uniform-reservoir) deftimered-3-arity)

(deftest test-deftimer
(is (= (mt/rate-mean deftimered) 0.0))
Expand Down Expand Up @@ -116,3 +117,11 @@
(is (= java.lang.Long
(.getClass (mt/number-recorded t)))))))

(deftest test-update-timer
(let [r (mc/new-registry)
t (mt/timer r ["test" "timers" "test-update-timer"])
expected-time 666
expected-time-unit TimeUnit/SECONDS]
(is (= 0 (mt/largest t)))
(mt/update! t expected-time expected-time-unit)
(is (= (.toNanos expected-time-unit expected-time) (mt/largest t)))))

0 comments on commit 5accaee

Please sign in to comment.