diff --git a/test/monger/test/stress.clj b/test/monger/test/stress.clj new file mode 100644 index 0000000..1d8d0e2 --- /dev/null +++ b/test/monger/test/stress.clj @@ -0,0 +1,39 @@ +(ns monger.test.stress + (:import [com.mongodb Mongo DB DBCollection WriteResult DBObject WriteConcern DBCursor] + [java.util Date]) + (:require [monger core]) + (:use [clojure.test])) + + +;; +;; Fixture functions +;; + +(defn purge-collection + [collection-name, f] + (monger.collection/remove collection-name) + (f) + (monger.collection/remove collection-name)) + +(defn purge-things-collection + [f] + (purge-collection "things" f)) + +(use-fixtures :each purge-things-collection) + + + +;; +;; Tests +;; + +(deftest insert-large-batches-of-documents-without-object-ids + (doseq [n [1000 10000 100000 1000000]] + (let [collection "things" + docs (map (fn [i] + (monger.conversion/to-db-object { :title "Untitled" :created-at (Date.) :number i })) + (take n (iterate inc 1)))] + (monger.collection/remove collection) + (println "Inserting " n " documents...") + (time (monger.collection/insert-batch collection docs)) + (is (= n (monger.collection/count collection))))))