Skip to content

Commit

Permalink
#5 timer related events encoding/decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ojow committed May 30, 2018
1 parent ff1bee3 commit 80b1acc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
7 changes: 5 additions & 2 deletions re/resources/re/config.dev.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
:count 1
:handler #ig/ref :re.handler/decoder}
:re.handler/decoder {:classes ["events.SdkEvent$SDKEvent"
"events.SystemEventOuterClass$TimerExpired"]
"events.SystemEventOuterClass$TimerExpired"
"events.SystemEventOuterClass$Timer"]
:next #ig/ref :re/crm}
:re/crm {:oam #ig/ref :re/oam
:entities #ig/ref :re.boundary/entities
Expand All @@ -29,7 +30,9 @@
:topic "dev"}

:re/kafka-producer {:configs {"bootstrap.servers" ["kafka:9092"]}}
:re/encoder {:classes ["events.SdkEvent$SDKEvent"]}
:re/encoder {:classes ["events.SdkEvent$SDKEvent"
"events.SystemEventOuterClass$TimerExpired"
"events.SystemEventOuterClass$Timer"]}

:re/db {:contact-points ["scylladb"]
:keyspace "re_dev"}
Expand Down
32 changes: 30 additions & 2 deletions re/test/re/handler/decoder_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[integrant.core :as ig]
[re.test-utils :refer [with-system]]
[proto-edn.core :as proto])
(:import events.SdkEvent$SDKEvent))
(:import events.SdkEvent$SDKEvent
events.SystemEventOuterClass$TimerExpired
events.SystemEventOuterClass$Timer))

(defmethod ig/init-key ::db [_ _]
(promise))
Expand All @@ -13,7 +15,9 @@
(deliver db message)))

(def config
{:re.handler/decoder {:classes ["events.SdkEvent$SDKEvent"]
{:re.handler/decoder {:classes ["events.SdkEvent$SDKEvent"
"events.SystemEventOuterClass$TimerExpired"
"events.SystemEventOuterClass$Timer"]
:next (ig/ref ::next)}
::next {:db (ig/ref ::db)}
::db {}})
Expand All @@ -27,3 +31,27 @@
(.toByteArray))]
((:re.handler/decoder system) {:value bytes})
(is (= @(::db system) {:value event})))))

(deftest timer-expired
(with-system [system config]
(let [event {"header" {"type" "events.TimerExpired" "createdAt" 0 "source" "test"}
"correlationId" "0"
"universe" "0"}
bytes (-> event
(proto/merge-and-build (SystemEventOuterClass$TimerExpired/newBuilder))
(.toByteArray))]
((:re.handler/decoder system) {:value bytes})
(is (= @(::db system) {:value event})))))

(deftest timer
(with-system [system config]
(let [event {"header" {"type" "events.Timer" "createdAt" 0 "source" "test"}
"correlationId" "0"
"expireAt" 0}
bytes (-> event
(proto/merge-and-build (SystemEventOuterClass$Timer/newBuilder))
(.toByteArray))]
((:re.handler/decoder system) {:value bytes})
(is (= @(::db system) {:value event})))))


0 comments on commit 80b1acc

Please sign in to comment.