Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
kawasima committed Sep 28, 2016
2 parents ef4ed73 + 855ab9e commit cf73261
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.7.1
16 changes: 10 additions & 6 deletions src/clj/job_streamer/control_bus/component/jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@
(let [since (.substring q (count "since:"))]
(when (b/valid? {:since since}
:since [[v/datetime (:date f/formatters)]])
{:since (f/parse (:date f/formatters) since)})))
{:since (some->> since (f/parse (:date f/formatters)) .toDate)})))

(defn- parse-query-until [q]
(let [until (.substring q (count "until:"))]
(let [until (.substring q (count "until:"))
parse-date-fn (partial f/parse (:date f/formatters))]
(when (b/valid? {:until until}
:until [[v/datetime (:date f/formatters)]])
{:until (f/parse (:date f/formatters) until)})))
{:until (some-> until
parse-date-fn
(.plusDays 1)
.toDate)})))

(defn- parse-query-exit-status [q]
(let [exit-status (.substring q (count "exit-status:"))]
Expand Down Expand Up @@ -125,17 +129,17 @@

(:until qmap)
(update-in [:where] conj
'[(<= ?end-time ?until-condition)])
'[(< ?end-time ?until-condition)])

(:exit-status qmap)
(update-in [:where] conj
'[(.contains ^String ?exit-status ?exit-status-condition)]))
app-name
(:job-name qmap [])
;if argument is nil or empty vector datomic occurs error
(or (not-empty (:job-name qmap)) [""])
(:since qmap "")
(:until qmap "")
(:exit-status qmap ""))]

{:results (->> jobs
(drop (dec (or offset 0)))
(take (or limit 20))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap data = context.getMergedJobDataMap();
String jobName = data.getString("job-name");
String host = data.getString("host");
int port = data.getInt("port");
long port = data.getLong("port");
String appName = data.getString("app-name");

URLConnection conn;
Expand Down
74 changes: 66 additions & 8 deletions test/clj/job_streamer/control_bus/component/jobs_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns job-streamer.control-bus.component.jobs-test
(:require (job-streamer.control-bus.component [jobs :as jobs]
[apps :as apps]
[datomic :refer [datomic-component]]
[datomic :refer [datomic-component] :as d]
[migration :refer [migration-component]])
(job-streamer.control-bus [system :as system]
[model :as model]
Expand All @@ -11,7 +11,8 @@
[clojure.test :refer :all]
[clojure.pprint :refer :all]
[clojure.edn :as edn]
[clj-time.format :as f]))
[clj-time.format :as f])
(:import [org.joda.time DateTime]))



Expand Down Expand Up @@ -45,6 +46,22 @@
:application/classpaths []})}]
(handler request)))

(defn setup-execution [{:keys [datomic] :as jobs}
{:keys [db/id job-execution/end-time job-execution/create-time]
:or {job-execution/end-time (java.util.Date.)
job-execution/create-time (java.util.Date.)}}]
(let [execution-id (d/tempid :db.part/user)]
(-> (d/transact
datomic
[{:db/id execution-id
:job-execution/batch-status :batch-status/undispatched
:job-execution/create-time create-time
:job-execution/end-time end-time
:job-execution/exit-status "COMPLETE"
:job-execution/job-parameters "{}"}
[:db/add id :job/executions execution-id]])
:tempids)))

(deftest find-all
(testing "find-all"
(let [system (new-system config)]
Expand Down Expand Up @@ -73,12 +90,57 @@
(let [res (jobs/find-all (:jobs system) "default" nil)]
(is (= 1 (:hits res)))))))

(deftest find-all-with-query
(let [system (new-system config)
handler (-> (jobs/list-resource (:jobs system) "default"))]
(create-app system)
;; setup data
(handler {:request-method :post
:content-type "application/edn"
:body (pr-str {:job/name "job1"})})
(handler {:request-method :post
:content-type "application/edn"
:body (pr-str {:job/name "job2"})})
(testing "Mathes exactly"
(let [res (jobs/find-all (:jobs system) "default" "job1")]
(is (= 1 (:hits res)))))

(testing "A query of multiple keywords"
(let [res (jobs/find-all (:jobs system) "default" "job1 job2")]
(is (= 2 (:hits res)))))

(testing "backward matching"
(let [res (jobs/find-all (:jobs system) "default" "b2")]
(is (= 1 (:hits res)))
(is (= "job2" (get-in res [:results 0 :job/name])))))

(let [job-id (get-in (jobs/find-all (:jobs system) "default" "job1") [:results 0 :db/id])
end-time (.toDate (f/parse (:date f/formatters) "2016-09-09"))]
(setup-execution (:jobs system)
{:db/id job-id :job-execution/end-time end-time})
(testing "since"
(let [res (jobs/find-all (:jobs system) "default" "since:2016-09-09")]
(pprint res)
(is (= 1 (:hits res)))
(is (= "job1" (get-in res [:results 0 :job/name])))))
(testing "until"
(let [res (jobs/find-all (:jobs system) "default" "until:2016-09-09")]
(is (= 1 (:hits res)))
(is (= "job1" (get-in res [:results 0 :job/name])))))
(testing "range"
(let [res (jobs/find-all (:jobs system) "default" "since:2016-09-09 until:2016-09-09")]
(is (= 1 (:hits res)))
(is (= "job1" (get-in res [:results 0 :job/name])))))


)))

(deftest parse-query
(testing "parse-query"
(let [result (jobs/parse-query "a b since:2016-09-01 until:2016-09-02 exit-status:COMPLETED")]
(is (= "a" (first (:job-name result))))
(is (= "2016-09-01" (f/unparse (:date f/formatters) (:since result))))
(is (= "2016-09-02" (f/unparse (:date f/formatters) (:until result))))
(is (= "2016-09-01" (some->> result :since (new DateTime) (f/unparse (:date f/formatters)))))
(is (= "2016-09-03" (some->> result :until (new DateTime) (f/unparse (:date f/formatters)))))
(is (= "COMPLETED" (:exit-status result)))))
(testing "nil query returns nil"
(let [result (jobs/parse-query nil)]
Expand All @@ -91,10 +153,6 @@
(let [result (jobs/parse-query "a")]
(is (= {:job-name '("a")} result))))

(testing "single simple query"
(let [result (jobs/parse-query "a")]
(is (= {:job-name '("a")} result))))

(testing "ignore breaking tokens in a query"
(let [result (jobs/parse-query "a since: until: since:xxx until:yyy")]
(is (= {:job-name '("a")} result)))))

0 comments on commit cf73261

Please sign in to comment.