You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by knusbaum <gi...@git.apache.org> on 2015/11/03 21:29:03 UTC

[GitHub] storm pull request: [STORM-885] Heartbeat Server (Pacemaker)

Github user knusbaum commented on a diff in the pull request:

    https://github.com/apache/storm/pull/838#discussion_r43802385
  
    --- Diff: storm-core/test/clj/org/apache/storm/pacemaker_test.clj ---
    @@ -0,0 +1,227 @@
    +(ns org.apache.storm.pacemaker-test
    +  (:require [clojure.test :refer :all]
    +            [org.apache.storm.pacemaker [pacemaker :as pacemaker]]
    +            [conjure.core :as conjure])
    +  (:import [backtype.storm.generated
    +            HBExecutionException HBNodes HBRecords
    +            HBServerMessageType HBMessage HBMessageData HBPulse]))
    +
    +(defn- message-with-rand-id [type data]
    +  (let [mid (rand-int 1000)
    +        message (HBMessage. type data)]
    +    (.set_message_id message mid)
    +    [message mid]))
    +
    +(defn- string-to-bytes [string]
    +  (byte-array (map int string)))
    +
    +(defn- bytes-to-string [bytez]
    +  (apply str (map char bytez)))
    +
    +(defn- makenode [handler path]
    +  (.handleMessage handler
    +                  (HBMessage.
    +                   HBServerMessageType/SEND_PULSE
    +                   (HBMessageData/pulse
    +                    (doto (HBPulse.)
    +                      (.set_id path)
    +                      (.set_details (string-to-bytes "nothing")))))
    +                  true))
    +
    +(deftest pacemaker-server-create-path
    +  (conjure/stubbing
    +   [pacemaker/register nil]
    +   (let [handler (pacemaker/mk-handler {})]
    +     (testing "CREATE_PATH"
    +       (let [[message mid] (message-with-rand-id
    +                            HBServerMessageType/CREATE_PATH
    +                            (HBMessageData/path "/testpath"))
    +             response (.handleMessage handler message true)]
    +         (is (= (.get_message_id response) mid))
    +         (is (= (.get_type response) HBServerMessageType/CREATE_PATH_RESPONSE))
    +         (is (= (.get_data response) nil)))))))
    +
    +(deftest pacemaker-server-exists
    +  (conjure/stubbing
    +   [pacemaker/register nil]
    +   (let [handler (pacemaker/mk-handler {})]
    +     (testing "EXISTS - false"
    +       (let [[message mid] (message-with-rand-id HBServerMessageType/EXISTS
    +                                                 (HBMessageData/path "/testpath"))
    +             bad-response (.handleMessage handler message false)
    +             good-response (.handleMessage handler message true)]
    +         (is (= (.get_message_id bad-response) mid))
    +         (is (= (.get_type bad-response) HBServerMessageType/NOT_AUTHORIZED))
    +
    +         (is (= (.get_message_id good-response) mid))
    +         (is (= (.get_type good-response) HBServerMessageType/EXISTS_RESPONSE))
    +         (is (= (.get_boolval (.get_data good-response)) false))))
    +
    +     (testing "EXISTS - true"
    +       (let [path "/exists_path"
    +             data-string "pulse data"]
    +         (let [[send _] (message-with-rand-id
    +                         HBServerMessageType/SEND_PULSE
    +                         (HBMessageData/pulse
    +                          (doto (HBPulse.)
    +                            (.set_id path)
    +                            (.set_details (string-to-bytes data-string)))))
    +               _ (.handleMessage handler send true)
    +               [message mid] (message-with-rand-id HBServerMessageType/EXISTS
    +                                                   (HBMessageData/path path))
    +               bad-response (.handleMessage handler message false)
    +               good-response (.handleMessage handler message true)]
    +           (is (= (.get_message_id bad-response) mid))
    +          (is (= (.get_type bad-response) HBServerMessageType/NOT_AUTHORIZED))
    +
    +          (is (= (.get_message_id good-response) mid))
    +          (is (= (.get_type good-response) HBServerMessageType/EXISTS_RESPONSE))
    +          (is (= (.get_boolval (.get_data good-response)) true))))))))
    --- End diff --
    
    Spacing for a bunch of these `is` forms is off.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---