diff --git a/dev/clj/app/db.clj b/dev/clj/app/db.clj new file mode 100644 index 0000000..dfcb6f5 --- /dev/null +++ b/dev/clj/app/db.clj @@ -0,0 +1,50 @@ +(ns app.db + (:require [mount.core :refer [defstate]] + [datomic.api :as d] + [clojure.tools.logging :refer [info]] + [app.conf :refer [config]])) + +(defn- new-connection [conf] + (info "conf: " conf) + (let [uri (get-in conf [:datomic :uri])] + (info "creating a connection to datomic:" uri) + (d/create-database uri) + (d/connect uri))) + +(defn disconnect [conf conn] + (let [uri (get-in conf [:datomic :uri])] + (info "disconnecting from " uri) + (.release conn) ;; usually it's not released, here just to illustrate the access to connection on (stop) + (d/delete-database uri))) + +(defstate conn :start (new-connection config) + :stop (disconnect config conn)) + +;; datomic schema (staging as an example) +(defn create-schema [conn] + (let [schema [{:db/id #db/id [:db.part/db] + :db/ident :order/symbol + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one + :db/index true + :db.install/_attribute :db.part/db} + + {:db/id #db/id [:db.part/db] + :db/ident :order/bid + :db/valueType :db.type/bigdec + :db/cardinality :db.cardinality/one + :db.install/_attribute :db.part/db} + + {:db/id #db/id [:db.part/db] + :db/ident :order/qty + :db/valueType :db.type/long + :db/cardinality :db.cardinality/one + :db.install/_attribute :db.part/db} + + {:db/id #db/id [:db.part/db] + :db/ident :order/offer + :db/valueType :db.type/bigdec + :db/cardinality :db.cardinality/one + :db.install/_attribute :db.part/db}]] + + @(d/transact conn schema))) diff --git a/dev/clj/app/example.clj b/dev/clj/app/example.clj index 81ffb49..ab425eb 100644 --- a/dev/clj/app/example.clj +++ b/dev/clj/app/example.clj @@ -1,10 +1,9 @@ (ns app.example - (:require [datomic.api :as d] - [clojure.tools.nrepl.server :refer [start-server stop-server]] + (:require [clojure.tools.nrepl.server :refer [start-server stop-server]] [mount.core :as mount :refer [defstate]] - [app.utils.datomic :refer [touch]] [app.conf :refer [config]] - [app.nyse :as nyse])) + [app.www]) + (:gen-class)) ;; for -main / uberjar (no need in dev) ;; example on creating a network REPL (defn- start-nrepl [{:keys [host port]}] @@ -14,52 +13,6 @@ (defstate nrepl :start (start-nrepl (:nrepl config)) :stop (stop-server nrepl)) -;; datomic schema -(defn create-schema [conn] - (let [schema [{:db/id #db/id [:db.part/db] - :db/ident :order/symbol - :db/valueType :db.type/string - :db/cardinality :db.cardinality/one - :db/index true - :db.install/_attribute :db.part/db} - - {:db/id #db/id [:db.part/db] - :db/ident :order/bid - :db/valueType :db.type/bigdec - :db/cardinality :db.cardinality/one - :db.install/_attribute :db.part/db} - - {:db/id #db/id [:db.part/db] - :db/ident :order/qty - :db/valueType :db.type/long - :db/cardinality :db.cardinality/one - :db.install/_attribute :db.part/db} - - {:db/id #db/id [:db.part/db] - :db/ident :order/offer - :db/valueType :db.type/bigdec - :db/cardinality :db.cardinality/one - :db.install/_attribute :db.part/db}]] - - @(d/transact conn schema))) - -(defn add-order [ticker bid offer qty] ;; can take connection as param - @(d/transact nyse/conn [{:db/id (d/tempid :db.part/user) - :order/symbol ticker - :order/bid bid - :order/offer offer - :order/qty qty}])) - - -(defn find-orders [ticker] ;; can take connection as param - (let [orders (d/q '[:find ?e :in $ ?ticker - :where [?e :order/symbol ?ticker]] - (d/db nyse/conn) ticker)] - (touch nyse/conn orders))) - -(defn create-nyse-schema [] - (create-schema nyse/conn)) - ;; example of an app entry point (defn -main [& args] (mount/start)) diff --git a/dev/clj/app/nyse.clj b/dev/clj/app/nyse.clj index f6a8ede..6cd1147 100644 --- a/dev/clj/app/nyse.clj +++ b/dev/clj/app/nyse.clj @@ -1,21 +1,20 @@ (ns app.nyse - (:require [mount.core :as mount :refer [defstate]] - [datomic.api :as d] - [clojure.tools.logging :refer [info]] - [app.conf :refer [config]])) + (:require [datomic.api :as d] + [app.db :refer [create-schema] :as db] + [app.utils.datomic :refer [touch]])) -(defn- new-connection [conf] - (info "conf: " conf) - (let [uri (get-in conf [:datomic :uri])] - (info "creating a connection to datomic:" uri) - (d/create-database uri) - (d/connect uri))) +(defn add-order [ticker bid offer qty] ;; can take connection as param + @(d/transact db/conn [{:db/id (d/tempid :db.part/user) + :order/symbol ticker + :order/bid bid + :order/offer offer + :order/qty qty}])) -(defn disconnect [conf conn] - (let [uri (get-in conf [:datomic :uri])] - (info "disconnecting from " uri) - (.release conn) ;; usually it's not released, here just to illustrate the access to connection on (stop) - (d/delete-database uri))) +(defn find-orders [ticker] ;; can take connection as param + (let [orders (d/q '[:find ?e :in $ ?ticker + :where [?e :order/symbol ?ticker]] + (d/db db/conn) ticker)] + (touch db/conn orders))) -(defstate conn :start (new-connection config) - :stop (disconnect config conn)) +(defn create-nyse-schema [] + (create-schema db/conn)) diff --git a/dev/clj/app/www.clj b/dev/clj/app/www.clj new file mode 100644 index 0000000..2103d4e --- /dev/null +++ b/dev/clj/app/www.clj @@ -0,0 +1,31 @@ +(ns app.www + (:require [app.nyse :refer [add-order find-orders create-nyse-schema]] + [app.conf :refer [config]] + [mount.core :refer [defstate]] + [cheshire.core :refer [generate-string]] + [compojure.core :refer [routes defroutes GET POST]] + [compojure.handler :as handler] + [ring.adapter.jetty :refer [run-jetty]])) + +(defroutes mount-example-routes + + (GET "/" [] "welcome to mount sample app!") + (GET "/nyse/orders/:ticker" [ticker] + (generate-string (find-orders ticker))) + + (POST "/nyse/orders" [ticker qty bid offer] + (add-order ticker (bigdec bid) (bigdec offer) (Integer/parseInt qty)) + (generate-string {:added {:ticker ticker + :qty qty + :bid bid + :offer offer}}))) + +(defn start-nyse [{:keys [www]}] + (create-nyse-schema) ;; creating schema (usually done long before the app is started..) + (-> (routes mount-example-routes) + (handler/site) + (run-jetty {:join? false + :port (:port www)}))) + +(defstate nyse-app :start (start-nyse config) + :stop (.stop nyse-app)) ;; it's a "org.eclipse.jetty.server.Server" at this point diff --git a/dev/dev.clj b/dev/dev.clj index d9c493e..f2facf1 100644 --- a/dev/dev.clj +++ b/dev/dev.clj @@ -12,12 +12,15 @@ [clojure.tools.namespace.repl :as tn] [mount.core :as mount] [app.utils.logging :refer [with-logging-status]] - [app.example :refer [create-nyse-schema find-orders add-order]])) ;; <<<< replace this your "app" namespace(s) you want to be available at REPL time + [app.www] + [app.example] + [app.nyse :refer [create-nyse-schema find-orders add-order]])) ;; <<<< replace this your "app" namespace(s) you want to be available at REPL time (defn start [] (with-logging-status) (mount/start #'app.conf/config - #'app.nyse/conn + #'app.db/conn + #'app.www/nyse-app #'app.example/nrepl)) ;; example on how to start app with certain states (defn stop [] diff --git a/dev/resources/config.edn b/dev/resources/config.edn index e927032..dd8d3fd 100644 --- a/dev/resources/config.edn +++ b/dev/resources/config.edn @@ -1,6 +1,8 @@ {:datomic {:uri "datomic:mem://mount"} + :www {:port 4242} + :h2 {:classname "org.h2.Driver" :subprotocol "h2" diff --git a/project.clj b/project.clj index 9d424ae..5cad57a 100644 --- a/project.clj +++ b/project.clj @@ -8,10 +8,13 @@ :dependencies [] ;; for visual clarity - :profiles {:dev {:source-paths ["dev" "dev/clj"] + :profiles {:dev {:source-paths ["dev" "dev/clj" "test/clj"] :dependencies [[org.clojure/clojure "1.7.0"] [org.clojure/clojurescript "1.7.170"]; :classifier "aot"] [datascript "0.13.3"] + [compojure "1.4.0"] + [ring/ring-jetty-adapter "1.1.0"] + [cheshire "5.5.0"] [hiccups "0.3.0"] [com.andrewmcveigh/cljs-time "0.3.14"] [ch.qos.logback/logback-classic "1.1.3"] @@ -58,4 +61,4 @@ :optimizations :advanced :pretty-print false}}}}} - :test {:source-paths ["dev" "test/clj" "test"]}}) + :test {:source-paths ["test" "test/clj" "test/cljs"]}}) diff --git a/src/mount/core.cljc b/src/mount/core.cljc index 30ba572..5027239 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -144,7 +144,7 @@ resume (assoc :resume `(fn [] ~resume)))] `(do (def ~state (DerefableState. ~state-name)) - ((var update-meta!) [~state-name] (assoc ~s-meta :inst (atom (NotStartedState. ~state-name)) + ((var mount.core/update-meta!) [~state-name] (assoc ~s-meta :inst (atom (NotStartedState. ~state-name)) :var (var ~state))) (var ~state)))))) diff --git a/test/clj/app/conf.clj b/test/clj/tapp/conf.clj similarity index 85% rename from test/clj/app/conf.clj rename to test/clj/tapp/conf.clj index 3273a95..6c821ba 100644 --- a/test/clj/app/conf.clj +++ b/test/clj/tapp/conf.clj @@ -1,8 +1,10 @@ -(ns app.conf +(ns tapp.conf (:require [mount.core :as mount :refer [defstate]] [clojure.edn :as edn] [clojure.tools.logging :refer [info]])) +(alter-meta! *ns* assoc ::load false) + (defn load-config [path] (info "loading config from" path) (-> path diff --git a/test/clj/app/example.clj b/test/clj/tapp/example.clj similarity index 92% rename from test/clj/app/example.clj rename to test/clj/tapp/example.clj index 028d406..721d2da 100644 --- a/test/clj/app/example.clj +++ b/test/clj/tapp/example.clj @@ -1,10 +1,12 @@ -(ns app.example +(ns tapp.example (:require [datomic.api :as d] [clojure.tools.nrepl.server :refer [start-server stop-server]] [mount.core :as mount :refer [defstate]] - [app.utils.datomic :refer [touch]] - [app.conf :refer [config]] - [app.nyse :as nyse])) + [tapp.utils.datomic :refer [touch]] + [tapp.conf :refer [config]] + [tapp.nyse :as nyse])) + +(alter-meta! *ns* assoc ::load false) ;; example on creating a network REPL (defn- start-nrepl [{:keys [host port]}] diff --git a/test/clj/app/nyse.clj b/test/clj/tapp/nyse.clj similarity index 88% rename from test/clj/app/nyse.clj rename to test/clj/tapp/nyse.clj index 374cba7..3a2800c 100644 --- a/test/clj/app/nyse.clj +++ b/test/clj/tapp/nyse.clj @@ -1,8 +1,10 @@ -(ns app.nyse +(ns tapp.nyse (:require [mount.core :as mount :refer [defstate]] [datomic.api :as d] [clojure.tools.logging :refer [info]] - [app.conf :refer [config]])) + [tapp.conf :refer [config]])) + +(alter-meta! *ns* assoc ::load false) (defn- new-connection [conf] (info "conf: " conf) diff --git a/test/clj/app/utils/datomic.clj b/test/clj/tapp/utils/datomic.clj similarity index 83% rename from test/clj/app/utils/datomic.clj rename to test/clj/tapp/utils/datomic.clj index 836f9b9..321f0d7 100644 --- a/test/clj/app/utils/datomic.clj +++ b/test/clj/tapp/utils/datomic.clj @@ -1,6 +1,8 @@ -(ns app.utils.datomic +(ns tapp.utils.datomic (:require [datomic.api :as d])) +(alter-meta! *ns* assoc ::load false) + (defn entity [conn id] (d/entity (d/db conn) id)) diff --git a/test/clj/app/utils/logging.clj b/test/clj/tapp/utils/logging.clj similarity index 95% rename from test/clj/app/utils/logging.clj rename to test/clj/tapp/utils/logging.clj index 2d8c64d..c888838 100644 --- a/test/clj/app/utils/logging.clj +++ b/test/clj/tapp/utils/logging.clj @@ -1,4 +1,4 @@ -(ns app.utils.logging ;; << change to your namespace/path +(ns tapp.utils.logging ;; << change to your namespace/path (:require [mount.core] [robert.hooke :refer [add-hook clear-hooks]] [clojure.string :refer [split]] diff --git a/test/cljs/tapp/audit_log.cljs b/test/cljs/tapp/audit_log.cljs new file mode 100644 index 0000000..0eac430 --- /dev/null +++ b/test/cljs/tapp/audit_log.cljs @@ -0,0 +1,25 @@ +(ns tapp.audit-log + (:require [datascript.core :as d] + [cljs-time.core :refer [now]]) + (:require-macros [mount.core :refer [defstate]])) + +(defstate log :start (d/create-conn {})) + +(defn audit [db source & msg] + (d/transact! @db [{:db/id -1 + :source source + :timestamp (now) + :msg (apply str msg)}])) + +(defn find-source-logs [db source] + (d/q '{:find [?t ?msg] + :in [$ ?s] + :where [[?e :source ?s] + [?e :timestamp ?t] + [?e :msg ?msg]]} + @@db source)) + +(defn find-all-logs [db] + (->> (map :e (d/datoms @@db :aevt :timestamp)) + dedupe + (d/pull-many @@db '[:timestamp :source :msg]))) diff --git a/test/cljs/tapp/conf.cljs b/test/cljs/tapp/conf.cljs new file mode 100644 index 0000000..8439412 --- /dev/null +++ b/test/cljs/tapp/conf.cljs @@ -0,0 +1,9 @@ +(ns tapp.conf + (:require [tapp.audit-log :refer [audit log]]) + (:require-macros [mount.core :refer [defstate]])) + +(defn load-config [path] + (audit log :app-conf "loading config from '" path "' (at least pretending)") + {:system-a {:uri "ws://echo.websocket.org/"}}) + +(defstate config :start (load-config "resources/config.end")) diff --git a/test/cljs/tapp/example.cljs b/test/cljs/tapp/example.cljs new file mode 100644 index 0000000..5f8808a --- /dev/null +++ b/test/cljs/tapp/example.cljs @@ -0,0 +1,26 @@ +(ns tapp.example + (:require [mount.core :as mount] + [tapp.conf] + [tapp.websockets] + [tapp.audit-log :refer [log find-all-logs]] + [cljs-time.format :refer [unparse formatters]] + [hiccups.runtime :as hiccupsrt]) + (:require-macros [hiccups.core :as hiccups :refer [html]])) + +(defn format-log-event [{:keys [timestamp source msg]}] + (str (unparse (formatters :date-hour-minute-second-fraction) timestamp) + " → [" (name source) "]: " msg)) + +(defn show-log [] + (.write js/document + (html [:ul (doall (for [e (find-all-logs log)] + [:li (format-log-event e)]))]))) + +(mount/start) + +;; time to establish a websocket connection before disconnecting +(js/setTimeout #(mount/stop-except "#'tapp.audit-log/log") 500) + +;; time to close a connection to show it in audit +(js/setTimeout #(show-log) 1000) + diff --git a/test/cljs/tapp/websockets.cljs b/test/cljs/tapp/websockets.cljs new file mode 100644 index 0000000..71adc07 --- /dev/null +++ b/test/cljs/tapp/websockets.cljs @@ -0,0 +1,22 @@ +(ns tapp.websockets + (:require [tapp.conf :refer [config]] + [tapp.audit-log :refer [audit log]]) + (:require-macros [mount.core :refer [defstate]])) + +(defn ws-status [ws] + {:url (.-url ws) :ready-state (.-readyState ws)}) + +(defn connect [uri] + (let [ws (js/WebSocket. uri)] + (audit log :system-a "connecting to " (ws-status ws)) + (set! (.-onopen ws) #(audit log :system-a "opened " (ws-status ws))) + (set! (.-onclose ws) #(audit log :system-a "closed " (ws-status ws))) + ws)) + +(defn disconnect [ws] + (audit log :system-a "closing " (ws-status @ws)) + (.close @ws) + (audit log :system-a "disconnecting " (ws-status @ws))) + +(defstate system-a :start (connect (get-in @config [:system-a :uri])) + :stop (disconnect system-a)) diff --git a/test/mount/test.cljc b/test/mount/test.cljc index b24368d..fa06e33 100644 --- a/test/mount/test.cljc +++ b/test/mount/test.cljc @@ -15,6 +15,8 @@ mount.test.suspend-resume )) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (mount.core/in-cljc-mode) #?(:cljs diff --git a/test/mount/test/cleanup_dirty_states.cljc b/test/mount/test/cleanup_dirty_states.cljc index c4fced9..88986bc 100644 --- a/test/mount/test/cleanup_dirty_states.cljc +++ b/test/mount/test/cleanup_dirty_states.cljc @@ -2,23 +2,25 @@ (:require #?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]] [mount.core :as mount :refer-macros [defstate]] - [app.websockets :refer [system-a]] - [app.conf :refer [config]] - [app.audit-log :refer [log]]] + [tapp.websockets :refer [system-a]] + [tapp.conf :refer [config]] + [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [app.example]]) + [tapp.example]]) [mount.test.helper :refer [dval helper forty-two]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + #?(:clj (deftest cleanup-dirty-states (let [_ (mount/start)] - (is (not (.isClosed (:server-socket (dval app.example/nrepl))))) - (require 'app.example :reload) + (is (not (.isClosed (:server-socket (dval tapp.example/nrepl))))) + (require 'tapp.example :reload) (mount/start) ;; should not result in "BindException Address already in use" since the clean up will stop the previous instance - (is (not (.isClosed (:server-socket (dval app.example/nrepl))))) + (is (not (.isClosed (:server-socket (dval tapp.example/nrepl))))) (mount/stop) - (is (instance? mount.core.NotStartedState (dval app.example/nrepl)))))) + (is (instance? mount.core.NotStartedState (dval tapp.example/nrepl)))))) #?(:cljs (deftest cleanup-dirty-states diff --git a/test/mount/test/fun_with_values.cljc b/test/mount/test/fun_with_values.cljc index 61cf200..667f216 100644 --- a/test/mount/test/fun_with_values.cljc +++ b/test/mount/test/fun_with_values.cljc @@ -5,6 +5,8 @@ :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]]]))) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (defn f [n] (fn [m] (+ n m))) diff --git a/test/mount/test/helper.cljc b/test/mount/test/helper.cljc index ecc0cff..e02bf32 100644 --- a/test/mount/test/helper.cljc +++ b/test/mount/test/helper.cljc @@ -3,6 +3,8 @@ #?@(:cljs [[mount.core :as mount :refer-macros [defstate]]] :clj [[mount.core :as mount :refer [defstate]]]))) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (defn dval "returns a value of DerefableState without deref'ing it" [d] diff --git a/test/mount/test/parts.cljc b/test/mount/test/parts.cljc index 20a503f..0a76a91 100644 --- a/test/mount/test/parts.cljc +++ b/test/mount/test/parts.cljc @@ -2,24 +2,26 @@ (:require #?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]] [mount.core :as mount :refer-macros [defstate]] - [app.websockets :refer [system-a]] - [app.conf :refer [config]] - [app.audit-log :refer [log]]] + [tapp.websockets :refer [system-a]] + [tapp.conf :refer [config]] + [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [app.nyse :refer [conn]]]) + [tapp.nyse :refer [conn]]]) [mount.test.helper :refer [dval]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (defstate should-not-start :start (constantly 42)) #?(:clj (defn with-parts [f] - (mount/start #'app.conf/config #'app.nyse/conn) + (mount/start #'tapp.conf/config #'tapp.nyse/conn) (f) (mount/stop))) (use-fixtures :once - #?(:cljs {:before #(mount/start #'app.conf/config #'app.audit-log/log) + #?(:cljs {:before #(mount/start #'tapp.conf/config #'tapp.audit-log/log) :after mount/stop} :clj with-parts)) diff --git a/test/mount/test/private_fun.cljc b/test/mount/test/private_fun.cljc index 47ef9a4..e487e54 100644 --- a/test/mount/test/private_fun.cljc +++ b/test/mount/test/private_fun.cljc @@ -7,6 +7,8 @@ [mount.test.fun-with-values :refer [private-f]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (use-fixtures :once #?(:cljs {:before #(mount/start #'mount.test.fun-with-values/private-f) :after mount/stop} diff --git a/test/mount/test/start_with.cljc b/test/mount/test/start_with.cljc index 7e7a7bd..d8ef8b8 100644 --- a/test/mount/test/start_with.cljc +++ b/test/mount/test/start_with.cljc @@ -2,16 +2,18 @@ (:require #?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]] [mount.core :as mount :refer-macros [defstate]] - [app.websockets :refer [system-a]] - [app.conf :refer [config]] - [app.audit-log :refer [log]]] + [tapp.websockets :refer [system-a]] + [tapp.conf :refer [config]] + [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [app.conf :refer [config]] - [app.nyse :refer [conn]] - [app.example :refer [nrepl]]]) + [tapp.conf :refer [config]] + [tapp.nyse :refer [conn]] + [tapp.example :refer [nrepl]]]) [mount.test.helper :refer [dval helper]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (defstate test-conn :start 42 :stop (constantly 0)) @@ -21,7 +23,7 @@ (deftest start-with (testing "should start with substitutes" - (let [_ (mount/start-with {#'app.websockets/system-a #'mount.test.start-with/test-conn + (let [_ (mount/start-with {#'tapp.websockets/system-a #'mount.test.start-with/test-conn #'mount.test.helper/helper #'mount.test.start-with/test-nrepl})] (is (map? (dval config))) (is (vector? (dval helper))) @@ -30,7 +32,7 @@ (mount/stop))) (testing "should not start the substitute itself" - (let [_ (mount/start-with {#'app.websockets/system-a #'mount.test.start-with/test-conn})] + (let [_ (mount/start-with {#'tapp.websockets/system-a #'mount.test.start-with/test-conn})] (is (instance? mount.core.NotStartedState (dval test-conn))) (is (= 42 (dval system-a))) (mount/stop))) @@ -60,15 +62,15 @@ (deftest start-with (testing "should start with substitutes" - (let [_ (mount/start-with {#'app.nyse/conn #'mount.test.start-with/test-conn - #'app.example/nrepl #'mount.test.start-with/test-nrepl})] + (let [_ (mount/start-with {#'tapp.nyse/conn #'mount.test.start-with/test-conn + #'tapp.example/nrepl #'mount.test.start-with/test-nrepl})] (is (map? (dval config))) (is (vector? (dval nrepl))) (is (= (dval conn) 42)) (mount/stop))) (testing "should not start the substitute itself" - (let [_ (mount/start-with {#'app.nyse/conn #'mount.test.start-with/test-conn})] + (let [_ (mount/start-with {#'tapp.nyse/conn #'mount.test.start-with/test-conn})] (is (instance? mount.core.NotStartedState (dval test-conn))) (is (= (dval conn) 42)) (mount/stop))) diff --git a/test/mount/test/start_without.cljc b/test/mount/test/start_without.cljc index f6a68d1..a678e16 100644 --- a/test/mount/test/start_without.cljc +++ b/test/mount/test/start_without.cljc @@ -2,24 +2,26 @@ (:require #?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]] [mount.core :as mount :refer-macros [defstate]] - [app.websockets :refer [system-a]] - [app.conf :refer [config]] - [app.audit-log :refer [log]]] + [tapp.websockets :refer [system-a]] + [tapp.conf :refer [config]] + [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [app.conf :refer [config]] - [app.nyse :refer [conn]] - [app.example :refer [nrepl]]]) + [tapp.conf :refer [config]] + [tapp.nyse :refer [conn]] + [tapp.example :refer [nrepl]]]) [mount.test.helper :refer [dval helper]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + #?(:clj (defn without [f] - (mount/start-without #'app.nyse/conn #'app.example/nrepl) + (mount/start-without #'tapp.nyse/conn #'tapp.example/nrepl) (f) (mount/stop))) (use-fixtures :once - #?(:cljs {:before #(mount/start-without #'mount.test.helper/helper #'app.websockets/system-a) + #?(:cljs {:before #(mount/start-without #'mount.test.helper/helper #'tapp.websockets/system-a) :after mount/stop} :clj without)) diff --git a/test/mount/test/stop_except.cljc b/test/mount/test/stop_except.cljc index 3e61f97..26fc54c 100644 --- a/test/mount/test/stop_except.cljc +++ b/test/mount/test/stop_except.cljc @@ -2,22 +2,24 @@ (:require #?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]] [mount.core :as mount :refer-macros [defstate]] - [app.websockets :refer [system-a]] - [app.conf :refer [config]] - [app.audit-log :refer [log]]] + [tapp.websockets :refer [system-a]] + [tapp.conf :refer [config]] + [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [app.conf :refer [config]] - [app.nyse :refer [conn]] - [app.example :refer [nrepl]]]) + [tapp.conf :refer [config]] + [tapp.nyse :refer [conn]] + [tapp.example :refer [nrepl]]]) [mount.test.helper :refer [dval helper]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + #?(:cljs (deftest stop-except (testing "should stop all except nrepl" (let [_ (mount/start) - _ (mount/stop-except #'app.audit-log/log #'mount.test.helper/helper)] + _ (mount/stop-except #'tapp.audit-log/log #'mount.test.helper/helper)] (is (= :started (dval helper))) (is (instance? datascript.db/DB @(dval log))) (is (instance? mount.core.NotStartedState (dval config))) @@ -33,7 +35,7 @@ (testing "should stop all normally after stop-except" (let [_ (mount/start) - _ (mount/stop-except #'app.audit-log/log #'mount.test.helper/helper) + _ (mount/stop-except #'tapp.audit-log/log #'mount.test.helper/helper) _ (mount/stop)] (is (instance? mount.core.NotStartedState (dval config))) (is (instance? mount.core.NotStartedState (dval log))) @@ -44,7 +46,7 @@ (testing "should stop all except nrepl" (let [_ (mount/start) - _ (mount/stop-except #'app.nyse/conn #'app.conf/config)] + _ (mount/stop-except #'tapp.nyse/conn #'tapp.conf/config)] (is (map? (dval config))) (is (instance? datomic.peer.LocalConnection (dval conn))) (is (instance? mount.core.NotStartedState (dval nrepl))) @@ -59,7 +61,7 @@ (testing "should stop all normally after stop-except" (let [_ (mount/start) - _ (mount/stop-except #'app.nyse/conn #'app.conf/config) + _ (mount/stop-except #'tapp.nyse/conn #'tapp.conf/config) _ (mount/stop)] (is (instance? mount.core.NotStartedState (dval config))) (is (instance? mount.core.NotStartedState (dval conn))) diff --git a/test/mount/test/suspend_resume.cljc b/test/mount/test/suspend_resume.cljc index ea1fe36..c3503ec 100644 --- a/test/mount/test/suspend_resume.cljc +++ b/test/mount/test/suspend_resume.cljc @@ -2,16 +2,18 @@ (:require #?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]] [mount.core :as mount :refer-macros [defstate]] - [app.websockets :refer [system-a]] - [app.conf :refer [config]] - [app.audit-log :refer [log]]] + [tapp.websockets :refer [system-a]] + [tapp.conf :refer [config]] + [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [app.conf :refer [config]] - [app.nyse :refer [conn]] - [app.example :refer [nrepl]]]) + [tapp.conf :refer [config]] + [tapp.nyse :refer [conn]] + [tapp.example :refer [nrepl]]]) [mount.test.helper :refer [dval]])) +#?(:clj (alter-meta! *ns* assoc ::load false)) + (defn koncat [k s] (-> (name k) (str "-" (name s)) @@ -48,7 +50,7 @@ (testing "should resume _only suspendable_ states that are currently suspended" (let [_ (mount/start) - _ (mount/stop #'app.websockets/system-a) + _ (mount/stop #'tapp.websockets/system-a) _ (mount/suspend) _ (mount/resume)] (is (map? (dval config))) @@ -82,7 +84,7 @@ (testing "when replacing a non suspendable state with a suspendable one, the later should be able to suspend/resume, the original should not be suspendable after resume and preserve its lifecycle fns after rollback/stop" - (let [_ (mount/start-with {#'app.websockets/system-a #'mount.test.suspend-resume/web-server}) + (let [_ (mount/start-with {#'tapp.websockets/system-a #'mount.test.suspend-resume/web-server}) _ (mount/suspend)] (is (= (dval system-a) :w-suspended)) (is (instance? mount.core.NotStartedState (dval web-server))) @@ -107,7 +109,7 @@ (testing "should resume _only suspendable_ states that are currently suspended" (let [_ (mount/start) - _ (mount/stop #'app.example/nrepl) + _ (mount/stop #'tapp.example/nrepl) _ (mount/suspend) _ (mount/resume)] (is (map? (dval config))) @@ -142,7 +144,7 @@ (testing "when replacing a non suspendable state with a suspendable one, the later should be able to suspend/resume, the original should not be suspendable after resume and preserve its lifecycle fns after rollback/stop" - (let [_ (mount/start-with {#'app.example/nrepl #'mount.test.suspend-resume/web-server}) + (let [_ (mount/start-with {#'tapp.example/nrepl #'mount.test.suspend-resume/web-server}) _ (mount/suspend)] (is (= (dval nrepl) :w-suspended)) (is (instance? mount.core.NotStartedState (dval web-server))) @@ -176,7 +178,7 @@ the original should still be suspended and preserve its lifecycle fns after the rollback/stop" (let [_ (mount/start) _ (mount/suspend) - _ (mount/start-with {#'mount.test.suspend-resume/web-server #'app.nyse/conn}) ;; TODO: good to WARN on started states during "start-with" + _ (mount/start-with {#'mount.test.suspend-resume/web-server #'tapp.nyse/conn}) ;; TODO: good to WARN on started states during "start-with" _ (mount/suspend)] (is (instance? datomic.peer.LocalConnection (dval conn))) (is (= (dval web-server) :w-suspended)) ;; since the "conn" does not have a resume method, so web-server was not started diff --git a/test/mount/test/var/fun_with_values.clj b/test/mount/test/var/fun_with_values.clj index f6a09a1..155f318 100644 --- a/test/mount/test/var/fun_with_values.clj +++ b/test/mount/test/var/fun_with_values.clj @@ -2,6 +2,8 @@ (:require [clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]])) +(alter-meta! *ns* assoc ::load false) + (defn f [n] (fn [m] (+ n m))) diff --git a/test/mount/test/var/private_fun.clj b/test/mount/test/var/private_fun.clj index f00a37d..6c91456 100644 --- a/test/mount/test/var/private_fun.clj +++ b/test/mount/test/var/private_fun.clj @@ -3,6 +3,8 @@ [mount.core :as mount :refer [defstate]] [mount.test.var.fun-with-values :refer [private-f]])) +(alter-meta! *ns* assoc ::load false) + (defn in-clj-mode [f] (mount/in-clj-mode) (require :reload 'mount.test.var.fun-with-values 'mount.test.var.private-fun)