Skip to content

Commit

Permalink
Nippy thaw to return a message map instead of defrecord
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol Vijaywargiya committed Aug 13, 2021
1 parent 863e5cd commit 6dfcb14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/ziggurat/messaging/consumer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
(defn- nippy-deserialize
[frozen]
(try
(nippy/thaw frozen)
(let [thaw (nippy/thaw frozen)]
(into {} thaw)) ;Converting defrecord into map, since proto does not understand defrecord
(catch Exception e
(log/error e "Failed to deserialize nippy message"))))

Expand Down
16 changes: 8 additions & 8 deletions test/ziggurat/messaging/consumer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,16 @@
converted-message-payload (consumer/convert-and-ack-message nil {:delivery-tag 1} proto-serialized-message-payload false "default")]
(is (= "class [B" (str (type (:message converted-message-payload)))))
(is (= (bytes-to-str converted-message-payload) (bytes-to-str message-payload)))))
(testing "should return a ziggurat.message_payload/->MessagePayload if serialized using nippy"
(let [expected-message-payload (assoc (zmp/->MessagePayload proto-message topic-entity) :retry-count 4)
nippy-serialized-message-payload (nippy/freeze expected-message-payload)
(testing "should return a map and not ziggurat.message_payload/->MessagePayload if original message was a ziggurat.message_payload/->MessagePayload and serialized using nippy"
(let [nippy-message-payload (assoc (zmp/->MessagePayload proto-message topic-entity) :retry-count 3)
nippy-serialized-message-payload (nippy/freeze nippy-message-payload)
converted-message-payload (consumer/convert-and-ack-message nil {:delivery-tag 1} nippy-serialized-message-payload false "default")]
(is (= (bytes-to-str converted-message-payload) (bytes-to-str expected-message-payload)))))
(testing "should return a ziggurat.mapper/->MessagePayload if serialized using nippy"
(let [expected-message-payload (assoc (mpr/->MessagePayload proto-message topic-entity) :retry-count 4)
nippy-serialized-message-payload (nippy/freeze expected-message-payload)
(is (= (bytes-to-str converted-message-payload) (bytes-to-str message-payload)))))
(testing "should return a map and not ziggurat.mapper/->MessagePayload if original message was a ziggurat.mapper/->MessagePayload and serialized using nippy"
(let [nippy-message-payload (assoc (mpr/->MessagePayload proto-message topic-entity) :retry-count 3)
nippy-serialized-message-payload (nippy/freeze nippy-message-payload)
converted-message-payload (consumer/convert-and-ack-message nil {:delivery-tag 1} nippy-serialized-message-payload false "default")]
(is (= (bytes-to-str converted-message-payload) (bytes-to-str expected-message-payload)))))
(is (= (bytes-to-str converted-message-payload) (bytes-to-str message-payload)))))
(testing "should return a clojure map if serialized using nippy"
(let [random-bytes-as-message-payload (.getBytes (String. "Hello World"))
converted-message-payload (consumer/convert-and-ack-message nil {:delivery-tag 1} random-bytes-as-message-payload false "default")]
Expand Down

0 comments on commit 6dfcb14

Please sign in to comment.