             [com.gfredericks.test.chuck :refer [times]]
             [com.gfredericks.test.chuck.clojure-test :refer [checking]]))
 
-(defn new-replica []
-    (atom {:replica {:job-scheduler :onyx.job-scheduler/balanced
-                     :messaging {:onyx.messaging/impl :dummy-messenger}}
-           :message-id 0}))
-
-
 (def messenger (dummy-messenger {:onyx.peer/try-join-once? false}))
 
 (def id (java.util.UUID/randomUUID))


(def peer-config (assoc (:peer-config config) 
                        :onyx/id id
                        :onyx.bookkeeper/write-batch-size 1
                        :onyx.bookkeeper/write-batch-timeout 10000000))

(def bookkeeper-peer-state (atom nil))

(defn add-to-bookkeeper [arg]
  (let [event (:event @bookkeeper-peer-state)
        state-log (:onyx.core/state-log event)
        ack-promise (promise)]
    (state-ext/store-log-entry state-log event (fn [] (deliver ack-promise :done)) arg)
    ;; Wait until it's acked
    @ack-promise))

(defn init-state [& args]
  [])

                                (close-peer (:event @previous-peer-state)))))
   :real/command #'new-log-after-crash})

(def add-to-log-espec
  {:model/args (fn [state]
                 [gen/int])
   :next-state (fn [state [arg] result]
                 (conj state arg))
   :real/command #'add-to-bookkeeper})

(defn close-peer-cleanup [state]
  (close-peer (:event @bookkeeper-peer-state)))
