diff --git a/metrics-clojure-core/src/metrics/timers.clj b/metrics-clojure-core/src/metrics/timers.clj index 3628c86..935d854 100644 --- a/metrics-clojure-core/src/metrics/timers.clj +++ b/metrics-clojure-core/src/metrics/timers.clj @@ -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 @@ -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." diff --git a/metrics-clojure-core/test/metrics/test/timers_test.clj b/metrics-clojure-core/test/metrics/test/timers_test.clj index afb6074..c31097c 100644 --- a/metrics-clojure-core/test/metrics/test/timers_test.clj +++ b/metrics-clojure-core/test/metrics/test/timers_test.clj @@ -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) @@ -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)) @@ -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))))) \ No newline at end of file