Skip to content

Commit

Permalink
Merge branch 'master' of github.com:aphyr/riemann-clojure-client
Browse files Browse the repository at this point in the history
  • Loading branch information
aphyr committed Apr 5, 2014
2 parents 35db57e + f5d8c68 commit 11bafaa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/riemann/codec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@
"Transforms a java protobuf to an Event."
[^Proto$Event e]
(Event.
(when (.hasHost e) (.getHost e))
(when (.hasService e) (.getService e))
(when (.hasState e) (.getState e))
(when (.hasHost e) (.getHost e))
(when (.hasService e) (.getService e))
(when (.hasState e) (.getState e))
(when (.hasDescription e) (.getDescription e))
(cond
(.hasMetricSint64 e) (.getMetricSint64 e)
(.hasMetricD e) (.getMetricD e)
(.hasMetricF e) (.getMetricF e))
(.hasMetricSint64 e) (.getMetricSint64 e)
(.hasMetricD e) (.getMetricD e)
(.hasMetricF e) (.getMetricF e))
(when (< 0 (.getTagsCount e)) (vec (.getTagsList e)))
(when (.hasTime e) (.getTime e))
(when (.hasTtl e) (.getTtl e))))
(if (.hasTime e) (.getTime e)
(/ (double (System/currentTimeMillis))
1000))
(when (.hasTtl e) (.getTtl e))))

(defn decode-pb-event
[^Proto$Event e]
Expand Down
20 changes: 14 additions & 6 deletions test/riemann/codec_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@
(map->Msg)))

(deftest protobufs
(let [roundtrip (fn [m] (-> m
encode-pb-msg
decode-pb-msg
(assoc :decode-time nil)))]
(let [roundtrip (fn [m] (let [m' (-> m
encode-pb-msg
decode-pb-msg
(assoc :decode-time nil))]
; Ignore automatically provided times.
(->> (:events m')
(map (fn [e e']
(if (:time e)
e'
(assoc e' :time nil)))
(:events m))
(assoc m' :events))))]
(are [m] (= (msg m) (roundtrip m))
{}
{:ok true}
Expand Down Expand Up @@ -79,6 +87,6 @@
:tags ["a" "b" "c"]
:time 12345
:ttl (float 10)}]})]
; (time (dotimes [n 10000000]
; (roundtrip m))))))
; (time (dotimes [n 10000000]
; (roundtrip m))))))
)))

0 comments on commit 11bafaa

Please sign in to comment.