From 65e134547114799d6d29110af561fb62ce06a008 Mon Sep 17 00:00:00 2001 From: Justin Stoller Date: Mon, 4 Apr 2016 15:38:47 -0700 Subject: [PATCH 1/3] bump pl-clojure-style to 4141164 --- ext/pl-clojure-style | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pl-clojure-style b/ext/pl-clojure-style index dbfe1e73..41411645 160000 --- a/ext/pl-clojure-style +++ b/ext/pl-clojure-style @@ -1 +1 @@ -Subproject commit dbfe1e731c142090a13a59a255272e9408585c0b +Subproject commit 414116454e4f1e74114727bd8a84547822f89991 From f45a178ce1bb268e97cacb47ad2ffef58f545461 Mon Sep 17 00:00:00 2001 From: Justin Stoller Date: Mon, 4 Apr 2016 15:41:13 -0700 Subject: [PATCH 2/3] Apply cljfmt recommendations --- .../clj/java_service_example/java_service.clj | 28 +- .../shutdown_app/test_external_shutdown.clj | 8 +- src/puppetlabs/trapperkeeper/bootstrap.clj | 30 +- src/puppetlabs/trapperkeeper/config.clj | 40 +- src/puppetlabs/trapperkeeper/core.clj | 26 +- src/puppetlabs/trapperkeeper/internal.clj | 34 +- src/puppetlabs/trapperkeeper/plugins.clj | 12 +- src/puppetlabs/trapperkeeper/services.clj | 4 +- .../services/nrepl/nrepl_service.clj | 18 +- .../trapperkeeper/services_internal.clj | 110 ++--- .../trapperkeeper/bootstrap_test.clj | 238 +++++----- test/puppetlabs/trapperkeeper/config_test.clj | 70 +-- test/puppetlabs/trapperkeeper/core_test.clj | 38 +- .../examples/bootstrapping/test_services.clj | 42 +- .../trapperkeeper/internal_test.clj | 54 +-- .../puppetlabs/trapperkeeper/logging_test.clj | 24 +- .../trapperkeeper/optional_deps_test.clj | 92 ++-- .../puppetlabs/trapperkeeper/plugins_test.clj | 18 +- .../trapperkeeper/services_internal_test.clj | 108 ++--- .../services_namespaces_test/ns2.clj | 20 +- .../trapperkeeper/services_test.clj | 72 +-- .../trapperkeeper/shutdown_test.clj | 442 +++++++++--------- .../trapperkeeper/testutils/bootstrap.clj | 6 +- .../trapperkeeper/testutils/logging.clj | 26 +- 24 files changed, 780 insertions(+), 780 deletions(-) diff --git a/examples/java_service/src/clj/java_service_example/java_service.clj b/examples/java_service/src/clj/java_service_example/java_service.clj index 3327beaf..0d7eb589 100644 --- a/examples/java_service/src/clj/java_service_example/java_service.clj +++ b/examples/java_service/src/clj/java_service_example/java_service.clj @@ -8,20 +8,20 @@ (meaning-of-life-fn [this])) (defservice java-service - JavaService - [] + JavaService + [] ;; Service functions are implemented in a java `ServiceImpl` class - (msg-fn [this] (ServiceImpl/getMessage)) - (meaning-of-life-fn [this] (ServiceImpl/getMeaningOfLife))) + (msg-fn [this] (ServiceImpl/getMessage)) + (meaning-of-life-fn [this] (ServiceImpl/getMeaningOfLife))) (defservice java-service-consumer - [[:JavaService msg-fn meaning-of-life-fn] - [:ShutdownService request-shutdown]] - (init [this context] - (log/info "Java service consumer!") - (log/infof "The message from Java is: '%s'" (msg-fn)) - (log/infof "The meaning of life is: '%s'" (meaning-of-life-fn)) - context) - (start [this context] - (request-shutdown) - context)) + [[:JavaService msg-fn meaning-of-life-fn] + [:ShutdownService request-shutdown]] + (init [this context] + (log/info "Java service consumer!") + (log/infof "The message from Java is: '%s'" (msg-fn)) + (log/infof "The meaning of life is: '%s'" (meaning-of-life-fn)) + context) + (start [this context] + (request-shutdown) + context)) diff --git a/examples/shutdown_app/src/examples/shutdown_app/test_external_shutdown.clj b/examples/shutdown_app/src/examples/shutdown_app/test_external_shutdown.clj index be8e0d00..a977b824 100644 --- a/examples/shutdown_app/src/examples/shutdown_app/test_external_shutdown.clj +++ b/examples/shutdown_app/src/examples/shutdown_app/test_external_shutdown.clj @@ -5,13 +5,13 @@ (trapperkeeper/defservice test-service [] (stop [this context] - (println "If you see this printed out then shutdown works correctly!") - context)) + (println "If you see this printed out then shutdown works correctly!") + context)) (defn -main [& args] (println "Waiting for a shutdown signal - use Ctrl-C or kill.") (println "You should see a message printed out when services are being shutdown.") (trapperkeeper/run - {:config testutils/empty-config - :bootstrap-config "examples/shutdown_app/bootstrap.cfg"})) + {:config testutils/empty-config + :bootstrap-config "examples/shutdown_app/bootstrap.cfg"})) diff --git a/src/puppetlabs/trapperkeeper/bootstrap.clj b/src/puppetlabs/trapperkeeper/bootstrap.clj index 4ee80284..9b8573c6 100644 --- a/src/puppetlabs/trapperkeeper/bootstrap.clj +++ b/src/puppetlabs/trapperkeeper/bootstrap.clj @@ -24,13 +24,13 @@ an IllegalArgumentException if the line is not valid." [line :- schema/Str] (if-let [[match namespace service-name] (re-matches - #"^([a-zA-Z0-9\.\-]+)/([a-zA-Z0-9\.\-]+)$" - line)] + #"^([a-zA-Z0-9\.\-]+)/([a-zA-Z0-9\.\-]+)$" + line)] {:namespace namespace :service-name service-name} (throw (IllegalArgumentException. - (str "Invalid line in bootstrap config file:\n\n\t" - line - "\n\nAll lines must be of the form: '/'."))))) + (str "Invalid line in bootstrap config file:\n\n\t" + line + "\n\nAll lines must be of the form: '/'."))))) (schema/defn ^:private resolve-service! :- (schema/protocol services/ServiceDefinition) "Given the namespace and name of a service, loads the namespace, @@ -42,12 +42,12 @@ (try (require (symbol resolve-ns)) (catch FileNotFoundException e (throw (IllegalArgumentException. - (str "Unable to load service: " resolve-ns "/" service-name) - e)))) + (str "Unable to load service: " resolve-ns "/" service-name) + e)))) (if-let [service-def (ns-resolve (symbol resolve-ns) (symbol service-name))] (internal/validate-service-graph! (var-get service-def)) (throw (IllegalArgumentException. - (str "Unable to load service: " resolve-ns "/" service-name))))) + (str "Unable to load service: " resolve-ns "/" service-name))))) (schema/defn ^:private remove-comments :- schema/Str "Given a line of text from the bootstrap config file, remove @@ -77,8 +77,8 @@ ;; (in the case of a normal path, it is useless - there is no ;; reason to mess with URIs) (throw (IllegalArgumentException. - (str "Specified bootstrap config file does not exist: '" - config-path "'"))))))) + (str "Specified bootstrap config file does not exist: '" + config-path "'"))))))) (schema/defn ^:private config-from-cli :- (schema/maybe BootstrapFiles) "Given the data from the command-line (parsed via `core/parse-cli-args!`), @@ -91,10 +91,10 @@ (when (contains? cli-data :bootstrap-config) (when-let [config-path (cli-data :bootstrap-config)] (let [config-files (flatten (map - find-bootstraps-from-path - (string/split config-path #",")))] + find-bootstraps-from-path + (string/split config-path #",")))] (log/debug (format "Loading bootstrap configs:\n%s" - (string/join "\n" config-files))) + (string/join "\n" config-files))) config-files)))) (schema/defn ^:private config-from-cwd :- (schema/maybe BootstrapFiles) @@ -129,8 +129,8 @@ (config-from-classpath))] bootstrap-configs (throw (IllegalStateException. - (str "Unable to find bootstrap.cfg file via --bootstrap-config " - "command line argument, current working directory, or on classpath"))))) + (str "Unable to find bootstrap.cfg file via --bootstrap-config " + "command line argument, current working directory, or on classpath"))))) (schema/defn chain-files :- [schema/Str] "Takes a list of files, reads all their lines in, and returns a flattened seq diff --git a/src/puppetlabs/trapperkeeper/config.clj b/src/puppetlabs/trapperkeeper/config.clj index 3737cbe1..896b4009 100644 --- a/src/puppetlabs/trapperkeeper/config.clj +++ b/src/puppetlabs/trapperkeeper/config.clj @@ -36,7 +36,7 @@ (defprotocol ConfigService (get-config [this] "Returns a map containing all of the configuration values") (get-in-config [this ks] [this ks default] - "Returns the individual configuration value from the nested + "Returns the individual configuration value from the nested configuration structure, where ks is a sequence of keys. Returns nil if the key is not present, or the default value if supplied.")) @@ -68,13 +68,13 @@ [path] (when-not (.canRead (io/file path)) (throw (FileNotFoundException. - (format "Configuration path '%s' must exist and must be readable." - path)))) + (format "Configuration path '%s' must exist and must be readable." + path)))) (if-not (fs/directory? path) [path] (mapcat - #(fs/glob (fs/file path %)) - ["*.ini" "*.conf" "*.json" "*.properties" "*.edn" "*.yaml" "*.yml"]))) + #(fs/glob (fs/file path %)) + ["*.ini" "*.conf" "*.json" "*.properties" "*.edn" "*.yaml" "*.yml"]))) (defn load-config "Given a path to a configuration file or directory of configuration files, @@ -89,7 +89,7 @@ (apply ks/deep-merge-with-keys (fn [ks & _] (throw (IllegalArgumentException. - (str "Duplicate configuration entry: " ks))))) + (str "Duplicate configuration entry: " ks))))) (merge {})))) (defn config-service @@ -98,18 +98,18 @@ parameter should be the path to an .ini file or a directory of .ini files." [config-data-fn] (service ConfigService - [] - (init [this context] - (assoc context :config (config-data-fn))) - (get-config [this] - (let [{:keys [config]} (service-context this)] - config)) - (get-in-config [this ks] - (let [{:keys [config]} (service-context this)] - (get-in config ks))) - (get-in-config [this ks default] - (let [{:keys [config]} (service-context this)] - (get-in config ks default))))) + [] + (init [this context] + (assoc context :config (config-data-fn))) + (get-config [this] + (let [{:keys [config]} (service-context this)] + config)) + (get-in-config [this ks] + (let [{:keys [config]} (service-context this)] + (get-in config ks))) + (get-in-config [this ks default] + (let [{:keys [config]} (service-context this)] + (get-in config ks default))))) (schema/defn parse-config-data :- (schema/pred map?) "Parses the .ini, .edn, .conf, .json, or .properties configuration file(s) @@ -121,8 +121,8 @@ (if-not (contains? cli-data :config) {:debug debug?} (-> (:config cli-data) - (load-config) - (assoc :debug debug?))))) + (load-config) + (assoc :debug debug?))))) (defn initialize-logging! "Initializes the logging system based on the configuration data." diff --git a/src/puppetlabs/trapperkeeper/core.clj b/src/puppetlabs/trapperkeeper/core.clj index 8da0ed1f..2a421e6f 100644 --- a/src/puppetlabs/trapperkeeper/core.clj +++ b/src/puppetlabs/trapperkeeper/core.clj @@ -15,13 +15,13 @@ :doc "An alias for the `puppetlabs.trapperkeeper.services/service` macro so that it is accessible from the core namespace along with the rest of the API."} - service #'services/service) + service #'services/service) (def #^{:macro true :doc "An alias for the `puppetlabs.trapperkeeper.services/defservice` macro so that it is accessible from the core namespace along with the rest of the API."} - defservice #'services/defservice) + defservice #'services/defservice) (defn build-app "Given a list of services and a map of configuration data, build an instance @@ -168,14 +168,14 @@ (binding [*out* stream] (println msg) (flush)) (System/exit status))] (try+ - (-> (or args '()) - (internal/parse-cli-args!) - (run)) - (catch map? m - (case (without-ns (:type m)) - :cli-error (quit 1 (:message m) *err*) - :cli-help (quit 0 (:message m) *out*) - (throw+))) - (finally - (log/debug "Finished TK main lifecycle, shutting down Clojure agent threads.") - (shutdown-agents))))) + (-> (or args '()) + (internal/parse-cli-args!) + (run)) + (catch map? m + (case (without-ns (:type m)) + :cli-error (quit 1 (:message m) *err*) + :cli-help (quit 0 (:message m) *out*) + (throw+))) + (finally + (log/debug "Finished TK main lifecycle, shutting down Clojure agent threads.") + (shutdown-agents))))) diff --git a/src/puppetlabs/trapperkeeper/internal.clj b/src/puppetlabs/trapperkeeper/internal.clj index 4c689bba..480594ba 100644 --- a/src/puppetlabs/trapperkeeper/internal.clj +++ b/src/puppetlabs/trapperkeeper/internal.clj @@ -38,9 +38,9 @@ service graph." [service-graph] (and - (map? service-graph) - (every? keyword? (keys service-graph)) - (every? (some-fn ifn? service-graph?) (vals service-graph)))) + (map? service-graph) + (every? keyword? (keys service-graph)) + (every? (some-fn ifn? service-graph?) (vals service-graph)))) (defn validate-service-graph! "Validates that a ServiceDefinition contains a valid trapperkeeper service graph. @@ -50,9 +50,9 @@ {:post [(satisfies? s/ServiceDefinition %)]} (if-not (satisfies? s/ServiceDefinition service-def) (throw (IllegalArgumentException. - (str "Invalid service definition; expected a service " - "definition (created via `service` or `defservice`); " - "found: " (pr-str service-def))))) + (str "Invalid service definition; expected a service " + "definition (created via `service` or `defservice`); " + "found: " (pr-str service-def))))) (if (service-graph? (s/service-map service-def)) service-def (throw (IllegalArgumentException. (str "Invalid service graph; service graphs must " @@ -103,13 +103,13 @@ (if (sequential? (:error data)) (let [missing-services (keys (ks/filter-map - (fn [_ v] (= v 'missing-required-key)) - (.error (first (:error data)))))] + (fn [_ v] (= v 'missing-required-key)) + (.error (first (:error data)))))] (if (= 1 (count missing-services)) (throw (RuntimeException. - (format "Service '%s' not found" (first missing-services)))) + (format "Service '%s' not found" (first missing-services)))) (throw (RuntimeException. - (format "Services '%s' not found" missing-services))))) + (format "Services '%s' not found" missing-services))))) (throw e))))) (defn compile-graph @@ -174,11 +174,11 @@ updated-ctxt (lifecycle-fn s (get-in @app-context [:service-contexts service-id] {}))] (if-not (map? updated-ctxt) (throw (IllegalStateException. - (format - "Lifecycle function '%s' for service '%s' must return a context map (got: %s)" - lifecycle-fn-name - (or (s/service-symbol s) service-id) - (pr-str updated-ctxt))))) + (format + "Lifecycle function '%s' for service '%s' must return a context map (got: %s)" + lifecycle-fn-name + (or (s/service-symbol s) service-id) + (pr-str updated-ctxt))))) ;; store the updated service context map in the application context atom (swap! app-context assoc-in [:service-contexts service-id] updated-ctxt))) @@ -397,7 +397,7 @@ (s/service ShutdownService [] (get-shutdown-reason [this] (when (realized? shutdown-reason-promise) - @shutdown-reason-promise)) + @shutdown-reason-promise)) (wait-for-shutdown [this] (deref shutdown-reason-promise)) (request-shutdown [this] (request-shutdown* shutdown-reason-promise)) (shutdown-on-error [this svc-id f] (shutdown-on-error* shutdown-reason-promise app-context svc-id f)) @@ -553,7 +553,7 @@ (a/service-graph [this] graph-instance) (a/app-context [this] app-context) (a/check-for-errors! [this] (throw-app-error-if-exists! - this)) + this)) (a/init [this] (run-lifecycle-fns app-context s/init "init" ordered-services) this) diff --git a/src/puppetlabs/trapperkeeper/plugins.clj b/src/puppetlabs/trapperkeeper/plugins.clj index ce11e572..6163cc62 100644 --- a/src/puppetlabs/trapperkeeper/plugins.clj +++ b/src/puppetlabs/trapperkeeper/plugins.clj @@ -11,14 +11,14 @@ [name] (and ;; ignore directories - (not (or (.isDirectory (file name)) - (.endsWith name "/"))) ; necessary for directories in .jars + (not (or (.isDirectory (file name)) + (.endsWith name "/"))) ; necessary for directories in .jars ;; don't care about anything in META-INF - (not (.startsWith name "META-INF")) + (not (.startsWith name "META-INF")) ;; lein includes project.clj ... no thank you - (not (= name "project.clj")))) + (not (= name "project.clj")))) (defn- handle-duplicate! "Helper for `process-file`; handles a found duplicate. Throws an exception @@ -60,7 +60,7 @@ (map #(.getName %) (enumeration-seq (.entries (JarFile. file)))))] (reduce (partial process-file container-filename) acc filenames)) acc ; There may be directories on the classpath that do not exist. - ))) +))) (defn jars-in-dir "Given a path to a directory on disk, returns a collection of all of the .jar @@ -100,4 +100,4 @@ (log/info "Adding plugin .jar " (.getAbsolutePath jar) " to classpath.") (kitchensink/add-classpath jar))) (throw (IllegalArgumentException. - (str "Plugins directory " plugins-path " does not exist"))))))) + (str "Plugins directory " plugins-path " does not exist"))))))) diff --git a/src/puppetlabs/trapperkeeper/services.clj b/src/puppetlabs/trapperkeeper/services.clj index 8fee2cab..85daef98 100644 --- a/src/puppetlabs/trapperkeeper/services.clj +++ b/src/puppetlabs/trapperkeeper/services.clj @@ -55,8 +55,8 @@ (let [{:keys [service-sym service-protocol-sym service-id service-fn-map dependencies fns-map]} (si/parse-service-forms! - lifecycle-fn-names - forms) + lifecycle-fn-names + forms) output-schema (si/build-output-schema (keys service-fn-map))] `(reify ServiceDefinition (service-def-id [this] ~service-id) diff --git a/src/puppetlabs/trapperkeeper/services/nrepl/nrepl_service.clj b/src/puppetlabs/trapperkeeper/services/nrepl/nrepl_service.clj index 45a54048..8b6c78d7 100644 --- a/src/puppetlabs/trapperkeeper/services/nrepl/nrepl_service.clj +++ b/src/puppetlabs/trapperkeeper/services/nrepl/nrepl_service.clj @@ -1,9 +1,9 @@ (ns puppetlabs.trapperkeeper.services.nrepl.nrepl-service (:require - [clojure.tools.logging :as log] - [clojure.tools.nrepl.server :as nrepl] - [puppetlabs.kitchensink.core :refer [to-bool]] - [puppetlabs.trapperkeeper.core :refer [defservice]])) + [clojure.tools.logging :as log] + [clojure.tools.nrepl.server :as nrepl] + [puppetlabs.kitchensink.core :refer [to-bool]] + [puppetlabs.trapperkeeper.core :refer [defservice]])) ;; If no port is specified in the config then 7888 is used @@ -36,7 +36,7 @@ (let [{:keys [enabled? port bind handler]} (process-config get-in-config)] (if enabled? (do (log/info "Starting nREPL service on" bind "port" port) - (nrepl/start-server :port port :bind bind :handler handler)) + (nrepl/start-server :port port :bind bind :handler handler)) (log/info "nREPL service disabled, not starting")))) (defn- shutdown-nrepl @@ -58,11 +58,11 @@ If no port is specified then the default port of 7888 is used." [[:ConfigService get-in-config]] (init [this context] - (let [nrepl-server (startup-nrepl get-in-config)] - (assoc context :nrepl-server nrepl-server))) + (let [nrepl-server (startup-nrepl get-in-config)] + (assoc context :nrepl-server nrepl-server))) (stop [this context] - (shutdown-nrepl (context :nrepl-server)) - context)) + (shutdown-nrepl (context :nrepl-server)) + context)) diff --git a/src/puppetlabs/trapperkeeper/services_internal.clj b/src/puppetlabs/trapperkeeper/services_internal.clj index a0528181..37cf6df1 100644 --- a/src/puppetlabs/trapperkeeper/services_internal.clj +++ b/src/puppetlabs/trapperkeeper/services_internal.clj @@ -99,9 +99,9 @@ (if (every? seq? fns) {:fns fns} (throw (IllegalArgumentException. - (format - "Invalid service definition; expected function definitions following dependency list, invalid value: '%s'" - (pr-str (first (filter #(not (seq? %)) fns)))))))) + (format + "Invalid service definition; expected function definitions following dependency list, invalid value: '%s'" + (pr-str (first (filter #(not (seq? %)) fns)))))))) ;; TODO Not converting to use schema since this fn's behavior should literally ;; be a schema @@ -142,9 +142,9 @@ (map? f) (merge {:service-protocol-sym nil} (validate-deps-form! forms)) (vector? f) (merge {:service-protocol-sym nil} (validate-deps-form! forms)) :else (throw (IllegalArgumentException. - (format - "Invalid service definition; first form must be protocol or dependency list; found '%s'" - (pr-str f))))))) + (format + "Invalid service definition; first form must be protocol or dependency list; found '%s'" + (pr-str f))))))) (schema/defn ^:always-validate validate-protocol-sym! :- Protocol "Given a var, validate that the var exists and that its value is a protocol. @@ -154,12 +154,12 @@ var :- (schema/maybe Var)] (if-not var (throw (IllegalArgumentException. - (format "Unrecognized service protocol '%s'" sym)))) + (format "Unrecognized service protocol '%s'" sym)))) (let [protocol (var-get var)] (if-not (protocol? protocol) (throw (IllegalArgumentException. - (format "Specified service protocol '%s' does not appear to be a protocol!" - sym)))) + (format "Specified service protocol '%s' does not appear to be a protocol!" + sym)))) protocol)) (schema/defn ^:always-validate validate-protocol-fn-names! :- nil @@ -172,9 +172,9 @@ (set (map name lifecycle-fn-names)))] (if-not (empty? collisions) (throw (IllegalArgumentException. - (format "Service protocol '%s' includes function named '%s', which conflicts with lifecycle function by same name" - (name service-protocol-sym) - (first collisions))))))) + (format "Service protocol '%s' includes function named '%s', which conflicts with lifecycle function by same name" + (name service-protocol-sym) + (first collisions))))))) (schema/defn ^:always-validate validate-provided-fns! :- nil "Validate that the seq of fns specified in a service body does not include @@ -186,15 +186,15 @@ (if (and (nil? service-protocol-sym) (> (count provided-fns) 0)) (throw (IllegalArgumentException. - (format - "Service attempts to define function '%s', but does not provide protocol" - (name (first provided-fns)))))) + (format + "Service attempts to define function '%s', but does not provide protocol" + (name (first provided-fns)))))) (let [extras (difference provided-fns service-fns)] (when-not (empty? extras) (throw (IllegalArgumentException. - (format - "Service attempts to define function '%s', which does not exist in protocol '%s'" - (name (first extras)) (name service-protocol-sym))))))) + (format + "Service attempts to define function '%s', which does not exist in protocol '%s'" + (name (first extras)) (name service-protocol-sym))))))) (schema/defn ^:always-validate validate-required-fns! :- nil "Given a map of fn forms and a list of required function names, @@ -207,8 +207,8 @@ (let [fn-name (ks/without-ns (keyword fn-name))] (if-not (contains? fns-map fn-name) (throw (IllegalArgumentException. - (format "Service does not define function '%s', which is required by protocol '%s'" - (name fn-name) (name protocol-sym)))))))) + (format "Service does not define function '%s', which is required by protocol '%s'" + (name fn-name) (name protocol-sym)))))))) (schema/defn ^:always-validate add-default-lifecycle-fn :- FnsMap "Given a map of fns defined by a service, and the name of a lifecycle function, @@ -220,7 +220,7 @@ (if (contains? fns-map (keyword fn-name)) fns-map (assoc fns-map (keyword fn-name) - (list (cons fn-name '([this context] context)))))) + (list (cons fn-name '([this context] context)))))) (schema/defn ^:always-validate add-default-lifecycle-fns :- FnsMap "Given a map of fns comprising a service body, add in a default implementation @@ -239,11 +239,11 @@ [fns-map :- FnsMap fn-names :- [Symbol]] (reduce - (fn [acc fn-name] - (let [sigs (fns-map (ks/without-ns (keyword fn-name)))] - (concat acc sigs))) - '() - fn-names)) + (fn [acc fn-name] + (let [sigs (fns-map (ks/without-ns (keyword fn-name)))] + (concat acc sigs))) + '() + fn-names)) (schema/defn ^:always-validate build-service-map :- ServiceMap "Given a map from service protocol function names (keywords) to service @@ -282,31 +282,31 @@ (validate-protocol-fn-names! service-protocol-sym service-fn-names lifecycle-fn-names)) (let [fns-map (->> (reduce - (fn [acc f] + (fn [acc f] ; second element should be a vector - params to the fn - (when-not (vector? (second f)) + (when-not (vector? (second f)) ; macro was used incorrectly - perhaps the user ; mistakenly tried to insert a docstring, like: ; `(service-fn "docs about service-fn..." [this] ... )` - (throw - (Exception. - (str - "Incorrect macro usage: service functions must " - "be defined the same as a call to `reify`, eg: " - "`(my-service-fn [this other-args] ...)`")))) - (let [k (keyword (first f)) - cur (acc k)] - (if cur - (assoc acc k (cons f cur)) - (assoc acc k (list f))))) - {} - fns) - (add-default-lifecycle-fns lifecycle-fn-names))] + (throw + (Exception. + (str + "Incorrect macro usage: service functions must " + "be defined the same as a call to `reify`, eg: " + "`(my-service-fn [this other-args] ...)`")))) + (let [k (keyword (first f)) + cur (acc k)] + (if cur + (assoc acc k (cons f cur)) + (assoc acc k (list f))))) + {} + fns) + (add-default-lifecycle-fns lifecycle-fn-names))] (validate-provided-fns! - service-protocol-sym - (set (map (comp ks/without-ns keyword) service-fn-names)) - (difference (ks/keyset fns-map) - (set (map (comp ks/without-ns keyword) lifecycle-fn-names)))) + service-protocol-sym + (set (map (comp ks/without-ns keyword) service-fn-names)) + (difference (ks/keyset fns-map) + (set (map (comp ks/without-ns keyword) lifecycle-fn-names)))) (when service-protocol-sym (validate-required-fns! service-protocol-sym service-fn-names fns-map)) fns-map)) @@ -317,9 +317,9 @@ otherwise." [service-protocol-sym :- (schema/maybe Symbol)] (ks/without-ns - (if service-protocol-sym - (keyword service-protocol-sym) - (keyword (gensym "tk-service"))))) + (if service-protocol-sym + (keyword service-protocol-sym) + (keyword (gensym "tk-service"))))) (schema/defn ^:always-validate get-service-fn-map :- ServiceFnMap "Get a map of service fns based on a protocol. Keys will be keywords of the @@ -329,8 +329,8 @@ (if service-protocol-sym (let [service-protocol-var (resolve service-protocol-sym) service-protocol (validate-protocol-sym! - service-protocol-sym - service-protocol-var)] + service-protocol-sym + service-protocol-var)] (reduce (fn [acc fn-name] (assoc acc (keyword (name fn-name)) fn-name)) {} @@ -356,10 +356,10 @@ service-fn-map (get-service-fn-map service-protocol-sym) fns-map (build-fns-map! - service-protocol-sym - (vals service-fn-map) - lifecycle-fn-names - fns)] + service-protocol-sym + (vals service-fn-map) + lifecycle-fn-names + fns)] {:service-sym service-sym :service-protocol-sym service-protocol-sym diff --git a/test/puppetlabs/trapperkeeper/bootstrap_test.clj b/test/puppetlabs/trapperkeeper/bootstrap_test.clj index 1d297adc..0d03cf70 100644 --- a/test/puppetlabs/trapperkeeper/bootstrap_test.clj +++ b/test/puppetlabs/trapperkeeper/bootstrap_test.clj @@ -36,116 +36,116 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/hello-world-servic (is (= (test-fn test-svc) :foo)) (is (= (hello-world hello-world-svc) "hello world")))) - (with-additional-classpath-entries ["./dev-resources/bootstrapping/classpath"] - (testing "Looks for bootstrap config on classpath (dev-resources)" - (with-test-logging - (let [app (bootstrap-with-empty-config) - test-svc (get-service app :TestService) - hello-world-svc (get-service app :HelloWorldService)] - (is (logged? - #"Loading bootstrap config from classpath: 'file:/.*dev-resources/bootstrapping/classpath/bootstrap.cfg'" - :debug)) - (is (= (test-fn test-svc) :classpath)) - (is (= (hello-world hello-world-svc) "hello world"))))) + (with-additional-classpath-entries ["./dev-resources/bootstrapping/classpath"] + (testing "Looks for bootstrap config on classpath (dev-resources)" + (with-test-logging + (let [app (bootstrap-with-empty-config) + test-svc (get-service app :TestService) + hello-world-svc (get-service app :HelloWorldService)] + (is (logged? + #"Loading bootstrap config from classpath: 'file:/.*dev-resources/bootstrapping/classpath/bootstrap.cfg'" + :debug)) + (is (= (test-fn test-svc) :classpath)) + (is (= (hello-world hello-world-svc) "hello world"))))) - (testing "Gives precedence to bootstrap config in cwd" - (let [old-cwd (System/getProperty "user.dir")] - (try - (System/setProperty - "user.dir" - (.getAbsolutePath (file "./dev-resources/bootstrapping/cwd"))) - (with-test-logging - (let [app (bootstrap-with-empty-config) - test-svc (get-service app :TestService) - hello-world-svc (get-service app :HelloWorldService)] - (is (logged? - #"Loading bootstrap config from current working directory: '.*/dev-resources/bootstrapping/cwd/bootstrap.cfg'" - :debug)) - (is (= (test-fn test-svc) :cwd)) - (is (= (hello-world hello-world-svc) "hello world")))) - (finally (System/setProperty "user.dir" old-cwd))))) + (testing "Gives precedence to bootstrap config in cwd" + (let [old-cwd (System/getProperty "user.dir")] + (try + (System/setProperty + "user.dir" + (.getAbsolutePath (file "./dev-resources/bootstrapping/cwd"))) + (with-test-logging + (let [app (bootstrap-with-empty-config) + test-svc (get-service app :TestService) + hello-world-svc (get-service app :HelloWorldService)] + (is (logged? + #"Loading bootstrap config from current working directory: '.*/dev-resources/bootstrapping/cwd/bootstrap.cfg'" + :debug)) + (is (= (test-fn test-svc) :cwd)) + (is (= (hello-world hello-world-svc) "hello world")))) + (finally (System/setProperty "user.dir" old-cwd))))) - (testing "Gives precedence to bootstrap config specified as CLI arg" - (with-test-logging - (let [bootstrap-path "./dev-resources/bootstrapping/cli/bootstrap.cfg" - app (bootstrap-with-empty-config ["--bootstrap-config" bootstrap-path]) - test-svc (get-service app :TestService) - hello-world-svc (get-service app :HelloWorldService)] - (is (logged? - (format "Loading bootstrap configs:\n%s" (fs/absolute bootstrap-path)) - :debug)) - (is (= (test-fn test-svc) :cli)) - (is (= (hello-world hello-world-svc) "hello world"))))))) + (testing "Gives precedence to bootstrap config specified as CLI arg" + (with-test-logging + (let [bootstrap-path "./dev-resources/bootstrapping/cli/bootstrap.cfg" + app (bootstrap-with-empty-config ["--bootstrap-config" bootstrap-path]) + test-svc (get-service app :TestService) + hello-world-svc (get-service app :HelloWorldService)] + (is (logged? + (format "Loading bootstrap configs:\n%s" (fs/absolute bootstrap-path)) + :debug)) + (is (= (test-fn test-svc) :cli)) + (is (= (hello-world hello-world-svc) "hello world"))))))) - (testing "Invalid bootstrap configurations" - (testing "Bootstrap config path specified on CLI does not exist" - (let [cfg-path "./dev-resources/bootstrapping/cli/non-existent-bootstrap.cfg"] - (is (thrown-with-msg? - IllegalArgumentException - #"Specified bootstrap config file does not exist: '.*non-existent-bootstrap.cfg'" - (bootstrap-with-empty-config ["--bootstrap-config" cfg-path]))))) + (testing "Invalid bootstrap configurations" + (testing "Bootstrap config path specified on CLI does not exist" + (let [cfg-path "./dev-resources/bootstrapping/cli/non-existent-bootstrap.cfg"] + (is (thrown-with-msg? + IllegalArgumentException + #"Specified bootstrap config file does not exist: '.*non-existent-bootstrap.cfg'" + (bootstrap-with-empty-config ["--bootstrap-config" cfg-path]))))) - (testing "No bootstrap config found" - (is (thrown-with-msg? - IllegalStateException - #"Unable to find bootstrap.cfg file via --bootstrap-config command line argument, current working directory, or on classpath" - (bootstrap-with-empty-config))) - (let [got-expected-exception (atom false)] - (try+ - (bootstrap-with-empty-config ["--bootstrap-config" nil]) - (catch map? m - (is (contains? m :type)) - (is (= :cli-error (without-ns (:type m)))) - (is (= :puppetlabs.kitchensink.core/cli-error (:type m))) - (is (contains? m :message)) - (is (re-find - #"Missing required argument for.*--bootstrap-config" - (m :message))) - (reset! got-expected-exception true))) - (is (true? @got-expected-exception)))) + (testing "No bootstrap config found" + (is (thrown-with-msg? + IllegalStateException + #"Unable to find bootstrap.cfg file via --bootstrap-config command line argument, current working directory, or on classpath" + (bootstrap-with-empty-config))) + (let [got-expected-exception (atom false)] + (try+ + (bootstrap-with-empty-config ["--bootstrap-config" nil]) + (catch map? m + (is (contains? m :type)) + (is (= :cli-error (without-ns (:type m)))) + (is (= :puppetlabs.kitchensink.core/cli-error (:type m))) + (is (contains? m :message)) + (is (re-find + #"Missing required argument for.*--bootstrap-config" + (m :message))) + (reset! got-expected-exception true))) + (is (true? @got-expected-exception)))) - (testing "Bad line in bootstrap config file" - (let [bootstrap-config (StringReader. " + (testing "Bad line in bootstrap config file" + (let [bootstrap-config (StringReader. " puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service This is not a legit line. ")] - (is (thrown-with-msg? - IllegalArgumentException - #"(?is)Invalid line in bootstrap.*This is not a legit line" - (parse-and-bootstrap bootstrap-config))))) + (is (thrown-with-msg? + IllegalArgumentException + #"(?is)Invalid line in bootstrap.*This is not a legit line" + (parse-and-bootstrap bootstrap-config))))) - (testing "Bootstrap config file is empty." - (let [bootstrap-config (StringReader. "")] - (is (thrown-with-msg? - Exception - #"Empty bootstrap config file" - (parse-and-bootstrap bootstrap-config))))) + (testing "Bootstrap config file is empty." + (let [bootstrap-config (StringReader. "")] + (is (thrown-with-msg? + Exception + #"Empty bootstrap config file" + (parse-and-bootstrap bootstrap-config))))) - (testing "Service namespace doesn't exist" - (let [bootstrap-config (StringReader. - "non-existent-service/test-service")] - (is (thrown-with-msg? - IllegalArgumentException - #"Unable to load service: non-existent-service/test-service" - (parse-and-bootstrap bootstrap-config))))) + (testing "Service namespace doesn't exist" + (let [bootstrap-config (StringReader. + "non-existent-service/test-service")] + (is (thrown-with-msg? + IllegalArgumentException + #"Unable to load service: non-existent-service/test-service" + (parse-and-bootstrap bootstrap-config))))) - (testing "Service function doesn't exist" - (let [bootstrap-config (StringReader. - "puppetlabs.trapperkeeper.examples.bootstrapping.test-services/non-existent-service")] - (is (thrown-with-msg? - IllegalArgumentException - #"Unable to load service: puppetlabs.trapperkeeper.examples.bootstrapping.test-services/non-existent-service" - (parse-and-bootstrap bootstrap-config))))) + (testing "Service function doesn't exist" + (let [bootstrap-config (StringReader. + "puppetlabs.trapperkeeper.examples.bootstrapping.test-services/non-existent-service")] + (is (thrown-with-msg? + IllegalArgumentException + #"Unable to load service: puppetlabs.trapperkeeper.examples.bootstrapping.test-services/non-existent-service" + (parse-and-bootstrap bootstrap-config))))) - (testing "Invalid service graph" + (testing "Invalid service graph" - (let [bootstrap-config (StringReader. - "puppetlabs.trapperkeeper.examples.bootstrapping.test-services/invalid-service-graph-service")] - (is (thrown-with-msg? - IllegalArgumentException - #"Invalid service definition;" - (parse-and-bootstrap bootstrap-config))))))) + (let [bootstrap-config (StringReader. + "puppetlabs.trapperkeeper.examples.bootstrapping.test-services/invalid-service-graph-service")] + (is (thrown-with-msg? + IllegalArgumentException + #"Invalid service definition;" + (parse-and-bootstrap bootstrap-config))))))) (testing "comments allowed in bootstrap config file" (let [bootstrap-config " @@ -174,10 +174,10 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; test-svc-three (get-service app :TestServiceThree) hello-world-svc (get-service app :HelloWorldService)] (is (logged? - (format "Loading bootstrap configs:\n%s\n%s" - (fs/absolute bootstrap-one) - (fs/absolute bootstrap-two)) - :debug)) + (format "Loading bootstrap configs:\n%s\n%s" + (fs/absolute bootstrap-one) + (fs/absolute bootstrap-two)) + :debug)) (is (= (test-fn test-svc) :cli)) (is (= (test-fn-two test-svc-two) :two)) (is (= (test-fn-three test-svc-three) :three)) @@ -193,9 +193,9 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; (is (logged? ; We can't know what order it will find the files on disk, so just ; look for a partial match with the path we gave TK. - (re-pattern (format "Loading bootstrap configs:\n%s" - (fs/absolute bootstrap-path))) - :debug)) + (re-pattern (format "Loading bootstrap configs:\n%s" + (fs/absolute bootstrap-path))) + :debug)) (is (= (test-fn test-svc) :cli)) (is (= (test-fn-two test-svc-two) :two)) (is (= (test-fn-three test-svc-three) :three)) @@ -212,10 +212,10 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; test-svc-three (get-service app :TestServiceThree) hello-world-svc (get-service app :HelloWorldService)] (is (logged? - (format "Loading bootstrap configs:\n%s\n%s" - (fs/absolute bootstrap-one) - (fs/absolute bootstrap-two)) - :debug)) + (format "Loading bootstrap configs:\n%s\n%s" + (fs/absolute bootstrap-one) + (fs/absolute bootstrap-two)) + :debug)) (is (= (test-fn test-svc) :cli)) (is (= (test-fn-two test-svc-two) :two)) (is (= (test-fn-three test-svc-three) :three)) @@ -226,12 +226,12 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; (with-test-logging (let [bootstrap-path "./dev-resources/bootstrapping/cli/path with spaces/bootstrap.cfg" app (bootstrap-with-empty-config - ["--bootstrap-config" bootstrap-path]) + ["--bootstrap-config" bootstrap-path]) test-svc (get-service app :TestService) hello-world-svc (get-service app :HelloWorldService)] (is (logged? - (format "Loading bootstrap configs:\n%s" (fs/absolute bootstrap-path)) - :debug)) + (format "Loading bootstrap configs:\n%s" (fs/absolute bootstrap-path)) + :debug)) (is (= (test-fn test-svc) :cli)) (is (= (hello-world hello-world-svc) "hello world"))))) (testing "Multiple bootstrap files can be specified with spaces in the names" @@ -245,10 +245,10 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; test-svc-three (get-service app :TestServiceThree) hello-world-svc (get-service app :HelloWorldService)] (is (logged? - (format "Loading bootstrap configs:\n%s\n%s" - (fs/absolute bootstrap-one) - (fs/absolute bootstrap-two)) - :debug)) + (format "Loading bootstrap configs:\n%s\n%s" + (fs/absolute bootstrap-one) + (fs/absolute bootstrap-two)) + :debug)) (is (= (test-fn test-svc) :cli)) (is (= (test-fn-two test-svc-two) :two)) (is (= (test-fn-three test-svc-three) :three)) @@ -258,7 +258,7 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; (testing "duplicate bootstrap entries are allowed" (let [bootstrap-path "./dev-resources/bootstrapping/cli/duplicate_entries.cfg" app (bootstrap-with-empty-config - ["--bootstrap-config" bootstrap-path]) + ["--bootstrap-config" bootstrap-path]) hello-world-svc (get-service app :HelloWorldService)] (is (= (hello-world hello-world-svc) "hello world"))))) @@ -275,12 +275,12 @@ puppetlabs.trapperkeeper.examples.bootstrapping.test-services/foo-test-service ; (let [bootstrap-one (StringReader. "one\ntwo") bootstrap-two (StringReader. "three\nfour")] (is (= - ["one", "two", "three", "four"] - (chain-files [bootstrap-one bootstrap-two]))))) + ["one", "two", "three", "four"] + (chain-files [bootstrap-one bootstrap-two]))))) (testing "chain-files removes empty files" (let [bootstrap-one (StringReader. "one\ntwo") bootstrap-two (StringReader. "") bootstrap-three (StringReader. "three\nfour")] (is (= - ["one", "two", "three", "four"] - (chain-files [bootstrap-one bootstrap-two bootstrap-three])))))) + ["one", "two", "three", "four"] + (chain-files [bootstrap-one bootstrap-two bootstrap-three])))))) diff --git a/test/puppetlabs/trapperkeeper/config_test.clj b/test/puppetlabs/trapperkeeper/config_test.clj index 4ab15a45..35ceadd3 100644 --- a/test/puppetlabs/trapperkeeper/config_test.clj +++ b/test/puppetlabs/trapperkeeper/config_test.clj @@ -15,32 +15,32 @@ (get-in-config [this ks] [this ks default])) (defservice test-service - ConfigTestService - [[:ConfigService get-in-config get-config]] - (test-fn [this ks] (get-in-config ks)) - (test-fn2 [this] (get-config)) - (get-in-config [this ks] (get-in-config ks)) - (get-in-config [this ks default] (get-in-config ks default))) + ConfigTestService + [[:ConfigService get-in-config get-config]] + (test-fn [this ks] (get-in-config ks)) + (test-fn2 [this] (get-config)) + (get-in-config [this ks] (get-in-config ks)) + (get-in-config [this ks default] (get-in-config ks default))) (deftest test-config-service (testing "Fails if config path doesn't exist" (is (thrown-with-msg? - FileNotFoundException - #"Configuration path './foo/bar/baz' must exist and must be readable." - (bootstrap-services-with-cli-data [test-service] {:config "./foo/bar/baz"})))) + FileNotFoundException + #"Configuration path './foo/bar/baz' must exist and must be readable." + (bootstrap-services-with-cli-data [test-service] {:config "./foo/bar/baz"})))) (testing "Can read values from a single .ini file" (with-app-with-cli-data app [test-service] {:config "./dev-resources/config/file/config.ini"} (let [test-svc (get-service app :ConfigTestService)] - (is (= (test-fn test-svc [:foo :setting1]) "foo1")) - (is (= (test-fn test-svc [:foo :setting2]) "foo2")) - (is (= (test-fn test-svc [:bar :setting1]) "bar1")) + (is (= (test-fn test-svc [:foo :setting1]) "foo1")) + (is (= (test-fn test-svc [:foo :setting2]) "foo2")) + (is (= (test-fn test-svc [:bar :setting1]) "bar1")) - (testing "`get-config` function" - (is (= (test-fn2 test-svc) {:foo {:setting2 "foo2", - :setting1 "foo1"}, - :bar {:setting1 "bar1"} - :debug false} )))))) + (testing "`get-config` function" + (is (= (test-fn2 test-svc) {:foo {:setting2 "foo2" + :setting1 "foo1"} + :bar {:setting1 "bar1"} + :debug false})))))) (testing "Can read values from a single .edn file" (with-app-with-cli-data app [test-service] {:config "./dev-resources/config/file/config.edn"} @@ -71,26 +71,26 @@ {:config (str "./dev-resources/config/mixeddir/baz.ini," "./dev-resources/config/mixeddir/bar.conf")} (let [test-svc (get-service app :ConfigTestService)] - (is (= {:debug false, :baz {:setting1 "baz1", :setting2 "baz2"} - :bar {:junk "thingz" - :nesty {:mappy {:hi "there":stuff [1 2 {:how "areyou"} 3]}}}} - (test-fn2 test-svc)))))) + (is (= {:debug false, :baz {:setting1 "baz1", :setting2 "baz2"} + :bar {:junk "thingz" + :nesty {:mappy {:hi "there" :stuff [1 2 {:how "areyou"} 3]}}}} + (test-fn2 test-svc)))))) (testing "Conflicting comma-separated configs fail with error" (is (thrown-with-msg? - IllegalArgumentException - #"Duplicate configuration entry: \[:foo :baz\]" - (bootstrap-services-with-cli-data [test-service] - {:config (str "./dev-resources/config/conflictdir1/config.ini," - "./dev-resources/config/conflictdir1/config.conf")})))) + IllegalArgumentException + #"Duplicate configuration entry: \[:foo :baz\]" + (bootstrap-services-with-cli-data [test-service] + {:config (str "./dev-resources/config/conflictdir1/config.ini," + "./dev-resources/config/conflictdir1/config.conf")})))) (testing "Error results when second of two comma-separated configs is malformed" (is (thrown-with-msg? - FileNotFoundException - #"Configuration path 'blob.conf' must exist and must be readable." - (bootstrap-services-with-cli-data [test-service] - {:config (str "./dev-resources/config/conflictdir1/config.ini," - "blob.conf")})))) + FileNotFoundException + #"Configuration path 'blob.conf' must exist and must be readable." + (bootstrap-services-with-cli-data [test-service] + {:config (str "./dev-resources/config/conflictdir1/config.ini," + "blob.conf")})))) ;; NOTE: other individual file formats are tested in `typesafe-test` @@ -119,7 +119,7 @@ :baz {:setting1 "baz1" :setting2 "baz2"} :bar {:nesty {:mappy {:hi "there" - :stuff [1 2 {:how "areyou"} 3]}} + :stuff [1 2 {:how "areyou"} 3]}} :junk "thingz"} :qux {:first {:list [1 2]} :second {:key "value"}}} @@ -130,9 +130,9 @@ "./dev-resources/config/conflictdir2" "./dev-resources/config/conflictdir3"]] (is (thrown-with-msg? - IllegalArgumentException - #"Duplicate configuration entry: \[:foo :baz\]" - (bootstrap-services-with-cli-data [test-service] {:config invalid-config-dir}))))) + IllegalArgumentException + #"Duplicate configuration entry: \[:foo :baz\]" + (bootstrap-services-with-cli-data [test-service] {:config invalid-config-dir}))))) (testing "Can call load-config directly" (is (= {:taco {:burrito [1, 2] diff --git a/test/puppetlabs/trapperkeeper/core_test.clj b/test/puppetlabs/trapperkeeper/core_test.clj index 7161b415..86ded751 100644 --- a/test/puppetlabs/trapperkeeper/core_test.clj +++ b/test/puppetlabs/trapperkeeper/core_test.clj @@ -23,42 +23,42 @@ (init [this context] (f) context))] (logging/with-test-logging (is (thrown-with-msg? - RuntimeException #"Service ':MissingService' not found" - (testutils/bootstrap-services-with-empty-config [broken-service]))) + RuntimeException #"Service ':MissingService' not found" + (testutils/bootstrap-services-with-empty-config [broken-service]))) (is (logged? #"Error during app buildup!" :error) "App buildup error message not logged")))) (testing "missing service function throws meaningful message and logs error" (let [test-service (service FooService - [] - (foo [this] "foo")) + [] + (foo [this] "foo")) broken-service (service [[:FooService bar]] (init [this context] (bar) context))] (logging/with-test-logging (is (thrown-with-msg? - RuntimeException - #"Service function 'bar' not found in service 'FooService" - (testutils/bootstrap-services-with-empty-config - [test-service - broken-service]))) + RuntimeException + #"Service function 'bar' not found in service 'FooService" + (testutils/bootstrap-services-with-empty-config + [test-service + broken-service]))) (is (logged? #"Error during app buildup!" :error) "App buildup error message not logged"))) (is (thrown-with-msg? - RuntimeException #"Service does not define function 'foo'" - (macroexpand '(puppetlabs.trapperkeeper.services/service - puppetlabs.trapperkeeper.core-test/FooService - [] - (init [this context] context))))))) + RuntimeException #"Service does not define function 'foo'" + (macroexpand '(puppetlabs.trapperkeeper.services/service + puppetlabs.trapperkeeper.core-test/FooService + [] + (init [this context] context))))))) (deftest test-main (testing "Parsed CLI data" (let [bootstrap-file "/fake/path/bootstrap.cfg" config-dir "/fake/config/dir" cli-data (parse-cli-args! - ["--debug" - "--bootstrap-config" bootstrap-file - "--config" config-dir])] + ["--debug" + "--bootstrap-config" bootstrap-file + "--config" config-dir])] (is (= bootstrap-file (cli-data :bootstrap-config))) (is (= config-dir (cli-data :config))) (is (cli-data :debug)))) @@ -73,8 +73,8 @@ (is (= :puppetlabs.kitchensink.core/cli-error (:type m))) (is (contains? m :message)) (is (re-find - #"Unknown option.*--invalid-argument" - (m :message))) + #"Unknown option.*--invalid-argument" + (m :message))) (reset! got-expected-exception true))) (is (true? @got-expected-exception)))) diff --git a/test/puppetlabs/trapperkeeper/examples/bootstrapping/test_services.clj b/test/puppetlabs/trapperkeeper/examples/bootstrapping/test_services.clj index 1e3b50e1..69215f66 100644 --- a/test/puppetlabs/trapperkeeper/examples/bootstrapping/test_services.clj +++ b/test/puppetlabs/trapperkeeper/examples/bootstrapping/test_services.clj @@ -18,36 +18,36 @@ (test-fn-three [this])) (defservice hello-world-service - HelloWorldService - [] - (hello-world [this] "hello world")) + HelloWorldService + [] + (hello-world [this] "hello world")) (defservice foo-test-service - TestService - [] - (test-fn [this] :foo)) + TestService + [] + (test-fn [this] :foo)) (defservice classpath-test-service - TestService - [] - (test-fn [this] :classpath)) + TestService + [] + (test-fn [this] :classpath)) (defservice cwd-test-service - TestService - [] - (test-fn [this] :cwd)) + TestService + [] + (test-fn [this] :cwd)) (defservice cli-test-service - TestService - [] - (test-fn [this] :cli)) + TestService + [] + (test-fn [this] :cli)) (defservice test-service-two - TestServiceTwo - [] - (test-fn-two [this] :two)) + TestServiceTwo + [] + (test-fn-two [this] :two)) (defservice test-service-three - TestServiceThree - [] - (test-fn-three [this] :three)) + TestServiceThree + [] + (test-fn-three [this] :three)) diff --git a/test/puppetlabs/trapperkeeper/internal_test.clj b/test/puppetlabs/trapperkeeper/internal_test.clj index db08beaf..abe0f6c1 100644 --- a/test/puppetlabs/trapperkeeper/internal_test.clj +++ b/test/puppetlabs/trapperkeeper/internal_test.clj @@ -11,17 +11,17 @@ (let [boot-promise (promise) lifecycle-events (atom []) svc (tk/service - [] - (init [this context] - (swap! lifecycle-events conj :init) - context) - (start [this context] - @boot-promise - (swap! lifecycle-events conj :start) - context) - (stop [this context] - (swap! lifecycle-events conj :stop) - context)) + [] + (init [this context] + (swap! lifecycle-events conj :init) + context) + (start [this context] + @boot-promise + (swap! lifecycle-events conj :start) + context) + (stop [this context] + (swap! lifecycle-events conj :stop) + context)) config-fn (constantly {}) app (internal/build-app* [svc] config-fn) main-thread (future (internal/boot-services-for-app* app))] @@ -56,17 +56,17 @@ (let [stop-promise (promise) lifecycle-events (atom []) svc (tk/service - [] - (init [this context] - (swap! lifecycle-events conj :init) - context) - (start [this context] - (swap! lifecycle-events conj :start) - context) - (stop [this context] - @stop-promise - (swap! lifecycle-events conj :stop) - context)) + [] + (init [this context] + (swap! lifecycle-events conj :init) + context) + (start [this context] + (swap! lifecycle-events conj :start) + context) + (stop [this context] + @stop-promise + (swap! lifecycle-events conj :stop) + context)) app (testutils/bootstrap-services-with-config [svc] {})] @@ -84,12 +84,12 @@ ;; and confirm that we get a log message indicating that they were rejected (dotimes [i 3] (logging/with-test-logging - (internal/restart-tk-apps [app]) + (internal/restart-tk-apps [app]) - (is (logged? (format "Ignoring new SIGHUP restart requests; too many requests queued (%s)" - internal/max-pending-lifecycle-events) - :warn) - "Missing expected log message when too many HUP requests queued"))) + (is (logged? (format "Ignoring new SIGHUP restart requests; too many requests queued (%s)" + internal/max-pending-lifecycle-events) + :warn) + "Missing expected log message when too many HUP requests queued"))) ;; now we unblock all of the queued restarts (deliver stop-promise true) diff --git a/test/puppetlabs/trapperkeeper/logging_test.clj b/test/puppetlabs/trapperkeeper/logging_test.clj index b6216fed..c13b62bf 100644 --- a/test/puppetlabs/trapperkeeper/logging_test.clj +++ b/test/puppetlabs/trapperkeeper/logging_test.clj @@ -16,26 +16,26 @@ ;; Prevent the stacktrace from being printed out (with-redefs [clojure.stacktrace/print-cause-trace (fn [e] nil)] (catch-all-logger - (Exception. "This exception is expected; testing error logging") - "this is my error message")) + (Exception. "This exception is expected; testing error logging") + "this is my error message")) (is (logged? #"this is my error message" :error))))) (deftest with-test-logging-on-separate-thread (testing "test-logging captures log messages from `future` threads" (with-test-logging - (let [log-future (future - (log/error "yo yo yo"))] - @log-future - (is (logged? #"yo yo yo" :error))))) + (let [log-future (future + (log/error "yo yo yo"))] + @log-future + (is (logged? #"yo yo yo" :error))))) (testing "threading doesn't break stuff" (with-test-logging - (let [done? (promise)] - (.start (Thread. (fn [] - (log/info "test thread") - (deliver done? true)))) - (is (true? @done?)) - (is (logged? #"test thread" :info)))))) + (let [done? (promise)] + (.start (Thread. (fn [] + (log/info "test thread") + (deliver done? true)))) + (is (true? @done?)) + (is (logged? #"test thread" :info)))))) (deftest test-logging-configuration (testing "Calling `configure-logging!` with a logback.xml file" diff --git a/test/puppetlabs/trapperkeeper/optional_deps_test.clj b/test/puppetlabs/trapperkeeper/optional_deps_test.clj index 70c9c215..6cb028f4 100644 --- a/test/puppetlabs/trapperkeeper/optional_deps_test.clj +++ b/test/puppetlabs/trapperkeeper/optional_deps_test.clj @@ -35,22 +35,22 @@ (testing "when not using a protocol" (let [poetry-service (service {:required [HaikuService] :optional [SonnetService]} - (init [this ctx] - (assoc ctx - :haiku-svc (get-service this :HaikuService) - :sonnet-svc (tks/maybe-get-service this :SonnetService))))] + (init [this ctx] + (assoc ctx + :haiku-svc (get-service this :HaikuService) + :sonnet-svc (tks/maybe-get-service this :SonnetService))))] (is (build-app [poetry-service haiku-service] {})))) (testing "when dep form is well formed" (testing "when there are no optional deps" (let [poetry-service (service PoetryService - {:required [HaikuService SonnetService] - :optional []} - (get-haiku [this] - (let [haiku-svc (get-service this :HaikuService)] - (haiku haiku-svc "tea leaves thwart those who"))) - (get-sonnet [this] - (let [sonnet-svc (get-service this :SonnetService)] - (sonnet sonnet-svc "designing futures" ["rhyming" "is overrated"])))) + {:required [HaikuService SonnetService] + :optional []} + (get-haiku [this] + (let [haiku-svc (get-service this :HaikuService)] + (haiku haiku-svc "tea leaves thwart those who"))) + (get-sonnet [this] + (let [sonnet-svc (get-service this :SonnetService)] + (sonnet sonnet-svc "designing futures" ["rhyming" "is overrated"])))) app (build-app [haiku-service poetry-service sonnet-service] {})] (is (= ["here is a haiku" "about the topic you want" @@ -65,14 +65,14 @@ (testing "when there are normal optional deps" (testing "and they are all included" (let [poetry-service (service PoetryService - {:required [] - :optional [HaikuService SonnetService]} - (get-haiku [this] - (let [haiku-svc (get-service this :HaikuService)] - (haiku haiku-svc "tea leaves thwart those who"))) - (get-sonnet [this] - (let [sonnet-svc (get-service this :SonnetService)] - (sonnet sonnet-svc "designing futures" ["rhyming" "is overrated"])))) + {:required [] + :optional [HaikuService SonnetService]} + (get-haiku [this] + (let [haiku-svc (get-service this :HaikuService)] + (haiku haiku-svc "tea leaves thwart those who"))) + (get-sonnet [this] + (let [sonnet-svc (get-service this :SonnetService)] + (sonnet sonnet-svc "designing futures" ["rhyming" "is overrated"])))) app (build-app [haiku-service poetry-service sonnet-service] {})] (is (= ["here is a haiku" "about the topic you want" @@ -86,15 +86,15 @@ (testing "and one is excluded" (let [poetry-service (service PoetryService - {:required [] - :optional [HaikuService SonnetService]} - (get-haiku [this] - (let [haiku-svc (get-service this :HaikuService)] - (haiku haiku-svc "tea leaves thwart those who"))) - (get-sonnet [this] - (if (tks/service-included? this :SonnetService) - (sonnet (get-service this :SonnetService) "designing futures" ["rhyming" "is overrated"]) - ["imagine the saddest sonnet"]))) + {:required [] + :optional [HaikuService SonnetService]} + (get-haiku [this] + (let [haiku-svc (get-service this :HaikuService)] + (haiku haiku-svc "tea leaves thwart those who"))) + (get-sonnet [this] + (if (tks/service-included? this :SonnetService) + (sonnet (get-service this :SonnetService) "designing futures" ["rhyming" "is overrated"]) + ["imagine the saddest sonnet"]))) app (build-app [haiku-service poetry-service] {})] (is (= ["here is a haiku" "about the topic you want" @@ -105,16 +105,16 @@ (testing "and all are excluded" (let [poetry-service (service PoetryService - {:required [] - :optional [HaikuService SonnetService]} - (get-haiku [this] - (if-let [haiku-svc (tks/maybe-get-service this :HaikuService)] - (haiku haiku-svc ["tea leaves thwart those who"]) - ["imagine the saddest haiku"])) - (get-sonnet [this] - (if (tks/service-included? this :SonnetService) - (sonnet (get-service this :SonnetService) "designing futures" ["rhyming" "is overrated"]) - ["imagine the saddest sonnet"]))) + {:required [] + :optional [HaikuService SonnetService]} + (get-haiku [this] + (if-let [haiku-svc (tks/maybe-get-service this :HaikuService)] + (haiku haiku-svc ["tea leaves thwart those who"]) + ["imagine the saddest haiku"])) + (get-sonnet [this] + (if (tks/service-included? this :SonnetService) + (sonnet (get-service this :SonnetService) "designing futures" ["rhyming" "is overrated"]) + ["imagine the saddest sonnet"]))) app (build-app [poetry-service] {})] (is (= ["imagine the saddest haiku"] (get-haiku (tka/get-service app :PoetryService)))) @@ -123,13 +123,13 @@ (testing "when there is a destructured required dep" (let [poetry-service (service PoetryService - {:required [[:SonnetService sonnet]] - :optional [HaikuService]} - (get-haiku [this] - (if-let [haiku-svc (tks/maybe-get-service this :HaikuService)] - (haiku haiku-svc ["tea leaves thwart those who"]) - ["imagine the saddest haiku"])) - (get-sonnet [this] (sonnet "designing futures" ["rhyming" "is overrated"]))) + {:required [[:SonnetService sonnet]] + :optional [HaikuService]} + (get-haiku [this] + (if-let [haiku-svc (tks/maybe-get-service this :HaikuService)] + (haiku haiku-svc ["tea leaves thwart those who"]) + ["imagine the saddest haiku"])) + (get-sonnet [this] (sonnet "designing futures" ["rhyming" "is overrated"]))) app (build-app [poetry-service sonnet-service] {})] (is (= ["imagine the saddest haiku"] (get-haiku (tka/get-service app :PoetryService)))) diff --git a/test/puppetlabs/trapperkeeper/plugins_test.clj b/test/puppetlabs/trapperkeeper/plugins_test.clj index 2c66d687..ea7a9ad5 100644 --- a/test/puppetlabs/trapperkeeper/plugins_test.clj +++ b/test/puppetlabs/trapperkeeper/plugins_test.clj @@ -17,9 +17,9 @@ (deftest test-bad-directory (testing "TK throws an exception if --plugins is provided with a dir that does not exist." (is (thrown-with-msg? - IllegalArgumentException - #".*directory.*does not exist.*" - (bootstrap-with-empty-config ["--plugins" "/this/does/not/exist"]))))) + IllegalArgumentException + #".*directory.*does not exist.*" + (bootstrap-with-empty-config ["--plugins" "/this/does/not/exist"]))))) (deftest test-no-duplicates (testing "duplicate test passes on .jar with just a service in it" @@ -29,16 +29,16 @@ (deftest test-duplicates (testing "duplicate test fails when an older version of kitchensink is included" (is (thrown-with-msg? - IllegalArgumentException - #".*Class or namespace.*found in both.*" - (verify-no-duplicate-resources - (file "plugin-test-resources/bad-plugins")))))) + IllegalArgumentException + #".*Class or namespace.*found in both.*" + (verify-no-duplicate-resources + (file "plugin-test-resources/bad-plugins")))))) (deftest test-plugin-service (testing "TK can load and use service defined in plugin .jar" (let [app (bootstrap-with-empty-config - ["--plugins" "./plugin-test-resources/plugins" - "--bootstrap-config" "./dev-resources/bootstrapping/plugin/bootstrap.cfg"]) + ["--plugins" "./plugin-test-resources/plugins" + "--bootstrap-config" "./dev-resources/bootstrapping/plugin/bootstrap.cfg"]) service-fn (-> (service-graph app) :PluginTestService :moo)] diff --git a/test/puppetlabs/trapperkeeper/services_internal_test.clj b/test/puppetlabs/trapperkeeper/services_internal_test.clj index 60ccd16b..2584d57b 100644 --- a/test/puppetlabs/trapperkeeper/services_internal_test.clj +++ b/test/puppetlabs/trapperkeeper/services_internal_test.clj @@ -28,35 +28,35 @@ :fns '((fn1 [] "fn1") (fn2 [] "fn2")) :service-protocol-sym 'Foo} (si/find-prot-and-deps-forms! - '(Foo [] (fn1 [] "fn1") (fn2 [] "fn2"))))) + '(Foo [] (fn1 [] "fn1") (fn2 [] "fn2"))))) (is (= {:dependencies [] :fns '((fn1 [] "fn1") (fn2 [] "fn2")) :service-protocol-sym nil} (si/find-prot-and-deps-forms! - '([] (fn1 [] "fn1") (fn2 [] "fn2")))))) + '([] (fn1 [] "fn1") (fn2 [] "fn2")))))) (testing "should throw exception if the first form is not the protocol symbol or dependency vector" (is (thrown-with-msg? - IllegalArgumentException - #"Invalid service definition; first form must be protocol or dependency list; found '\"hi\"'" - (si/find-prot-and-deps-forms! '("hi" []))))) + IllegalArgumentException + #"Invalid service definition; first form must be protocol or dependency list; found '\"hi\"'" + (si/find-prot-and-deps-forms! '("hi" []))))) (testing "should throw exception if the first form is a protocol sym and the second is not a dependency vector" (is (thrown-with-msg? - IllegalArgumentException - #"Invalid service definition; expected dependency list following protocol, found: '\"hi\"'" - (si/find-prot-and-deps-forms! '(Foo "hi"))))) + IllegalArgumentException + #"Invalid service definition; expected dependency list following protocol, found: '\"hi\"'" + (si/find-prot-and-deps-forms! '(Foo "hi"))))) (testing "should throw an exception if all remaining forms are not seqs" (is (thrown-with-msg? - IllegalArgumentException - #"Invalid service definition; expected function definitions following dependency list, invalid value: '\"hi\"'" - (si/find-prot-and-deps-forms! '(Foo [] (fn1 [] "fn1") "hi")))))) + IllegalArgumentException + #"Invalid service definition; expected function definitions following dependency list, invalid value: '\"hi\"'" + (si/find-prot-and-deps-forms! '(Foo [] (fn1 [] "fn1") "hi")))))) (defn local-resolve "Resolve symbol in current (services-internal-test) namespace" [sym] {:pre [(symbol? sym)]} (ns-resolve - 'puppetlabs.trapperkeeper.services-internal-test - sym)) + 'puppetlabs.trapperkeeper.services-internal-test + sym)) (defprotocol EmptyProtocol) (def NonProtocolSym "hi") @@ -64,31 +64,31 @@ (deftest protocol-syms-test (testing "should not throw exception if protocol exists" (is (si/protocol? - (si/validate-protocol-sym! - 'EmptyProtocol - (local-resolve 'EmptyProtocol))))) + (si/validate-protocol-sym! + 'EmptyProtocol + (local-resolve 'EmptyProtocol))))) (testing "should throw exception if service protocol sym is not resolvable" (is (thrown-with-msg? - IllegalArgumentException - #"Unrecognized service protocol 'UndefinedSym'" - (si/validate-protocol-sym! 'UndefinedSym (local-resolve 'UndefinedSym))))) + IllegalArgumentException + #"Unrecognized service protocol 'UndefinedSym'" + (si/validate-protocol-sym! 'UndefinedSym (local-resolve 'UndefinedSym))))) (testing "should throw exception if service protocol symbol is resolveable but does not resolve to a protocol" (is (thrown-with-msg? - IllegalArgumentException - #"Specified service protocol 'NonProtocolSym' does not appear to be a protocol!" - (si/validate-protocol-sym! 'NonProtocolSym (local-resolve 'NonProtocolSym)))))) + IllegalArgumentException + #"Specified service protocol 'NonProtocolSym' does not appear to be a protocol!" + (si/validate-protocol-sym! 'NonProtocolSym (local-resolve 'NonProtocolSym)))))) (deftest build-fns-map-test (testing "minimal services may not define functions other than lifecycle functions" (is (thrown-with-msg? - IllegalArgumentException - #"Service attempts to define function 'foo', but does not provide protocol" - (si/build-fns-map! nil [] ['init 'start] - '((init [this context] context) - (start [this context] context) - (foo [this] "foo"))))))) + IllegalArgumentException + #"Service attempts to define function 'foo', but does not provide protocol" + (si/build-fns-map! nil [] ['init 'start] + '((init [this context] context) + (start [this context] context) + (foo [this] "foo"))))))) (defprotocol Service1 (service1-fn [this])) @@ -102,41 +102,41 @@ (deftest invalid-fns-test (testing "should throw an exception if there is no definition of a function in the protocol" (is (thrown-with-msg? - IllegalArgumentException - #"Service does not define function 'service1-fn', which is required by protocol 'Service1'" - (si/parse-service-forms! - ['init 'start] - (cons 'puppetlabs.trapperkeeper.services-internal-test/Service1 - '([] (init [this context] context))))))) + IllegalArgumentException + #"Service does not define function 'service1-fn', which is required by protocol 'Service1'" + (si/parse-service-forms! + ['init 'start] + (cons 'puppetlabs.trapperkeeper.services-internal-test/Service1 + '([] (init [this context] context))))))) (testing "should throw an exception if there is a definition for a function that is not in the protocol" (is (thrown-with-msg? - IllegalArgumentException - #"Service attempts to define function 'foo', which does not exist in protocol 'Service1'" - (si/parse-service-forms! - ['init 'start] - (cons 'puppetlabs.trapperkeeper.services-internal-test/Service1 - '([] (foo [this] "foo"))))))) + IllegalArgumentException + #"Service attempts to define function 'foo', which does not exist in protocol 'Service1'" + (si/parse-service-forms! + ['init 'start] + (cons 'puppetlabs.trapperkeeper.services-internal-test/Service1 + '([] (foo [this] "foo"))))))) (testing "should throw an exception if the protocol includes a function with the same name as a lifecycle function" (is (thrown-with-msg? - IllegalArgumentException - #"Service protocol 'BadServiceProtocol' includes function named 'start', which conflicts with lifecycle function by same name" - (si/parse-service-forms! - ['init 'start] - (cons 'puppetlabs.trapperkeeper.services-internal-test/BadServiceProtocol - '([] (start [this] "foo")))))))) + IllegalArgumentException + #"Service protocol 'BadServiceProtocol' includes function named 'start', which conflicts with lifecycle function by same name" + (si/parse-service-forms! + ['init 'start] + (cons 'puppetlabs.trapperkeeper.services-internal-test/BadServiceProtocol + '([] (start [this] "foo")))))))) (deftest prismatic-functionality-test (testing "prismatic fnk is initialized properly" (let [service1 (service Service1 - [] - (init [this context] context) - (start [this context] context) - (service1-fn [this] "Foo!")) + [] + (init [this context] context) + (start [this context] context) + (service1-fn [this] "Foo!")) service2 (service Service2 - [[:Service1 service1-fn]] - (init [this context] context) - (start [this context] context) - (service2-fn [this] "Bar!")) + [[:Service1 service1-fn]] + (init [this context] context) + (start [this context] context) + (service2-fn [this] "Bar!")) s1-graph (service-map service1) s2-graph (service-map service2)] (is (map? s1-graph)) diff --git a/test/puppetlabs/trapperkeeper/services_namespaces_test/ns2.clj b/test/puppetlabs/trapperkeeper/services_namespaces_test/ns2.clj index f4d8212c..cb33061d 100644 --- a/test/puppetlabs/trapperkeeper/services_namespaces_test/ns2.clj +++ b/test/puppetlabs/trapperkeeper/services_namespaces_test/ns2.clj @@ -1,19 +1,19 @@ (ns puppetlabs.trapperkeeper.services-namespaces-test.ns2 (:require - [clojure.test :refer :all] - [puppetlabs.trapperkeeper.core :as trapperkeeper] - [puppetlabs.trapperkeeper.services :as tk-services] - [puppetlabs.trapperkeeper.services-namespaces-test.ns1 :as ns1] - [puppetlabs.trapperkeeper.testutils.bootstrap :refer [bootstrap-services-with-empty-config]] - [schema.test :as schema-test] - [puppetlabs.kitchensink.testutils.fixtures :refer [with-no-jvm-shutdown-hooks]])) + [clojure.test :refer :all] + [puppetlabs.trapperkeeper.core :as trapperkeeper] + [puppetlabs.trapperkeeper.services :as tk-services] + [puppetlabs.trapperkeeper.services-namespaces-test.ns1 :as ns1] + [puppetlabs.trapperkeeper.testutils.bootstrap :refer [bootstrap-services-with-empty-config]] + [schema.test :as schema-test] + [puppetlabs.kitchensink.testutils.fixtures :refer [with-no-jvm-shutdown-hooks]])) (use-fixtures :once schema-test/validate-schemas with-no-jvm-shutdown-hooks) (trapperkeeper/defservice foo-service - ns1/FooService - [] - (foo [this] "foo")) + ns1/FooService + [] + (foo [this] "foo")) (deftest test-service-namespaces (testing "can boot service defined in different namespace than protocol" diff --git a/test/puppetlabs/trapperkeeper/services_test.clj b/test/puppetlabs/trapperkeeper/services_test.clj index 0e460db8..ee0398be 100644 --- a/test/puppetlabs/trapperkeeper/services_test.clj +++ b/test/puppetlabs/trapperkeeper/services_test.clj @@ -155,7 +155,7 @@ (internal/restart-tk-apps [app]) (let [start (System/currentTimeMillis)] (while (and (not= (count @call-seq) 15) - (< (- (System/currentTimeMillis) start) 5000)) + (< (- (System/currentTimeMillis) start) 5000)) (Thread/yield))) (is (= (count @call-seq) 15)) (is (= [:init-service1 :init-service2 :init-service3 @@ -181,11 +181,11 @@ service1 (service EmptyService [] (init [this context] - (reset! test-init-context (merge context context-elem)) - (swap! test-init-count inc) - {:context @test-init-context :count @test-init-count}) + (reset! test-init-context (merge context context-elem)) + (swap! test-init-count inc) + {:context @test-init-context :count @test-init-count}) (start [this context] - (reset! test-start-context context)))] + (reset! test-start-context context)))] (with-app-with-empty-config app [service1] (is (= context-elem @test-init-context)) (is (= {:foo "bar"} (:context @test-start-context))) @@ -211,18 +211,18 @@ ; the stop will happen because of the exception. So instead, we use ; the tk/run-app here to block on the app until the restart is ; called and explodes in an exception. - (let [app (internal/throw-app-error-if-exists! - (bootstrap-services-with-empty-config services)) - app-running (future (tk/run-app app))] - (is (= [:init-service1 :init-service2 :init-service3 - :start-service1 :start-service2 :start-service3] - @call-seq)) - (app/restart app) - (try - @app-running - (catch ExecutionException e - (is (instance? IllegalStateException (.getCause e))) - (is (= "Exploding Service" (.. e getCause getMessage))))))) + (let [app (internal/throw-app-error-if-exists! + (bootstrap-services-with-empty-config services)) + app-running (future (tk/run-app app))] + (is (= [:init-service1 :init-service2 :init-service3 + :start-service1 :start-service2 :start-service3] + @call-seq)) + (app/restart app) + (try + @app-running + (catch ExecutionException e + (is (instance? IllegalStateException (.getCause e))) + (is (= "Exploding Service" (.. e getCause getMessage))))))) ; Here we validate that the stop completed but no new init happened (is (= [:init-service1 :init-service2 :init-service3 :start-service1 :start-service2 :start-service3 @@ -235,18 +235,18 @@ service1 (service Service1 [] (init [this context] - (swap! test-context assoc :init-service-id (svcs/service-id this)) - context) + (swap! test-context assoc :init-service-id (svcs/service-id this)) + context) (start [this context] - (swap! test-context assoc :start-service-id (svcs/service-id this)) - context) + (swap! test-context assoc :start-service-id (svcs/service-id this)) + context) (stop [this context] - (swap! test-context assoc :stop-service-id (svcs/service-id this)) - context) + (swap! test-context assoc :stop-service-id (svcs/service-id this)) + context) (service1-fn [this] nil))] (with-app-with-empty-config app [service1] ;; no-op; we just want the app to start up and shut down - ) +) (is (= :Service1 (:init-service-id @test-context))) (is (= :Service1 (:start-service-id @test-context))) (is (= :Service1 (:stop-service-id @test-context)))))) @@ -270,8 +270,8 @@ service2 (service Service2 [[:Service1 service1-fn]] (init [this context] - (let [s1 (svcs/get-service this :Service1)] - (assoc context :s1 s1))) + (let [s1 (svcs/get-service this :Service1)] + (assoc context :s1 s1))) (service2-fn [this] ((svcs/service-context this) :s1))) app (bootstrap-services-with-empty-config [service1 service2]) s2 (app/get-service app :Service2) @@ -459,12 +459,12 @@ (let [call-seq (atom []) service0 (service [] (init [this context] - (swap! call-seq conj :init) - (assoc context :foo :bar)) + (swap! call-seq conj :init) + (assoc context :foo :bar)) (start [this context] - (swap! call-seq conj :start) - (is (= context {:foo :bar})) - context))] + (swap! call-seq conj :start) + (is (= context {:foo :bar})) + context))] (bootstrap-services-with-empty-config [service0]) (is (= [:init :start] @call-seq)))) @@ -475,8 +475,8 @@ result (atom nil) service0 (service [[:Service1 service1-fn]] (init [this context] - (reset! result (service1-fn)) - context))] + (reset! result (service1-fn)) + context))] (bootstrap-services-with-empty-config [service1 service0]) (is (= "hi" @result))))) @@ -492,7 +492,7 @@ service1 (service Service1 [[:MultiArityService foo]] (service1-fn [this] - [(foo 5) (foo 3 6)])) + [(foo 5) (foo 3 6)])) app (bootstrap-services-with-empty-config [ma-service service1]) mas (app/get-service app :MultiArityService) s1 (app/get-service app :Service1)] @@ -509,5 +509,5 @@ puppetlabs.trapperkeeper.services-test/Service1 [] (service1-fn - "This is an example of an invalid docstring" - [this] nil))))))) \ No newline at end of file + "This is an example of an invalid docstring" + [this] nil))))))) \ No newline at end of file diff --git a/test/puppetlabs/trapperkeeper/shutdown_test.clj b/test/puppetlabs/trapperkeeper/shutdown_test.clj index a0bb69fb..3e27422a 100644 --- a/test/puppetlabs/trapperkeeper/shutdown_test.clj +++ b/test/puppetlabs/trapperkeeper/shutdown_test.clj @@ -24,9 +24,9 @@ (testing "service with shutdown hook gets called during shutdown" (let [shutdown-called? (atom false) test-service (service [] - (stop [this context] - (reset! shutdown-called? true) - context)) + (stop [this context] + (reset! shutdown-called? true) + context)) app (bootstrap-services-with-empty-config [test-service])] (is (false? @shutdown-called?)) (internal/shutdown! (app-context app)) @@ -36,14 +36,14 @@ (testing "services are shut down in dependency order" (let [order (atom []) service1 (service ShutdownTestService - [] - (stop [this context] - (swap! order conj 1) - context)) + [] + (stop [this context] + (swap! order conj 1) + context)) service2 (service [[:ShutdownTestService]] - (stop [this context] - (swap! order conj 2) - context)) + (stop [this context] + (swap! order conj 2) + context)) app (bootstrap-services-with-empty-config [service1 service2])] (is (empty? @order)) (internal/shutdown! (app-context app)) @@ -53,26 +53,26 @@ (testing "services continue to shut down when one throws an exception" (let [shutdown-called? (atom false) test-service (service [] - (stop [this context] - (reset! shutdown-called? true) - context)) + (stop [this context] + (reset! shutdown-called? true) + context)) broken-service (service [] - (stop [this context] - (throw (RuntimeException. "dangit")))) + (stop [this context] + (throw (RuntimeException. "dangit")))) app (bootstrap-services-with-empty-config [test-service broken-service])] (is (false? @shutdown-called?)) (logging/with-test-logging - (internal/shutdown! (app-context app)) - (is (logged? #"Encountered error during shutdown sequence" :error))) + (internal/shutdown! (app-context app)) + (is (logged? #"Encountered error during shutdown sequence" :error))) (is (true? @shutdown-called?))))) (deftest shutdown-run-app-test (testing "`tk/run-app` runs the framework (blocking until shutdown signal received), and `request-shutdown` shuts down services" (let [shutdown-called? (atom false) test-service (service [] - (stop [this context] - (reset! shutdown-called? true) - context)) + (stop [this context] + (reset! shutdown-called? true) + context)) app (bootstrap-services-with-empty-config [test-service]) shutdown-svc (get-service app :ShutdownService)] (is (false? @shutdown-called?)) @@ -85,16 +85,16 @@ "shut down and the error is rethrown from main") (let [shutdown-called? (atom false) test-service (service ShutdownTestServiceWithFn - [[:ShutdownService shutdown-on-error]] - (stop [this context] - (reset! shutdown-called? true) - context) - (test-fn [this] - (future (shutdown-on-error - (service-id this) - #(throw - (Throwable. - "oops")))))) + [[:ShutdownService shutdown-on-error]] + (stop [this context] + (reset! shutdown-called? true) + context) + (test-fn [this] + (future (shutdown-on-error + (service-id this) + #(throw + (Throwable. + "oops")))))) app (tk/boot-services-with-config [test-service] {}) test-svc (get-service app :ShutdownTestServiceWithFn)] (is (false? @shutdown-called?)) @@ -120,149 +120,149 @@ (testing (str "shutdown will be called if a service throws an exception " "during init on main thread, with appropriate errors logged") (logging/with-test-logging - (let [shutdown-called? (atom false) - test-service (service ShutdownTestService - [] - (init [this context] - (throw (Throwable. "oops")) - context) - (stop [this context] - (reset! shutdown-called? true) - context))] - (bootstrap-and-validate-shutdown - [test-service] - shutdown-called? - #"oops") - (is (logged? #"Error during service init!!!" :error) - "Error message for service init not logged."))))) + (let [shutdown-called? (atom false) + test-service (service ShutdownTestService + [] + (init [this context] + (throw (Throwable. "oops")) + context) + (stop [this context] + (reset! shutdown-called? true) + context))] + (bootstrap-and-validate-shutdown + [test-service] + shutdown-called? + #"oops") + (is (logged? #"Error during service init!!!" :error) + "Error message for service init not logged."))))) (deftest shutdown-ex-during-start-test (testing (str "shutdown will be called if a service throws an exception " "during start on main thread, with appropriate errors logged") (logging/with-test-logging - (let [shutdown-called? (atom false) - test-service (service ShutdownTestService - [] - (start [this context] - (throw (Throwable. "oops")) - context) - (stop [this context] - (reset! shutdown-called? true) - context))] - (bootstrap-and-validate-shutdown - [test-service] - shutdown-called? - #"oops") - (is (logged? #"Error during service start!!!" :error) - "Error message for service start not logged."))))) + (let [shutdown-called? (atom false) + test-service (service ShutdownTestService + [] + (start [this context] + (throw (Throwable. "oops")) + context) + (stop [this context] + (reset! shutdown-called? true) + context))] + (bootstrap-and-validate-shutdown + [test-service] + shutdown-called? + #"oops") + (is (logged? #"Error during service start!!!" :error) + "Error message for service start not logged."))))) (deftest shutdown-log-errors-during-init-test (testing (str "`shutdown-on-error` will catch and log errors raised during " "init on main thread") (logging/with-test-logging - (let [shutdown-called? (atom false) - test-service (service ShutdownTestService - [[:ShutdownService shutdown-on-error]] - (init [this context] - (shutdown-on-error - :ShutdownTestService - #(throw (Throwable. "oops"))) - context) - (stop [this context] - (reset! shutdown-called? true) - context))] - (bootstrap-and-validate-shutdown - [test-service] - shutdown-called? - #"oops") - (is (logged? #"shutdown-on-error triggered because of exception!" - :error) - "Error message for shutdown-on-error not logged."))))) + (let [shutdown-called? (atom false) + test-service (service ShutdownTestService + [[:ShutdownService shutdown-on-error]] + (init [this context] + (shutdown-on-error + :ShutdownTestService + #(throw (Throwable. "oops"))) + context) + (stop [this context] + (reset! shutdown-called? true) + context))] + (bootstrap-and-validate-shutdown + [test-service] + shutdown-called? + #"oops") + (is (logged? #"shutdown-on-error triggered because of exception!" + :error) + "Error message for shutdown-on-error not logged."))))) (deftest shutdown-log-errors-during-init-future-test (testing (str "`shutdown-on-error` will catch and log errors raised during " "init on future") (logging/with-test-logging - (let [shutdown-called? (atom false) - test-service (service ShutdownTestService - [[:ShutdownService shutdown-on-error]] - (init [this context] - @(future - (shutdown-on-error - :ShutdownTestService - #(throw (Throwable. "oops")))) - context) - (stop [this context] - (reset! shutdown-called? true) - context))] - (bootstrap-and-validate-shutdown - [test-service] - shutdown-called? - #"oops") - (is (logged? #"shutdown-on-error triggered because of exception!" - :error) - "Error message for shutdown-on-error not logged."))))) + (let [shutdown-called? (atom false) + test-service (service ShutdownTestService + [[:ShutdownService shutdown-on-error]] + (init [this context] + @(future + (shutdown-on-error + :ShutdownTestService + #(throw (Throwable. "oops")))) + context) + (stop [this context] + (reset! shutdown-called? true) + context))] + (bootstrap-and-validate-shutdown + [test-service] + shutdown-called? + #"oops") + (is (logged? #"shutdown-on-error triggered because of exception!" + :error) + "Error message for shutdown-on-error not logged."))))) (deftest shutdown-log-errors-during-start-test (testing (str "`shutdown-on-error` will catch and log errors raised during" "start on main thread") (logging/with-test-logging - (let [shutdown-called? (atom false) - test-service (service ShutdownTestService - [[:ShutdownService shutdown-on-error]] - (start [this context] - (shutdown-on-error - :ShutdownTestService - #(throw (Throwable. "oops"))) - context) - (stop [this context] - (reset! shutdown-called? true) - context))] - (bootstrap-and-validate-shutdown - [test-service] - shutdown-called? - #"oops") - (is (logged? #"shutdown-on-error triggered because of exception!" - :error) - "Error message for shutdown-on-error not logged."))))) + (let [shutdown-called? (atom false) + test-service (service ShutdownTestService + [[:ShutdownService shutdown-on-error]] + (start [this context] + (shutdown-on-error + :ShutdownTestService + #(throw (Throwable. "oops"))) + context) + (stop [this context] + (reset! shutdown-called? true) + context))] + (bootstrap-and-validate-shutdown + [test-service] + shutdown-called? + #"oops") + (is (logged? #"shutdown-on-error triggered because of exception!" + :error) + "Error message for shutdown-on-error not logged."))))) (deftest shutdown-log-errors-during-start-future-test (testing (str "`shutdown-on-error` will catch and log errors raised during " "start on future") (logging/with-test-logging - (let [shutdown-called? (atom false) - test-service (service ShutdownTestService - [[:ShutdownService shutdown-on-error]] - (start [this context] - @(future - (shutdown-on-error - :ShutdownTestService - #(throw (Throwable. "oops")))) - context) - (stop [this context] - (reset! shutdown-called? true) - context))] - (bootstrap-and-validate-shutdown - [test-service] - shutdown-called? - #"oops") - (is (logged? #"shutdown-on-error triggered because of exception!" - :error) - "Error message for shutdown-on-error not logged."))))) + (let [shutdown-called? (atom false) + test-service (service ShutdownTestService + [[:ShutdownService shutdown-on-error]] + (start [this context] + @(future + (shutdown-on-error + :ShutdownTestService + #(throw (Throwable. "oops")))) + context) + (stop [this context] + (reset! shutdown-called? true) + context))] + (bootstrap-and-validate-shutdown + [test-service] + shutdown-called? + #"oops") + (is (logged? #"shutdown-on-error triggered because of exception!" + :error) + "Error message for shutdown-on-error not logged."))))) (deftest shutdown-on-error-callback-test (testing "`shutdown-on-error` takes an optional function that is called on error" (let [shutdown-called? (atom false) on-error-fn-called? (atom false) broken-service (service ShutdownTestServiceWithFn - [[:ShutdownService shutdown-on-error]] - (stop [this context] - (reset! shutdown-called? true) - context) - (test-fn [this] - (shutdown-on-error (service-id this) - #(throw (RuntimeException. "uh oh")) - (fn [ctxt] (reset! on-error-fn-called? true))))) + [[:ShutdownService shutdown-on-error]] + (stop [this context] + (reset! shutdown-called? true) + context) + (test-fn [this] + (shutdown-on-error (service-id this) + #(throw (RuntimeException. "uh oh")) + (fn [ctxt] (reset! on-error-fn-called? true))))) app (bootstrap-services-with-empty-config [broken-service]) test-svc (get-service app :ShutdownTestServiceWithFn)] (is (false? @shutdown-called?)) @@ -278,48 +278,48 @@ (deftest shutdown-on-error-callback-error-test (testing "errors thrown by the `shutdown-on-error` optional on-error function are caught and logged" (let [broken-service (service ShutdownTestServiceWithFn - [[:ShutdownService shutdown-on-error]] - (test-fn [this] - (shutdown-on-error (service-id this) - #(throw (Throwable. "foo")) - (fn [ctxt] (throw (Throwable. "busted on-error function")))))) + [[:ShutdownService shutdown-on-error]] + (test-fn [this] + (shutdown-on-error (service-id this) + #(throw (Throwable. "foo")) + (fn [ctxt] (throw (Throwable. "busted on-error function")))))) app (bootstrap-services-with-empty-config [broken-service]) test-svc (get-service app :ShutdownTestServiceWithFn)] (logging/with-test-logging - (test-fn test-svc) - (is (thrown-with-msg? - Throwable - #"foo" - (tk/run-app app))) - (is (logged? #"Error occurred during shutdown" :error)))))) + (test-fn test-svc) + (is (thrown-with-msg? + Throwable + #"foo" + (tk/run-app app))) + (is (logged? #"Error occurred during shutdown" :error)))))) (deftest shutdown-on-error-error-handling (testing "Shutdown-on-error should never throw an exception." (testing "providing `nil` for all arguments" (let [test-service (tk/service - [[:ShutdownService shutdown-on-error]] - (init [this context] - (shutdown-on-error nil nil nil) - context))] + [[:ShutdownService shutdown-on-error]] + (init [this context] + (shutdown-on-error nil nil nil) + context))] (is (not (nil? (tk/boot-services-with-config [test-service] {})))))) (testing "passing `nil` instead of a function" (let [test-service (tk/service - [[:ShutdownService shutdown-on-error]] - (init [this context] - (shutdown-on-error context nil) - context))] + [[:ShutdownService shutdown-on-error]] + (init [this context] + (shutdown-on-error context nil) + context))] (is (not (nil? (tk/boot-services-with-config [test-service] {})))))))) (deftest app-check-for-errors!-tests (testing "check-for-errors! throws exception for shutdown-on-error in init" (let [test-service (service ShutdownTestService - [[:ShutdownService shutdown-on-error]] - (init [this context] - (shutdown-on-error - :ShutdownTestService - #(throw (Throwable. "oops"))) - context)) + [[:ShutdownService shutdown-on-error]] + (init [this context] + (shutdown-on-error + :ShutdownTestService + #(throw (Throwable. "oops"))) + context)) app (tk/boot-services-with-config [test-service] {})] (is (thrown-with-msg? Throwable @@ -328,10 +328,10 @@ "Expected error not thrown for check-for-errors!"))) (testing "check-for-errors! throws exception for error in init" (let [test-service (service ShutdownTestService - [] - (init [this context] - (throw (Throwable. "oops")) - context)) + [] + (init [this context] + (throw (Throwable. "oops")) + context)) app (tk/boot-services-with-config [test-service] {})] (is (thrown-with-msg? Throwable @@ -340,12 +340,12 @@ "Expected error not thrown for check-for-errors!"))) (testing "check-for-errors! throws exception for shutdown-on-error in start" (let [test-service (service ShutdownTestService - [[:ShutdownService shutdown-on-error]] - (start [this context] - (shutdown-on-error - :ShutdownTestService - #(throw (Throwable. "oops"))) - context)) + [[:ShutdownService shutdown-on-error]] + (start [this context] + (shutdown-on-error + :ShutdownTestService + #(throw (Throwable. "oops"))) + context)) app (tk/boot-services-with-config [test-service] {})] (is (thrown-with-msg? Throwable @@ -354,10 +354,10 @@ "Expected error not thrown for check-for-errors!"))) (testing "check-for-errors! throws exception for error in start" (let [test-service (service ShutdownTestService - [] - (start [this context] - (throw (Throwable. "oops")) - context)) + [] + (start [this context] + (throw (Throwable. "oops")) + context)) app (tk/boot-services-with-config [test-service] {})] (is (thrown-with-msg? Throwable @@ -366,9 +366,9 @@ "Expected error not thrown for check-for-errors!"))) (testing "check-for-errors! returns app when no shutdown-on-error occurs" (let [test-service (service ShutdownTestService - [] - (init [this context] - context)) + [] + (init [this context] + context)) app (tk/boot-services-with-config [test-service] {})] (is (identical? app (check-for-errors! app)) "app not returned for check-for-errors!")))) @@ -379,21 +379,21 @@ stop-should-proceed? (promise) lifecycle-events (atom []) svc (tk/service - [[:ShutdownService request-shutdown]] - (init [this context] - (swap! lifecycle-events conj :init) - context) - (start [this context] - (swap! lifecycle-events conj :start) - context) - (stop [this context] - (swap! lifecycle-events conj :stop) + [[:ShutdownService request-shutdown]] + (init [this context] + (swap! lifecycle-events conj :init) + context) + (start [this context] + (swap! lifecycle-events conj :start) + context) + (stop [this context] + (swap! lifecycle-events conj :stop) ;; request shutdown, which will trigger the shutdown logic ;; on the main thread. - (request-shutdown) - (deliver first-stop-begun? true) - @stop-should-proceed? - context)) + (request-shutdown) + (deliver first-stop-begun? true) + @stop-should-proceed? + context)) app (testutils/bootstrap-services-with-config [svc] {}) @@ -446,18 +446,18 @@ stop-should-proceed? (promise) lifecycle-events (atom []) svc (tk/service - [] - (init [this context] - (swap! lifecycle-events conj :init) - context) - (start [this context] - (swap! lifecycle-events conj :start) - context) - (stop [this context] - (swap! lifecycle-events conj :stop) - (deliver first-stop-begun? true) - @stop-should-proceed? - context)) + [] + (init [this context] + (swap! lifecycle-events conj :init) + context) + (start [this context] + (swap! lifecycle-events conj :start) + context) + (stop [this context] + (swap! lifecycle-events conj :stop) + (deliver first-stop-begun? true) + @stop-should-proceed? + context)) app (testutils/bootstrap-services-with-config [svc] {}) @@ -509,18 +509,18 @@ stop-should-proceed? (promise) lifecycle-events (atom []) svc (tk/service - [] - (init [this context] - (swap! lifecycle-events conj :init) - context) - (start [this context] - (swap! lifecycle-events conj :start) - context) - (stop [this context] - (swap! lifecycle-events conj :stop) - (deliver first-stop-begun? true) - @stop-should-proceed? - context)) + [] + (init [this context] + (swap! lifecycle-events conj :init) + context) + (start [this context] + (swap! lifecycle-events conj :start) + context) + (stop [this context] + (swap! lifecycle-events conj :stop) + (deliver first-stop-begun? true) + @stop-should-proceed? + context)) app (testutils/bootstrap-services-with-config [svc] {}) diff --git a/test/puppetlabs/trapperkeeper/testutils/bootstrap.clj b/test/puppetlabs/trapperkeeper/testutils/bootstrap.clj index a12c4a73..29951776 100644 --- a/test/puppetlabs/trapperkeeper/testutils/bootstrap.clj +++ b/test/puppetlabs/trapperkeeper/testutils/bootstrap.clj @@ -27,8 +27,8 @@ (defn bootstrap-services-with-cli-data [services cli-data] (internal/throw-app-error-if-exists! - (tk/boot-services-with-config-fn services - #(config/parse-config-data cli-data)))) + (tk/boot-services-with-config-fn services + #(config/parse-config-data cli-data)))) (defmacro with-app-with-cli-data [app services cli-data & body] @@ -71,7 +71,7 @@ (bootstrap-with-empty-config [])) ([other-args] (-> other-args - (conj "--config" empty-config ) + (conj "--config" empty-config) (internal/parse-cli-args!) (tk/boot-with-cli-data) (internal/throw-app-error-if-exists!)))) diff --git a/test/puppetlabs/trapperkeeper/testutils/logging.clj b/test/puppetlabs/trapperkeeper/testutils/logging.clj index 7be227aa..15d7302d 100644 --- a/test/puppetlabs/trapperkeeper/testutils/logging.clj +++ b/test/puppetlabs/trapperkeeper/testutils/logging.clj @@ -300,8 +300,8 @@ (binding [*test-log-events* destination#] (with-redefs [pl-log/configure-logger! (fn [& _#])] (with-log-level root-logger-name :trace - (with-logging-to-atom root-logger-name destination# - ~@body)))))) + (with-logging-to-atom root-logger-name destination# + ~@body)))))) (defmacro with-test-logging-debug "Creates an environment for the use of the logged? test method, and @@ -439,15 +439,15 @@ ([destination debug?] (let [appender (proxy [AppenderBase] [] (append [logging-event] - (let [throwable-info (.getThrowableInformation logging-event) - ex (if throwable-info (.getThrowable throwable-info)) - entry [(.getLoggerName logging-event) - (.getLevel logging-event) - ex - (str (.getMessage logging-event))]] - (when debug? (log-to-console entry)) - (swap! destination conj entry))) - (close []))] + (let [throwable-info (.getThrowableInformation logging-event) + ex (if throwable-info (.getThrowable throwable-info)) + entry [(.getLoggerName logging-event) + (.getLevel logging-event) + ex + (str (.getMessage logging-event))]] + (when debug? (log-to-console entry)) + (swap! destination conj entry))) + (close []))] (.setContext appender (pl-log/logging-context)) appender))) @@ -475,8 +475,8 @@ (.addAppender root-logger# temp-appender#) (binding [clojure.tools.logging/*logger-factory* (atom-logger - ~log-output-atom - (~options :debug))] + ~log-output-atom + (~options :debug))] ~@body) (finally (.detachAppender root-logger# temp-appender#) From 4e59be52a6ccf5322b90c432d9385bc5806ee4bc Mon Sep 17 00:00:00 2001 From: Justin Stoller Date: Tue, 5 Apr 2016 10:30:56 -0700 Subject: [PATCH 3/3] (maint) realign comment in java service example --- .../java_service/src/clj/java_service_example/java_service.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/java_service/src/clj/java_service_example/java_service.clj b/examples/java_service/src/clj/java_service_example/java_service.clj index 0d7eb589..b1e2f76d 100644 --- a/examples/java_service/src/clj/java_service_example/java_service.clj +++ b/examples/java_service/src/clj/java_service_example/java_service.clj @@ -10,7 +10,7 @@ (defservice java-service JavaService [] - ;; Service functions are implemented in a java `ServiceImpl` class + ;; Service functions are implemented in a java `ServiceImpl` class (msg-fn [this] (ServiceImpl/getMessage)) (meaning-of-life-fn [this] (ServiceImpl/getMeaningOfLife)))