Cosmetics

This commit is contained in:
Michael S. Klishin 2012-06-08 22:03:43 +04:00
parent 74589346d0
commit 1c686c1766

View file

@ -3,13 +3,13 @@
org.bson.types.ObjectId
java.util.Date)
(:require [monger core util]
[monger.collection :as mgcol]
[monger.result :as mgres]
[monger.js :as js]
[monger.test.helper :as helper])
[monger.collection :as mc]
[monger.result :as mgres]
[clojurewerkz.support.js :as js]
[monger.test.helper :as helper])
(:use clojure.test
[monger operators conversion]
[monger.test.fixtures]))
monger.test.fixtures))
(helper/connect!)
@ -36,34 +36,34 @@
{ :state "IL" :quantity 3 :price 5.50 }]
expected [{:_id "CA", :value 204.9} {:_id "IL", :value 39.5} {:_id "NY", :value 697.0}]]
(deftest test-basic-inline-map-reduce-example
(mgcol/remove monger.core/*mongodb-database* collection {})
(is (mgres/ok? (mgcol/insert-batch collection batch)))
(let [output (mgcol/map-reduce collection mapper reducer nil MapReduceCommand$OutputType/INLINE {})
(mc/remove monger.core/*mongodb-database* collection {})
(is (mgres/ok? (mc/insert-batch collection batch)))
(let [output (mc/map-reduce collection mapper reducer nil MapReduceCommand$OutputType/INLINE {})
results (from-db-object ^DBObject (.results ^MapReduceOutput output) true)]
(mgres/ok? output)
(is (= expected results))))
(deftest test-basic-map-reduce-example-that-replaces-named-collection
(mgcol/remove monger.core/*mongodb-database* collection {})
(is (mgres/ok? (mgcol/insert-batch collection batch)))
(let [output (mgcol/map-reduce collection mapper reducer "mr_outputs" {})
(mc/remove monger.core/*mongodb-database* collection {})
(is (mgres/ok? (mc/insert-batch collection batch)))
(let [output (mc/map-reduce collection mapper reducer "mr_outputs" {})
results (from-db-object ^DBObject (.results ^MapReduceOutput output) true)]
(mgres/ok? output)
(is (= 3 (monger.core/count results)))
(is (= expected
(map #(from-db-object % true) (seq results))))
(is (= expected
(map #(from-db-object % true) (mgcol/find "mr_outputs"))))
(map #(from-db-object % true) (mc/find "mr_outputs"))))
(.drop ^MapReduceOutput output)))
(deftest test-basic-map-reduce-example-that-merged-results-into-named-collection
(mgcol/remove monger.core/*mongodb-database* collection {})
(is (mgres/ok? (mgcol/insert-batch collection batch)))
(mgcol/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})
(is (mgres/ok? (mgcol/insert collection { :state "OR" :price 17.95 :quantity 4 })))
(let [^MapReduceOutput output (mgcol/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})]
(mc/remove monger.core/*mongodb-database* collection {})
(is (mgres/ok? (mc/insert-batch collection batch)))
(mc/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})
(is (mgres/ok? (mc/insert collection { :state "OR" :price 17.95 :quantity 4 })))
(let [^MapReduceOutput output (mc/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})]
(mgres/ok? output)
(is (= 4 (monger.core/count output)))
(is (= ["CA" "IL" "NY" "OR"]
(map :_id (mgcol/find-maps "merged_mr_outputs"))))
(map :_id (mc/find-maps "merged_mr_outputs"))))
(.drop ^MapReduceOutput output))))