Skip to content

Commit

Permalink
Merge pull request #17 from va1en0k/allow_calculated_params_in_defjob
Browse files Browse the repository at this point in the history
Allow calculated params in defjob (relax args checking)
  • Loading branch information
alexott committed Aug 9, 2013
2 parents 159f357 + 7b1c6d6 commit 5b01723
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/clojure_hadoop/defjob.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
(assoc m k
(cond (keyword? v) (name v)
(number? v) (str v)
(string? v) v
(symbol? v) (full-name v)
(instance? Boolean v) (str v)
:else (throw (Exception. "defjob arguments must be strings, symbols, or keywords")))))
:else v)))
{} (apply hash-map opts))]
`(defn ~sym [] ~args)))
`(def ~sym (constantly ~args))))
2 changes: 1 addition & 1 deletion test/clojure_hadoop/examples/wordcount7.clj
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
:output-format :text
:compress-output false
:input "README.txt"
:output "tmp/out7"
:output (str "tmp/out" 7)
:replace true
:add-cache-file files-for-distributed-cache)

Expand Down
12 changes: 11 additions & 1 deletion test/clojure_hadoop/test/config.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(ns clojure-hadoop.test.config
(:use clojure.test clojure-hadoop.config clojure-hadoop.imports))
(:use clojure.test
clojure-hadoop.config
clojure-hadoop.imports
clojure-hadoop.defjob))

(import-conf)
(import-fs)
Expand Down Expand Up @@ -227,3 +230,10 @@
(deftest test-print-usage
(let [out (with-out-str (print-usage))]
(is (re-find #"Usage.*" out))))

(deftest test-defjob-creates-constant-configs
(defjob my-job
:timestamp (System/currentTimeMillis))
(let [job-conf (my-job)]
(Thread/sleep 20)
(is (= job-conf (my-job)))))

0 comments on commit 5b01723

Please sign in to comment.