From d77bc4729db9a0bf8184ce215f1e144e881ff48c Mon Sep 17 00:00:00 2001 From: Michael Angelo Calimlim Date: Wed, 1 Jul 2020 14:32:49 +0800 Subject: [PATCH] removed old protobuf library in favor of the new one --- resources/config.test.ci.edn | 1 - resources/config.test.edn | 2 +- src/ziggurat/config.clj | 1 - src/ziggurat/middleware/default.clj | 16 ++++----- test/ziggurat/middleware/default_test.clj | 42 ++++++----------------- 5 files changed, 18 insertions(+), 44 deletions(-) diff --git a/resources/config.test.ci.edn b/resources/config.test.ci.edn index 0f56ab5a..900f913c 100644 --- a/resources/config.test.ci.edn +++ b/resources/config.test.ci.edn @@ -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] diff --git a/resources/config.test.edn b/resources/config.test.edn index b2be5b5d..47b41852 100644 --- a/resources/config.test.edn +++ b/resources/config.test.edn @@ -8,7 +8,7 @@ :port [8125 :int] :enabled [false :bool]} :metrics {:constructor "ziggurat.dropwizard-metrics-wrapper/->DropwizardMetrics"} - :alpha-features {:protobuf-middleware {:enabled false}} + :alpha-features {} :sentry {:enabled [false :bool] :dsn "dummy" :worker-count [10 :int] diff --git a/src/ziggurat/config.clj b/src/ziggurat/config.clj index 8fb4e97d..3fc47db2 100644 --- a/src/ziggurat/config.clj +++ b/src/ziggurat/config.clj @@ -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" diff --git a/src/ziggurat/middleware/default.clj b/src/ziggurat/middleware/default.clj index 387de713..1e527320 100644 --- a/src/ziggurat/middleware/default.clj +++ b/src/ziggurat/middleware/default.clj @@ -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]])) @@ -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)) diff --git a/test/ziggurat/middleware/default_test.clj b/test/ziggurat/middleware/default_test.clj index 74fe1dd2..1b4ad385 100644 --- a/test/ziggurat/middleware/default_test.clj +++ b/test/ziggurat/middleware/default_test.clj @@ -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]) @@ -78,33 +77,14 @@ (reset! metric-reporter-called? true))] ((mw/protobuf->hash handler-fn nil topic-entity-name) (mw/->RegularMessage nil))) (is (true? @handler-fn-called?)) - (is (true? @metric-reporter-called?))))) - -(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?))))))) - (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))] - - ((mw/protobuf->hash (constantly nil) proto-class topic-entity-name) (mw/->RegularMessage proto-message)) - (is (true? @deserialize-message-called?)))))))) + (is (true? @metric-reporter-called?)))) + (testing "using 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?))))))