Skip to content

Commit

Permalink
Merge bae9efd into ae952f5
Browse files Browse the repository at this point in the history
  • Loading branch information
macalimlim committed Jul 1, 2020
2 parents ae952f5 + bae9efd commit 3165f00
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
1 change: 0 additions & 1 deletion resources/config.test.ci.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
:statsd {:host "localhost"
:port [8125 :int]
:enabled [false :bool]}
:alpha-features {:protobuf-middleware {:enabled false}}
:sentry {:enabled [false :bool]
:dsn "dummy"
:worker-count [10 :int]
Expand Down
1 change: 0 additions & 1 deletion resources/config.test.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
:port [8125 :int]
:enabled [false :bool]}
:metrics {:constructor "ziggurat.dropwizard-metrics-wrapper/->DropwizardMetrics"}
:alpha-features {:protobuf-middleware {:enabled false}}
:sentry {:enabled [false :bool]
:dsn "dummy"
:worker-count [10 :int]
Expand Down
1 change: 0 additions & 1 deletion src/ziggurat/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
:worker-count 10
:queue-size 10
:thread-termination-wait-s 1}
:alpha-features {:protobuf-middleware {:enabled false}}
:rabbit-mq-connection {:port 5672
:username "guest"
:password "guest"
Expand Down
16 changes: 6 additions & 10 deletions src/ziggurat/middleware/default.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require [protobuf.impl.flatland.mapdef :as protodef]
[sentry-clj.async :as sentry]
[ziggurat.config :refer [get-in-config ziggurat-config]]
[flatland.protobuf.core :as proto]
[ziggurat.metrics :as metrics]
[ziggurat.sentry :refer [sentry-reporter]]))

Expand All @@ -15,15 +14,12 @@
[message proto-class topic-entity-name]
(if-not (map? message) ;; TODO: we should have proper dispatch logic per message type (not like this)
(try
(let [[proto-define-fn proto-load-fn proto-schema-fn] (if (true? (get-in-config [:alpha-features :protobuf-middleware :enabled]))
[protodef/mapdef protodef/parse protodef/mapdef->schema]
[proto/protodef proto/protobuf-load proto/protobuf-schema])
proto-klass (proto-define-fn proto-class)
loaded-proto (proto-load-fn proto-klass message)
proto-keys (-> proto-klass
proto-schema-fn
:fields
keys)]
(let [proto-klass (protodef/mapdef proto-class)
loaded-proto (protodef/parse proto-klass message)
proto-keys (-> proto-klass
protodef/mapdef->schema
:fields
keys)]
(select-keys loaded-proto proto-keys))
(catch Throwable e
(let [service-name (:app-name (ziggurat-config))
Expand Down
47 changes: 22 additions & 25 deletions test/ziggurat/middleware/default_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns ziggurat.middleware.default-test
(:require [clojure.test :refer [deftest is join-fixtures testing use-fixtures]]
[protobuf.core :as proto]
[ziggurat.config :refer [ziggurat-config]]
[ziggurat.fixtures :as fix]
[ziggurat.metrics :as metrics]
[ziggurat.middleware.default :as mw])
Expand Down Expand Up @@ -82,29 +81,27 @@

(deftest protobuf->hash-test-alpha-and-deprecated
(testing "Deprecated protobuf deserializer"
(with-redefs [ziggurat-config (fn [] {:alpha-features {:protobuf-middleware {:enabled false}}})]
(common-protobuf->hash-test)
(testing "When alpha feature is disabled use the old deserializer function"
(let [deserialize-message-called? (atom false)
topic-entity-name "test"
message {:id 7
:path "/photos/h2k3j4h9h23"}
proto-class Example$Photo
proto-message (proto/->bytes (proto/create Example$Photo message))]
(with-redefs [mw/deserialize-message (fn [_ _ _] (reset! deserialize-message-called? true))]
((mw/protobuf->hash (constantly nil) proto-class topic-entity-name) (mw/->RegularMessage proto-message))
(is (true? @deserialize-message-called?)))))))
(common-protobuf->hash-test)
(testing "When alpha feature is disabled use the old deserializer function"
(let [deserialize-message-called? (atom false)
topic-entity-name "test"
message {:id 7
:path "/photos/h2k3j4h9h23"}
proto-class Example$Photo
proto-message (proto/->bytes (proto/create Example$Photo message))]
(with-redefs [mw/deserialize-message (fn [_ _ _] (reset! deserialize-message-called? true))]
((mw/protobuf->hash (constantly nil) proto-class topic-entity-name) (mw/->RegularMessage proto-message))
(is (true? @deserialize-message-called?))))))
(testing "Alpha protobuf deserializer"
(with-redefs [ziggurat.config/ziggurat-config (fn [] {:alpha-features {:protobuf-middleware {:enabled true}}})]
(common-protobuf->hash-test)
(testing "When alpha feature is enabled use the new deserializer function"
(let [deserialize-message-called? (atom false)
topic-entity-name "test"
message {:id 7
:path "/photos/h2k3j4h9h23"}
proto-class Example$Photo
proto-message (proto/->bytes (proto/create Example$Photo message))]
(with-redefs [mw/deserialize-message (fn [_ _ _] (reset! deserialize-message-called? true))]
(common-protobuf->hash-test)
(testing "When alpha feature is enabled use the new deserializer function"
(let [deserialize-message-called? (atom false)
topic-entity-name "test"
message {:id 7
:path "/photos/h2k3j4h9h23"}
proto-class Example$Photo
proto-message (proto/->bytes (proto/create Example$Photo message))]
(with-redefs [mw/deserialize-message (fn [_ _ _] (reset! deserialize-message-called? true))]

((mw/protobuf->hash (constantly nil) proto-class topic-entity-name) (mw/->RegularMessage proto-message))
(is (true? @deserialize-message-called?))))))))
((mw/protobuf->hash (constantly nil) proto-class topic-entity-name) (mw/->RegularMessage proto-message))
(is (true? @deserialize-message-called?)))))))

0 comments on commit 3165f00

Please sign in to comment.