Stress test now passes
This commit is contained in:
parent
eddc8b20bd
commit
c75b02814d
1 changed files with 28 additions and 35 deletions
|
|
@ -1,20 +1,19 @@
|
||||||
(ns monger.test.stress-test
|
(ns monger.test.stress-test
|
||||||
(:import [com.mongodb Mongo DB DBCollection WriteResult DBObject WriteConcern DBCursor]
|
(:require [monger.core :as mg]
|
||||||
java.util.Date)
|
[monger.collection :as mc]
|
||||||
(:require monger.core
|
[monger.conversion :refer [to-db-object]]
|
||||||
[monger.test.helper :as helper]
|
[clojure.test :refer :all])
|
||||||
[clojure.test :refer :all]))
|
(:import [com.mongodb WriteConcern]
|
||||||
|
java.util.Date))
|
||||||
|
|
||||||
|
|
||||||
;;
|
(let [conn (mg/connect)
|
||||||
;; Fixture functions
|
db (mg/get-db conn "monger-test")]
|
||||||
;;
|
|
||||||
|
|
||||||
(defn purge-collection
|
(defn purge-collection
|
||||||
[collection-name, f]
|
[coll f]
|
||||||
(monger.collection/remove collection-name)
|
(mc/remove db coll)
|
||||||
(f)
|
(f)
|
||||||
(monger.collection/remove collection-name))
|
(mc/remove db coll))
|
||||||
|
|
||||||
(defn purge-things-collection
|
(defn purge-things-collection
|
||||||
[f]
|
[f]
|
||||||
|
|
@ -22,21 +21,15 @@
|
||||||
|
|
||||||
(use-fixtures :each purge-things-collection)
|
(use-fixtures :each purge-things-collection)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;; Tests
|
|
||||||
;;
|
|
||||||
|
|
||||||
(monger.core/set-default-write-concern! WriteConcern/NORMAL)
|
(monger.core/set-default-write-concern! WriteConcern/NORMAL)
|
||||||
|
|
||||||
(deftest ^{:performance true} insert-large-batches-of-documents-without-object-ids
|
(deftest ^{:performance true} insert-large-batches-of-documents-without-object-ids
|
||||||
(doseq [n [1000 10000 100000]]
|
(doseq [n [1000 10000 100000]]
|
||||||
(let [collection "things"
|
(let [collection "things"
|
||||||
docs (map (fn [i]
|
docs (map (fn [i]
|
||||||
(monger.conversion/to-db-object { :title "Untitled" :created-at (Date.) :number i }))
|
(to-db-object { :title "Untitled" :created-at (Date.) :number i }))
|
||||||
(take n (iterate inc 1)))]
|
(take n (iterate inc 1)))]
|
||||||
(monger.collection/remove collection)
|
(mc/remove db collection)
|
||||||
(println "Inserting " n " documents...")
|
(println "Inserting " n " documents...")
|
||||||
(time (monger.collection/insert-batch collection docs))
|
(time (mc/insert-batch db collection docs))
|
||||||
(is (= n (monger.collection/count collection))))))
|
(is (= n (mc/count db collection)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue