Created
April 16, 2014 22:24
-
-
Save jpfuentes2/10938858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(invoke! [this test op] | |
(try+ | |
(case (:f op) | |
:read (try (let [value (json/parse-string (:body (consul-get client)) true) | |
seriousValue (-> (first value) | |
:Value | |
base64/decode | |
Integer.) | |
index (-> (first value) :Index)] | |
(assoc op :type :ok :value seriousValue :index index)) | |
(catch Exception e | |
(warn e "Read failed") | |
; Since reads don't have side effects, we can always | |
; pretend they didn't happen. | |
(assoc op :type :fail))) | |
:write (do (->> (:value op) | |
json/generate-string | |
(consul-put client)) | |
(assoc op :type :ok)) | |
:cas (let [[value value'] (:value op) | |
index (:index op) | |
ok? (consul-cas client index | |
(json/generate-string value) | |
(json/generate-string value'))] | |
(assoc op :type (if ok? :ok :fail)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment