Update dependencies, adapt to new core.cache and Ragtime APIs

This commit is contained in:
Michael Klishin 2018-12-02 21:24:29 +03:00
parent ba00ba27a5
commit 386f06da8c
No known key found for this signature in database
GPG key ID: E80EDCFA0CDB21EE
4 changed files with 23 additions and 152 deletions

View file

@ -4,8 +4,8 @@
:min-lein-version "2.5.1"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[org.mongodb/mongodb-driver "3.8.0"]
:dependencies [[org.clojure/clojure "1.9.0"]
[org.mongodb/mongodb-driver "3.9.1"]
[clojurewerkz/support "1.1.0"]]
:test-selectors {:default (fn [m]
(and (not (:performance m))
@ -31,31 +31,28 @@
:mailing-list {:name "clojure-mongodb"
:archive "https://groups.google.com/group/clojure-mongodb"
:post "clojure-mongodb@googlegroups.com"}
:profiles {:dj02x {:dependencies [[org.clojure/data.json "0.2.6" :exclusions [org.clojure/clojure]]]}
:1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0-alpha13"]]}
:master {:dependencies [[org.clojure/clojure "1.9.0-master-SNAPSHOT"]]}
:profiles {:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:master {:dependencies [[org.clojure/clojure "1.10.0-master-SNAPSHOT"]]}
:dev {:resource-paths ["test/resources"]
:dependencies [[clj-time "0.8.0" :exclusions [org.clojure/clojure]]
[cheshire "5.5.0" :exclusions [org.clojure/clojure]]
[org.clojure/data.json "0.2.5" :exclusions [org.clojure/clojure]]
[org.clojure/tools.cli "0.3.1" :exclusions [org.clojure/clojure]]
[org.clojure/core.cache "0.6.3" :exclusions [org.clojure/clojure]]
[ring/ring-core "1.3.0" :exclusions [org.clojure/clojure]]
[com.novemberain/validateur "2.4.2" :exclusions [org.clojure/clojure]]
[ch.qos.logback/logback-classic "1.1.3" :exclusions [org.slf4j/slf4j-api]]
[ragtime/ragtime.core "0.3.7" :exclusions [org.clojure/clojure]]]
:plugins [[lein-codox "0.9.0"]]
:dependencies [[clj-time "0.15.1" :exclusions [org.clojure/clojure]]
[cheshire "5.8.1" :exclusions [org.clojure/clojure]]
[org.clojure/data.json "0.2.6" :exclusions [org.clojure/clojure]]
[org.clojure/tools.cli "0.4.1" :exclusions [org.clojure/clojure]]
[org.clojure/core.cache "0.7.1" :exclusions [org.clojure/clojure]]
[ring/ring-core "1.7.1" :exclusions [org.clojure/clojure]]
[com.novemberain/validateur "2.6.0" :exclusions [org.clojure/clojure]]
[ch.qos.logback/logback-classic "1.2.3" :exclusions [org.slf4j/slf4j-api]]
[ragtime/core "0.7.2" :exclusions [org.clojure/clojure]]]
:plugins [[lein-codox "0.10.5"]]
:codox {:source-paths ["src/clojure"]
:namespaces [#"^monger\.(?!internal)"]}}
;; only clj-time/JodaTime available, used to test monger.joda-time w/o clojure.data.json
:dev2 {:resource-paths ["test/resources"]
:dependencies [[clj-time "0.8.0" :exclusions [org.clojure/clojure]]]}}
:aliases {"all" ["with-profile" "dev:dev,1.6:dev,1.8:dev,dj02x"]}
:repositories {"sonatype" {:url "http://oss.sonatype.org/content/repositories/releases"
:dependencies [[clj-time "0.15.1" :exclusions [org.clojure/clojure]]]}}
:aliases {"all" ["with-profile" "dev:dev,1.8:dev,master"]}
:repositories {"sonatype" {:url "https://oss.sonatype.org/content/repositories/releases"
:snapshots false
:releases {:checksum :fail :update :always}}
"sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots"
"sonatype-snapshots" {:url "https://oss.sonatype.org/content/repositories/snapshots"
:snapshots true
:releases {:checksum :fail :update :always}}})

View file

@ -4,7 +4,7 @@
;; The APL v2.0:
;;
;; ----------------------------------------------------------------------------------
;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team
;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@
;; The EPL v1.0:
;;
;; ----------------------------------------------------------------------------------
;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team.
;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team.
;; All rights reserved.
;;
;; This program and the accompanying materials are made available under the terms of
@ -34,7 +34,7 @@
(ns monger.ragtime
"Ragtime integration"
(:refer-clojure :exclude [find sort])
(:require [ragtime.core :as ragtime]
(:require [ragtime.protocols :as proto]
[monger.core :as mg]
[monger.collection :as mc]
[monger.query :refer [with-collection find sort]])
@ -47,7 +47,7 @@
(extend-type com.mongodb.DB
ragtime/Migratable
proto/DataStore
(add-migration-id [db id]
(mc/insert db migrations-collection {:_id id :created_at (Date.)} WriteConcern/FSYNC_SAFE))
(remove-migration-id [db id]

View file

@ -1,126 +0,0 @@
(ns monger.test.cache-test
(:require [monger.core :as mg]
[monger.collection :as mc]
[clojure.core.cache :refer :all]
[clojure.test :refer :all]
[monger.cache :refer :all])
(:import [clojure.core.cache BasicCache FIFOCache LRUCache TTLCache]
java.util.UUID))
;;
;; Playground/Tests. These were necessary because clojure.core.cache has
;; little documentation, incomplete test suite and
;; slightly non-standard (although necessary to support all those cache variations)
;; cache operations protocol.
;;
;; This is by no means clear or complete either but it did the job of helping me
;; explore the API.
(deftest ^{:cache true}
test-has?-with-basic-cache
(testing "that has? returns false for misses"
(let [c (BasicCache. {})]
(are [v] (is (false? (has? c v)))
:missing-key
"missing-key"
(gensym "missing-key"))))
(testing "that has? returns true for hits"
(let [c (BasicCache. {:skey "Value" :lkey (Long/valueOf 10000) "kkey" :keyword})]
(are [v] (is (has? c v))
:skey
:lkey
"kkey"))))
(deftest ^{:cache true}
test-lookup-with-basic-cache
(testing "that lookup returns nil for misses"
(let [c (BasicCache. {})]
(are [v] (is (nil? (lookup c v)))
:missing-key
"missing-key"
(gensym "missing-key"))))
(testing "that lookup returns cached values for hits"
(let [l (Long/valueOf 10000)
c (BasicCache. {:skey "Value" :lkey l "kkey" :keyword})]
(are [v k] (is (= v (lookup c k)))
"Value" :skey
l :lkey
:keyword "kkey"))))
(deftest ^{:cache true}
test-evict-with-basic-cache
(testing "that evict has no effect for keys that do not exist"
(let [c (atom (BasicCache. {:a 1 :b 2}))]
(swap! c evict :missing-key)
(is (has? @c :a))
(is (has? @c :b))))
(testing "that evict removes keys that did exist"
(let [c (atom (BasicCache. {:skey "Value" "kkey" :keyword}))]
(is (has? @c :skey))
(is (= "Value" (lookup @c :skey)))
(swap! c evict :skey)
(is (not (has? @c :skey)))
(is (= nil (lookup @c :skey)))
(is (has? @c "kkey"))
(is (= :keyword (lookup @c "kkey"))))))
(deftest ^{:cache true}
test-seed-with-basic-cache
(testing "that seed returns a new value"
(let [c (atom (BasicCache. {}))]
(swap! c seed {:a 1 :b "b" "c" :d})
(are [k v] (do
(is (has? @c k))
(is (= v (lookup @c k))))
:a 1
:b "b"
"c" :d))))
;;
;; Tests
;;
(let [conn (mg/connect)
db (mg/get-db conn "monger-test")]
(use-fixtures :each (fn [f]
(mc/remove db "basic_monger_cache_entries")
(f)
(mc/remove db "basic_monger_cache_entries")))
(deftest ^{:cache true}
test-has?-with-basic-monger-cache
(testing "that has? returns false for misses"
(let [coll "basic_monger_cache_entries"
c (basic-monger-cache-factory db coll)]
(is (not (has? c (str (UUID/randomUUID)))))
(is (not (has? c (str (UUID/randomUUID)))))))
(testing "that has? returns true for hits"
(let [coll "basic_monger_cache_entries"
c (basic-monger-cache-factory db coll {"a" 1 "b" "cache" "c" 3/4})]
(is (has? c "a"))
(is (has? c "b"))
(is (has? c "c"))
(is (not (has? c "d"))))))
(deftest ^{:cache true}
test-lookup-with-basic-monger-cache
(testing "that lookup returns nil for misses"
(let [coll "basic_monger_cache_entries"
c (basic-monger-cache-factory db coll)]
(are [v] (is (nil? (lookup c v)))
:missing-key
"missing-key"
(gensym "missing-key"))))
(testing "that lookup returns cached values for hits"
(let [l (Long/valueOf 10000)
coll "basic_monger_cache_entries"
c (basic-monger-cache-factory db coll {:skey "Value" :lkey l "kkey" :keyword})]
(are [v k] (is (= v (lookup c k)))
"Value" :skey
l :lkey
"keyword" "kkey")))))

View file

@ -2,7 +2,7 @@
(:require [monger.core :as mg]
[monger.collection :as mc]
monger.ragtime
[ragtime.core :refer :all]
[ragtime.protocols :refer :all]
[clojure.test :refer :all]))