Tests for TTL collections, improve aggregation framework tests
This commit is contained in:
parent
65240d1f14
commit
f374bc53ba
3 changed files with 43 additions and 21 deletions
|
|
@ -10,7 +10,8 @@
|
|||
[ragtime/ragtime.core "0.2.0"]]
|
||||
:test-selectors {:default (fn [m]
|
||||
(and (not (:performance m))
|
||||
(not (:edge-features m))))
|
||||
(not (:edge-features m))
|
||||
(not (:time-consuming m))))
|
||||
:focus :focus
|
||||
:updating :updating
|
||||
:indexing :indexing
|
||||
|
|
@ -20,7 +21,8 @@
|
|||
:command :command
|
||||
:performance :performance
|
||||
;; as in, edge mongodb server
|
||||
:edge-features :edge-features
|
||||
:edge-features :edge-features
|
||||
:time-consuming :time-consuming
|
||||
:all (constantly true)}
|
||||
:source-paths ["src/clojure"]
|
||||
:java-source-paths ["src/java"]
|
||||
|
|
|
|||
|
|
@ -18,15 +18,15 @@
|
|||
{ :state "IL" :quantity 2 :price 11.50 }
|
||||
{ :state "CA" :quantity 2 :price 2.95 }
|
||||
{ :state "IL" :quantity 3 :price 5.50 }]
|
||||
expected [{:quantity 1 :state "CA"}
|
||||
{:quantity 2 :state "NY"}
|
||||
{:quantity 1 :state "NY"}
|
||||
{:quantity 2 :state "IL"}
|
||||
{:quantity 2 :state "CA"}
|
||||
{:quantity 3 :state "IL"}]]
|
||||
expected #{{:quantity 1 :state "CA"}
|
||||
{:quantity 2 :state "NY"}
|
||||
{:quantity 1 :state "NY"}
|
||||
{:quantity 2 :state "IL"}
|
||||
{:quantity 2 :state "CA"}
|
||||
{:quantity 3 :state "IL"}}]
|
||||
(mc/insert-batch collection batch)
|
||||
(is (= 6 (mc/count collection)))
|
||||
(let [result (vec (map #(select-keys % [:state :quantity])
|
||||
(let [result (set (map #(select-keys % [:state :quantity])
|
||||
(mc/aggregate "docs" [{$project {:state 1 :quantity 1}}])))]
|
||||
(is (= expected result)))))
|
||||
|
||||
|
|
@ -39,14 +39,14 @@
|
|||
{ :state "IL" :quantity 2 :price 11.50 }
|
||||
{ :state "CA" :quantity 2 :price 2.95 }
|
||||
{ :state "IL" :quantity 3 :price 5.50 }]
|
||||
expected [{:_id "NY" :subtotal 398.0}
|
||||
{:_id "NY" :subtotal 299.0}
|
||||
{:_id "IL" :subtotal 23.0}
|
||||
{:_id "CA" :subtotal 5.9}
|
||||
{:_id "IL" :subtotal 16.5}
|
||||
{:_id "CA" :subtotal 199.0}]]
|
||||
expected #{{:_id "NY" :subtotal 398.0}
|
||||
{:_id "NY" :subtotal 299.0}
|
||||
{:_id "IL" :subtotal 23.0}
|
||||
{:_id "CA" :subtotal 5.9}
|
||||
{:_id "IL" :subtotal 16.5}
|
||||
{:_id "CA" :subtotal 199.0}}]
|
||||
(mc/insert-batch collection batch)
|
||||
(let [result (vec (mc/aggregate "docs" [{$project {:subtotal {$multiply ["$quantity", "$price"]}
|
||||
(let [result (set (mc/aggregate "docs" [{$project {:subtotal {$multiply ["$quantity", "$price"]}
|
||||
:_id "$state"}}]))]
|
||||
(is (= expected result)))))
|
||||
|
||||
|
|
@ -59,9 +59,9 @@
|
|||
{ :state "IL" :quantity 2 :price 11.50 }
|
||||
{ :state "CA" :quantity 2 :price 2.95 }
|
||||
{ :state "IL" :quantity 3 :price 5.50 }]
|
||||
expected [{:_id "CA", :total 204.9} {:_id "IL", :total 39.5} {:_id "NY", :total 697.0}]]
|
||||
expected #{{:_id "CA", :total 204.9} {:_id "IL", :total 39.5} {:_id "NY", :total 697.0}}]
|
||||
(mc/insert-batch collection batch)
|
||||
(let [result (vec (mc/aggregate "docs" [{$project {:subtotal {$multiply ["$quantity", "$price"]}
|
||||
(let [result (set (mc/aggregate "docs" [{$project {:subtotal {$multiply ["$quantity", "$price"]}
|
||||
:_id 1
|
||||
:state 1}}
|
||||
{$group {:_id "$state"
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@
|
|||
java.util.Date)
|
||||
(:require [monger core util]
|
||||
[monger.collection :as mc]
|
||||
[monger.test.helper :as helper])
|
||||
[monger.test.helper :as helper]
|
||||
monger.joda-time)
|
||||
(:use clojure.test
|
||||
[monger operators conversion]
|
||||
monger.test.fixtures))
|
||||
monger.test.fixtures
|
||||
[clj-time.core :only [now secs ago from-now]]))
|
||||
|
||||
(helper/connect!)
|
||||
|
||||
|
|
@ -31,3 +32,22 @@
|
|||
(mc/ensure-index collection { "language" 1 })
|
||||
(mc/ensure-index collection { "language" 1 } { :unique true })
|
||||
(mc/drop-indexes collection)))
|
||||
|
||||
(deftest ^{:indexing true :edge-features true :time-consuming true} test-ttl-collections
|
||||
(let [coll "recent_events"
|
||||
ttl 30
|
||||
sleep 120]
|
||||
(mc/remove coll)
|
||||
(mc/ensure-index coll {:created-at 1} {:expireAfterSeconds ttl})
|
||||
(dotimes [i 100]
|
||||
(mc/insert coll {:type "signup" :created-at (-> i secs ago) :i i}))
|
||||
(dotimes [i 100]
|
||||
(mc/insert coll {:type "signup" :created-at (-> i secs from-now) :i i}))
|
||||
(is (= 200 (mc/count coll {:type "signup"})))
|
||||
;; sleep for 65 seconds. MongoDB 2.1.2 seems to run TTLMonitor once per minute, according to
|
||||
;; the log. MK.
|
||||
(println (format "Now sleeping for %d seconds to test TTL collections!" sleep))
|
||||
(Thread/sleep (* sleep 1000))
|
||||
(println (format "Documents in the TTL collection: %d" (mc/count coll {:type "signup"})))
|
||||
(is (< (mc/count coll {:type "signup"}) 100))
|
||||
(mc/remove coll)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue