Skip to content
Browse files

Refactored tests.

  • Loading branch information...
1 parent c566ea7 commit 03264d89df83fc18685a756a0f5205ba44fe44f2 @otabat committed
View
1,723 test/couchbase_clj/test/client.clj
946 additions, 777 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
265 test/couchbase_clj/test/client_builder.clj
@@ -1,53 +1,54 @@
(ns couchbase-clj.test.client-builder
(:import [java.net URI]
- [net.spy.memcached FailureMode]
- [net.spy.memcached DefaultHashAlgorithm]
- [net.spy.memcached.auth AuthDescriptor]
- [net.spy.memcached.auth PlainCallbackHandler]
- [net.spy.memcached.transcoders LongTranscoder]
- [net.spy.memcached.transcoders SerializingTranscoder]
- [com.couchbase.client CouchbaseClient]
- [com.couchbase.client CouchbaseConnectionFactory]
- [com.couchbase.client CouchbaseConnectionFactoryBuilder]
- [couchbase_clj.client_builder.CouchbaseCljClientBuilder])
- (:require [couchbase-clj.client :as cbc]
- [couchbase-clj.client-builder :as cbb]
- [couchbase-clj.test.fixture :as tf])
- (:use [clojure.test]))
+ [net.spy.memcached FailureMode DefaultHashAlgorithm]
+ [net.spy.memcached.auth AuthDescriptor PlainCallbackHandler]
+ [net.spy.memcached.transcoders LongTranscoder SerializingTranscoder]
+ [com.couchbase.client
+ CouchbaseClient
+ CouchbaseConnectionFactory
+ CouchbaseConnectionFactoryBuilder])
+ (:use [clojure.test])
+ (:require [couchbase-clj.client :as cb-client]
+ [couchbase-clj.client-builder :as cb-client-builder]
+ [couchbase-clj.test.fixture :as tf]))
;(use-fixtures :once tf/setup-client tf/flush-data)
(use-fixtures :once tf/setup-client)
(deftest str->uri-test
(testing "Convert string to URI object."
- (is (instance? URI (cbb/str->uri "http://localhost/")))
+ (is (instance? URI (cb-client-builder/str->uri "http://localhost/")))
(is (instance? URI (URI. "http://127.0.0.1:8091/pools")))))
(deftest get-factory-builder-test
(testing "Get CouchbaseConnectionFactoryBuilder object."
- (let [cb (cbb/create-client-builder {:hash-alg :native-hash
- :failure-mode :redistribute})]
- (is (instance? CouchbaseConnectionFactoryBuilder (cbb/get-factory-builder cb))))))
+ (let [cb (cb-client-builder/create-client-builder
+ {:hash-alg :native-hash
+ :failure-mode :redistribute})]
+ (is (instance? CouchbaseConnectionFactoryBuilder
+ (cb-client-builder/get-factory-builder cb))))))
(deftest set-auth-descriptor-test
(testing "Set auth-descriptor option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :auth-descriptor (AuthDescriptor. (into-array [ "plain" ])
- (PlainCallbackHandler. "" ""))})]
+ (let [cf (cb-client-builder/build
+ {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :auth-descriptor (AuthDescriptor.
+ (into-array [ "plain" ])
+ (PlainCallbackHandler. "" ""))})]
(is (instance? AuthDescriptor (.getAuthDescriptor cf))))))
(deftest set-daemon-test
(testing "Set daemon option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :daemon true})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :daemon true})]
(is (= (.isDaemon cf) true)))))
(deftest set-failure-mode-test
@@ -56,10 +57,10 @@
:password tf/bucket-password
:uris (map #(URI. %) tf/uris)
:hash-alg :native-hash}
- cf1 (cbb/build (assoc m :failure-mode :redistribute))
- cf2 (cbb/build (assoc m :failure-mode :retry))
- cf3 (cbb/build (assoc m :failure-mode :cancel))
- cf4 (cbb/build (assoc m :failure-mode :else))]
+ cf1 (cb-client-builder/build (assoc m :failure-mode :redistribute))
+ cf2 (cb-client-builder/build (assoc m :failure-mode :retry))
+ cf3 (cb-client-builder/build (assoc m :failure-mode :cancel))
+ cf4 (cb-client-builder/build (assoc m :failure-mode :else))]
(is (= (.getFailureMode cf1) FailureMode/Redistribute))
(is (= (.getFailureMode cf2) FailureMode/Retry))
(is (= (.getFailureMode cf3) FailureMode/Cancel))
@@ -71,14 +72,14 @@
:password tf/bucket-password
:uris (map #(URI. %) tf/uris)
:failure-mode :redistribute}
- cf1 (cbb/build (assoc m :hash-alg :native-hash))
- cf2 (cbb/build (assoc m :hash-alg :ketama-hash))
- cf3 (cbb/build (assoc m :hash-alg :crc-hash))
- cf4 (cbb/build (assoc m :hash-alg :fnv1-64-hash))
- cf5 (cbb/build (assoc m :hash-alg :fnv1a-64-hash))
- cf6 (cbb/build (assoc m :hash-alg :fnv1-32-hash))
- cf7 (cbb/build (assoc m :hash-alg :fnv1a-32-hash))
- cf8 (cbb/build (assoc m :hash-alg :else))]
+ cf1 (cb-client-builder/build (assoc m :hash-alg :native-hash))
+ cf2 (cb-client-builder/build (assoc m :hash-alg :ketama-hash))
+ cf3 (cb-client-builder/build (assoc m :hash-alg :crc-hash))
+ cf4 (cb-client-builder/build (assoc m :hash-alg :fnv1-64-hash))
+ cf5 (cb-client-builder/build (assoc m :hash-alg :fnv1a-64-hash))
+ cf6 (cb-client-builder/build (assoc m :hash-alg :fnv1-32-hash))
+ cf7 (cb-client-builder/build (assoc m :hash-alg :fnv1a-32-hash))
+ cf8 (cb-client-builder/build (assoc m :hash-alg :else))]
(is (= (.getHashAlg cf1) DefaultHashAlgorithm/NATIVE_HASH))
(is (= (.getHashAlg cf2) DefaultHashAlgorithm/KETAMA_HASH))
(is (= (.getHashAlg cf3) DefaultHashAlgorithm/CRC_HASH))
@@ -90,23 +91,23 @@
(deftest set-max-reconnect-delay-test
(testing "Set max-reconnect-delay option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :max-reconnect-delay 500})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :max-reconnect-delay 500})]
(is (= (.getMaxReconnectDelay cf) 500)))))
;; TODO: Test failed, not working.
;(deftest set-min-reconnect-interval-test
; (testing "Set min-reconnect-interval option to a client."
-; (let [cf (cbb/build {:bucket tf/bucket
-; :password tf/bucket-password
-; :uris (map #(URI. %) tf/uris)
-; :hash-alg :native-hash
-; :failure-mode :redistribute
-; :min-reconnect-interval 2000})]
+; (let [cf (cb-client-builder/build {:bucket tf/bucket
+; :password tf/bucket-password
+; :uris (map #(URI. %) tf/uris)
+; :hash-alg :native-hash
+; :failure-mode :redistribute
+; :min-reconnect-interval 2000})]
; (is (= (.getMinReconnectInterval cf) 2000)))))
; APIs not provided?
@@ -115,112 +116,118 @@
(deftest set-op-queue-max-block-time-test
(testing "Set op-queue-max-block-time option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :op-queue-max-block-time 15000})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :op-queue-max-block-time 15000})]
(is (= (.getOpQueueMaxBlockTime cf) 15000)))))
(deftest set-op-timeout-test
(testing "Set op-timeout option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :op-timeout 10000})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :op-timeout 10000})]
(is (= (.getOperationTimeout cf) 10000)))))
(deftest set-read-buffer-size-test
(testing "Set read-buffer-size option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :read-buffer-size 10000})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :read-buffer-size 10000})]
(is (= (.getReadBufSize cf) 10000)))))
(deftest set-should-optimize-test
(testing "Set should-optimize option to a client."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :should-optimize false})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :should-optimize false})]
(is (= (.shouldOptimize cf) false)))))
(deftest set-timeout-exception-threshold-test
(testing "Set timeout-exception-threshold option to a client builder."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :timeout-exception-threshold 10000})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :timeout-exception-threshold 10000})]
(is (= (.getTimeoutExceptionThreshold cf) 9998)))))
(deftest set-transcoder-test
(testing "Set use-nagle-algorithm option to a client builder."
- (let [cl (cbc/create-client {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :transcoder (SerializingTranscoder.)})]
- (is (instance? SerializingTranscoder (.getTranscoder (cbc/get-client cl)))))))
+ (let [cl (cb-client/create-client {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :transcoder (SerializingTranscoder.)})]
+ (is (instance? SerializingTranscoder
+ (.getTranscoder (cb-client/get-client cl)))))))
(deftest set-use-nagle-algorithm-test
(testing "Set use-nagle-algorithm option to a client builder."
- (let [cf (cbb/build {:bucket tf/bucket
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :hash-alg :native-hash
- :failure-mode :redistribute
- :use-nagle-algorithm true})]
+ (let [cf (cb-client-builder/build {:bucket tf/bucket
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :hash-alg :native-hash
+ :failure-mode :redistribute
+ :use-nagle-algorithm true})]
(is (= (.useNagleAlgorithm cf) true)))))
(deftest create-client-builder-test
(testing "Creation of CouchbaseCljClientBuilder."
- (let [cb (cbb/create-client-builder {:hash-alg :native-hash
- :failure-mode :redistribute})]
- (is (instance? couchbase_clj.client_builder.CouchbaseCljClientBuilder cb)))))
+ (let [cb (cb-client-builder/create-client-builder
+ {:hash-alg :native-hash
+ :failure-mode :redistribute})]
+ (is (instance? couchbase_clj.client_builder.CouchbaseCljClientBuilder
+ cb)))))
(deftest create-factory-test
(testing "Creation of CouchbaseConnectionFactory"
- (let [fb (cbb/get-factory-builder (cbb/create-client-builder
- {:hash-alg :native-hash
- :failure-mode :redistribute}))
- cf (cbb/create-factory{:bucket tf/bucket
- :username tf/bucket-username
- :password tf/bucket-password
- :uris (map #(URI. %) tf/uris)
- :factory-builder fb})]
+ (let [fb (cb-client-builder/get-factory-builder
+ (cb-client-builder/create-client-builder
+ {:hash-alg :native-hash
+ :failure-mode :redistribute}))
+ cf (cb-client-builder/create-factory{:bucket tf/bucket
+ :username tf/bucket-username
+ :password tf/bucket-password
+ :uris (map #(URI. %) tf/uris)
+ :factory-builder fb})]
(is (instance? CouchbaseConnectionFactory cf)))))
(deftest build-test
(testing "Building of CouchbaseConnectionFactory with default value insertion."
- (let [cf (cbb/build {:bucket tf/bucket
- :username tf/bucket-username
- :password tf/bucket-password
- :uris tf/uris
- :auth-descriptor (AuthDescriptor. (into-array [ "plain" ])
- (PlainCallbackHandler. "" ""))
- :daemon true
- :failure-mode :retry
- :hash-alg :crc-hash
- :max-reconnect-delay 500
- ;:min-reconnect-interval 2000
- :obs-poll-interval 1000
- :obs-poll-max 30
- :op-queue-max-block-time 20000
- :op-timeout 20000
- :read-buffer-size 17000
- :should-optimize true
- :timeout-exception-threshold 33333
- :transcoder (SerializingTranscoder.)
- :use-nagle-algorithm true})]
+ (let [cf (cb-client-builder/build
+ {:bucket tf/bucket
+ :username tf/bucket-username
+ :password tf/bucket-password
+ :uris tf/uris
+ :auth-descriptor (AuthDescriptor.
+ (into-array [ "plain" ])
+ (PlainCallbackHandler. "" ""))
+ :daemon true
+ :failure-mode :retry
+ :hash-alg :crc-hash
+ :max-reconnect-delay 500
+ ;:min-reconnect-interval 2000
+ :obs-poll-interval 1000
+ :obs-poll-max 30
+ :op-queue-max-block-time 20000
+ :op-timeout 20000
+ :read-buffer-size 17000
+ :should-optimize true
+ :timeout-exception-threshold 33333
+ :transcoder (SerializingTranscoder.)
+ :use-nagle-algorithm true})]
(is (instance? CouchbaseConnectionFactory cf)))))
View
382 test/couchbase_clj/test/future.clj
@@ -1,334 +1,376 @@
(ns couchbase-clj.test.future
(:import [net.spy.memcached CASResponse]
- [net.spy.memcached.internal BulkGetFuture]
- [net.spy.memcached.internal GetFuture]
- [net.spy.memcached.internal OperationFuture]
- [net.spy.memcached.ops OperationStatus]
- [net.spy.memcached.ops CASOperationStatus]
+ [net.spy.memcached.internal BulkGetFuture GetFuture OperationFuture]
+ [net.spy.memcached.ops OperationStatus CASOperationStatus]
[com.couchbase.client.internal HttpFuture]
[com.couchbase.client.protocol.views View])
- (:require [couchbase-clj.client :as cbc]
- [couchbase-clj.future :as cbf]
- [couchbase-clj.test.fixture :as tf])
- (:use [clojure.test]))
+ (:use [clojure.test])
+ (:require [couchbase-clj.client :as cb-client]
+ [couchbase-clj.future :as cb-future]
+ [couchbase-clj.test.fixture :as tf]))
;(use-fixtures :once tf/setup-client tf/flush-data)
(use-fixtures :once tf/setup-client)
(deftest cas-response-test
(testing "Get the CASResponse converted to a Clojure keyword."
- (is (= (cbf/cas-response CASResponse/OK) :ok))
- (is (= (cbf/cas-response CASResponse/NOT_FOUND) :not-found))
- (is (= (cbf/cas-response CASResponse/EXISTS) :exists))
- (is (= (cbf/cas-response CASResponse/OBSERVE_ERROR_IN_ARGS) :observe-error-in-args))
- (is (= (cbf/cas-response CASResponse/OBSERVE_MODIFIED) :observe-modified))
- (is (= (cbf/cas-response CASResponse/OBSERVE_TIMEOUT) :observe-timeout))
- (is (= (cbf/cas-response :else) nil))))
+ (is (= (cb-future/cas-response CASResponse/OK) :ok))
+ (is (= (cb-future/cas-response CASResponse/NOT_FOUND) :not-found))
+ (is (= (cb-future/cas-response CASResponse/EXISTS) :exists))
+ (is (= (cb-future/cas-response CASResponse/OBSERVE_ERROR_IN_ARGS)
+ :observe-error-in-args))
+ (is (= (cb-future/cas-response CASResponse/OBSERVE_MODIFIED)
+ :observe-modified))
+ (is (= (cb-future/cas-response CASResponse/OBSERVE_TIMEOUT)
+ :observe-timeout))
+ (is (= (cb-future/cas-response :else) nil))))
(deftest bgf-deref-test
(testing "BulkGetFuture deref."
- (cbc/delete (tf/get-client) :bgf-deref1)
- (cbc/delete (tf/get-client) :bgf-deref2)
- (cbc/add (tf/get-client) :bgf-deref1 1)
- (cbc/add (tf/get-client) :bgf-deref2 2)
- (is (= @(cbc/async-get-multi (tf/get-client) [:bgf-deref1]) {"bgf-deref1" 1}))
- (is (= @(cbc/async-get-multi (tf/get-client) [:bgf-deref1 :bgf-deref2])
+ (cb-client/delete (tf/get-client) :bgf-deref1)
+ (cb-client/delete (tf/get-client) :bgf-deref2)
+ (cb-client/add (tf/get-client) :bgf-deref1 1)
+ (cb-client/add (tf/get-client) :bgf-deref2 2)
+ (is (= @(cb-client/async-get-multi (tf/get-client) [:bgf-deref1])
+ {"bgf-deref1" 1}))
+ (is (= @(cb-client/async-get-multi (tf/get-client) [:bgf-deref1 :bgf-deref2])
{"bgf-deref1" 1 "bgf-deref2" 2}))
- (is (= (deref (cbc/async-get-multi (tf/get-client) [:bgf-deref1]) 5000 :timeout)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client) [:bgf-deref1])
+ (deref 5000 :timeout))
{"bgf-deref1" 1}))
- (is (= (deref (cbc/async-get-multi (tf/get-client) [:bgf-deref1 :bgf-deref2]) 5000 :timeout)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-deref1 :bgf-deref2])
+ (deref 5000 :timeout))
{"bgf-deref1" 1 "bgf-deref2" 2}))))
(deftest bgf-realized?-test
(testing "BulkGetFuture realized?"
- (cbc/delete (tf/get-client) :bgf-realized)
- (cbc/add (tf/get-client) :bgf-realized 1)
- (let [fut (cbc/async-get-multi (tf/get-client) [:bgf-realized])]
+ (cb-client/delete (tf/get-client) :bgf-realized)
+ (cb-client/add (tf/get-client) :bgf-realized 1)
+ (let [fut (cb-client/async-get-multi (tf/get-client) [:bgf-realized])]
(is (true? (realized? (do @fut fut)))))))
(deftest bgf-get-future-test
(testing "BulkGetFuture get-future."
- (cbc/delete (tf/get-client) :bgf-get-future)
- (cbc/add (tf/get-client) :bgf-get-future 1)
- (let [fut (cbf/get-future (cbc/async-get-multi (tf/get-client) [:bgf-get-future]))]
+ (cb-client/delete (tf/get-client) :bgf-get-future)
+ (cb-client/add (tf/get-client) :bgf-get-future 1)
+ (let [fut (-> (cb-client/async-get-multi (tf/get-client) [:bgf-get-future])
+ cb-future/get-future)]
(is (instance? BulkGetFuture fut)))))
(deftest bgf-deref-json-test
(testing "BulkGetFuture deref-json."
- (cbc/delete (tf/get-client) :bgf-deref-json1)
- (cbc/delete (tf/get-client) :bgf-deref-json2)
- (cbc/add-json (tf/get-client) :bgf-deref-json1 {:a 1})
- (cbc/add-json (tf/get-client) :bgf-deref-json2 {:b 2})
- (is (= (cbf/deref-json (cbc/async-get-multi (tf/get-client) [:bgf-deref-json1]))
+ (cb-client/delete (tf/get-client) :bgf-deref-json1)
+ (cb-client/delete (tf/get-client) :bgf-deref-json2)
+ (cb-client/add-json (tf/get-client) :bgf-deref-json1 {:a 1})
+ (cb-client/add-json (tf/get-client) :bgf-deref-json2 {:b 2})
+ (is (= (-> (cb-client/async-get-multi (tf/get-client) [:bgf-deref-json1])
+ cb-future/deref-json)
{"bgf-deref-json1" {:a 1}}))
- (is (= (cbf/deref-json (cbc/async-get-multi (tf/get-client)
- [:bgf-deref-json1 :bgf-deref-json2]))
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-deref-json1 :bgf-deref-json2])
+ cb-future/deref-json)
{"bgf-deref-json1" {:a 1} "bgf-deref-json2" {:b 2}}))
- (is (= (cbf/deref-json (cbc/async-get-multi (tf/get-client)
- [:bgf-deref-json1]) 5000 :timeout)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-deref-json1])
+ (cb-future/deref-json 5000 :timeout))
{"bgf-deref-json1" {:a 1}}))
- (is (= (cbf/deref-json (cbc/async-get-multi
- (tf/get-client)
- [:bgf-deref-json1 :bgf-deref-json2]) 5000 :timeout)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-deref-json1 :bgf-deref-json2])
+ (cb-future/deref-json 5000 :timeout))
{"bgf-deref-json1" {:a 1} "bgf-deref-json2" {:b 2}}))))
(deftest bgf-future-get-test
(testing "BulkGetFuture future-get."
- (cbc/delete (tf/get-client) :bgf-future-get1)
- (cbc/delete (tf/get-client) :bgf-future-get2)
- (cbc/add (tf/get-client) :bgf-future-get1 1)
- (cbc/add (tf/get-client) :bgf-future-get2 2)
- (is (= (cbf/future-get (cbc/async-get-multi (tf/get-client) [:bgf-future-get1]))
+ (cb-client/delete (tf/get-client) :bgf-future-get1)
+ (cb-client/delete (tf/get-client) :bgf-future-get2)
+ (cb-client/add (tf/get-client) :bgf-future-get1 1)
+ (cb-client/add (tf/get-client) :bgf-future-get2 2)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client) [:bgf-future-get1])
+ cb-future/future-get)
{"bgf-future-get1" 1}))
- (is (= (cbf/future-get (cbc/async-get-multi (tf/get-client)
- [:bgf-future-get1 :bgf-future-get2]))
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-future-get1 :bgf-future-get2])
+ cb-future/future-get)
{"bgf-future-get1" 1 "bgf-future-get2" 2}))
- (is (= (cbf/future-get (cbc/async-get-multi (tf/get-client) [:bgf-future-get1]) 5000)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client) [:bgf-future-get1])
+ (cb-future/future-get 5000))
{"bgf-future-get1" 1}))
- (is (= (cbf/future-get (cbc/async-get-multi (tf/get-client)
- [:bgf-future-get1 :bgf-future-get2]) 5000)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-future-get1 :bgf-future-get2])
+ (cb-future/future-get 5000))
{"bgf-future-get1" 1 "bgf-future-get2" 2}))))
(deftest bgf-future-get-json-test
(testing "BulkGetFuture future-get-json."
- (cbc/delete (tf/get-client) :bgf-future-get-json1)
- (cbc/delete (tf/get-client) :bgf-future-get-json2)
- (cbc/add-json (tf/get-client) :bgf-future-get-json1 {:a 1})
- (cbc/add-json (tf/get-client) :bgf-future-get-json2 {:b 2})
- (is (= (cbf/future-get-json (cbc/async-get-multi (tf/get-client)
- [:bgf-future-get-json1]))
+ (cb-client/delete (tf/get-client) :bgf-future-get-json1)
+ (cb-client/delete (tf/get-client) :bgf-future-get-json2)
+ (cb-client/add-json (tf/get-client) :bgf-future-get-json1 {:a 1})
+ (cb-client/add-json (tf/get-client) :bgf-future-get-json2 {:b 2})
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-future-get-json1])
+ cb-future/future-get-json)
{"bgf-future-get-json1" {:a 1}}))
- (is (= (cbf/future-get-json (cbc/async-get-multi
- (tf/get-client)
- [:bgf-future-get-json1 :bgf-future-get-json2]))
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-future-get-json1
+ :bgf-future-get-json2])
+ cb-future/future-get-json)
{"bgf-future-get-json1" {:a 1} "bgf-future-get-json2" {:b 2}}))
- (is (= (cbf/future-get-json (cbc/async-get-multi (tf/get-client)
- [:bgf-future-get-json1]) 5000)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-future-get-json1])
+ (cb-future/future-get-json 5000))
{"bgf-future-get-json1" {:a 1}}))
- (is (= (cbf/future-get-json (cbc/async-get-multi
- (tf/get-client)
- [:bgf-future-get-json1 :bgf-future-get-json2]) 5000)
+ (is (= (-> (cb-client/async-get-multi (tf/get-client)
+ [:bgf-future-get-json1
+ :bgf-future-get-json2])
+ (cb-future/future-get-json 5000))
{"bgf-future-get-json1" {:a 1} "bgf-future-get-json2" {:b 2}}))))
(deftest bgf-future-status-test
(testing "BulkGetFuture future-status."
- (cbc/delete (tf/get-client) :bgf-future-status)
- (cbc/add (tf/get-client) :bgf-future-status 1)
- (let [st (cbf/future-status (cbc/async-get-multi (tf/get-client) [:bgf-future-status]))]
+ (cb-client/delete (tf/get-client) :bgf-future-status)
+ (cb-client/add (tf/get-client) :bgf-future-status 1)
+ (let [st (-> (cb-client/async-get-multi (tf/get-client) [:bgf-future-status])
+ (cb-future/future-status))]
(is (instance? CASOperationStatus st)))))
(deftest bgf-future-cancel-test
(testing "BulkGetFuture future-cancel."
- (cbc/delete (tf/get-client) :bgf-future-cancel)
- (cbc/add (tf/get-client) :bgf-future-cancel 1)
- (let [rs (cbf/future-cancel (cbc/async-get-multi (tf/get-client) [:bgf-future-cancel]))]
+ (cb-client/delete (tf/get-client) :bgf-future-cancel)
+ (cb-client/add (tf/get-client) :bgf-future-cancel 1)
+ (let [rs (-> (cb-client/async-get-multi (tf/get-client) [:bgf-future-cancel])
+ cb-future/future-cancel)]
(is (instance? Boolean rs)))))
(deftest bgf-future-cancelled?-test
(testing "BulkGetFuture future-cancelled?."
- (cbc/delete (tf/get-client) :bgf-future-cancelled)
- (cbc/add (tf/get-client) :bgf-future-cancelled 1)
- (let [fut (cbc/async-get-multi (tf/get-client) [:bgf-future-cancel])]
- (cbf/future-cancel fut)
- (is (true? (cbf/future-cancelled? fut))))))
+ (cb-client/delete (tf/get-client) :bgf-future-cancelled)
+ (cb-client/add (tf/get-client) :bgf-future-cancelled 1)
+ (let [fut (cb-client/async-get-multi (tf/get-client) [:bgf-future-cancel])]
+ (cb-future/future-cancel fut)
+ (is (true? (cb-future/future-cancelled? fut))))))
(deftest bgf-future-done?-test
(testing "BulkGetFuture future-done?."
- (cbc/delete (tf/get-client) :bgf-future-done)
- (cbc/add (tf/get-client) :bgf-future-done 1)
- (let [fut (cbc/async-get-multi (tf/get-client) [:bgf-future-done])]
+ (cb-client/delete (tf/get-client) :bgf-future-done)
+ (cb-client/add (tf/get-client) :bgf-future-done 1)
+ (let [fut (cb-client/async-get-multi (tf/get-client) [:bgf-future-done])]
@fut
- (is (true? (cbf/future-done? fut))))))
+ (is (true? (cb-future/future-done? fut))))))
(deftest gf-deref-test
(testing "GetFuture deref."
- (cbc/delete (tf/get-client) :gf-deref)
- (cbc/add (tf/get-client) :gf-deref 1)
- (is (= @(cbc/async-get (tf/get-client) :gf-deref) 1))
- (is (= (deref (cbc/async-get (tf/get-client) :gf-deref) 5000 :timeout) 1))))
+ (cb-client/delete (tf/get-client) :gf-deref)
+ (cb-client/add (tf/get-client) :gf-deref 1)
+ (is (= @(cb-client/async-get (tf/get-client) :gf-deref) 1))
+ (is (= (deref (cb-client/async-get (tf/get-client) :gf-deref) 5000 :timeout)
+ 1))))
(deftest gf-realized?-test
(testing "GetFuture realized?"
- (cbc/delete (tf/get-client) :gf-realized)
- (cbc/add (tf/get-client) :gf-realized 1)
- (let [fut (cbc/async-get (tf/get-client) :gf-realized)]
+ (cb-client/delete (tf/get-client) :gf-realized)
+ (cb-client/add (tf/get-client) :gf-realized 1)
+ (let [fut (cb-client/async-get (tf/get-client) :gf-realized)]
(is (true? (realized? (do @fut fut)))))))
(deftest gf-get-future-test
(testing "GetFuture get-future."
- (cbc/delete (tf/get-client) :gf-get-future)
- (cbc/add (tf/get-client) :gf-get-future 1)
- (let [fut (cbf/get-future (cbc/async-get (tf/get-client) :gf-get-future))]
+ (cb-client/delete (tf/get-client) :gf-get-future)
+ (cb-client/add (tf/get-client) :gf-get-future 1)
+ (let [fut (-> (cb-client/async-get (tf/get-client) :gf-get-future)
+ cb-future/get-future)]
(is (instance? GetFuture fut)))))
(deftest gf-deref-json-test
(testing "GetFuture deref-json."
- (cbc/delete (tf/get-client) :gf-deref-json)
- (cbc/add-json (tf/get-client) :gf-deref-json {:a 1})
- (is (= (cbf/deref-json (cbc/async-get (tf/get-client) :gf-deref-json))
+ (cb-client/delete (tf/get-client) :gf-deref-json)
+ (cb-client/add-json (tf/get-client) :gf-deref-json {:a 1})
+ (is (= (-> (cb-client/async-get (tf/get-client) :gf-deref-json)
+ cb-future/deref-json)
{:a 1}))
- (is (= (cbf/deref-json (cbc/async-get (tf/get-client) :gf-deref-json) 5000 :timeout)
+ (is (= (-> (cb-client/async-get (tf/get-client) :gf-deref-json)
+ (cb-future/deref-json 5000 :timeout))
{:a 1}))))
(deftest gf-future-get-test
(testing "GetFuture future-get."
- (cbc/delete (tf/get-client) :gf-future-get)
- (cbc/add (tf/get-client) :gf-future-get 1)
- (is (= (cbf/future-get (cbc/async-get (tf/get-client) :gf-future-get)) 1))
- (is (= (cbf/future-get (cbc/async-get (tf/get-client) :gf-future-get) 5000) 1))))
+ (cb-client/delete (tf/get-client) :gf-future-get)
+ (cb-client/add (tf/get-client) :gf-future-get 1)
+ (is (= (-> (cb-client/async-get (tf/get-client) :gf-future-get)
+ cb-future/future-get)
+ 1))
+ (is (= (-> (cb-client/async-get (tf/get-client) :gf-future-get)
+ (cb-future/future-get 5000))
+ 1))))
(deftest gf-future-get-json-test
(testing "GetFuture future-get-json."
- (cbc/delete (tf/get-client) :gf-future-get-json)
- (cbc/add-json (tf/get-client) :gf-future-get-json {:a 1})
- (is (= (cbf/future-get-json (cbc/async-get (tf/get-client) :gf-future-get-json))
+ (cb-client/delete (tf/get-client) :gf-future-get-json)
+ (cb-client/add-json (tf/get-client) :gf-future-get-json {:a 1})
+ (is (= (-> (cb-client/async-get (tf/get-client) :gf-future-get-json)
+ cb-future/future-get-json)
{:a 1}))
- (is (= (cbf/future-get-json (cbc/async-get (tf/get-client) :gf-future-get-json) 5000)
+ (is (= (-> (cb-client/async-get (tf/get-client) :gf-future-get-json)
+ (cb-future/future-get-json 5000))
{:a 1}))))
(deftest gf-future-status-test
(testing "GetFuture future-status."
- (cbc/delete (tf/get-client) :gf-future-status)
- (cbc/add (tf/get-client) :gf-future-status 1)
- (let [st (cbf/future-status (cbc/async-get (tf/get-client) :gf-future-status))]
+ (cb-client/delete (tf/get-client) :gf-future-status)
+ (cb-client/add (tf/get-client) :gf-future-status 1)
+ (let [st (-> (cb-client/async-get (tf/get-client) :gf-future-status)
+ cb-future/future-status)]
(is (instance? CASOperationStatus st)))))
(deftest gf-future-cancel-test
(testing "GetFuture future-cancel."
- (cbc/delete (tf/get-client) :gf-future-cancel)
- (cbc/add (tf/get-client) :gf-future-cancel 1)
- (let [rs (cbf/future-cancel (cbc/async-get (tf/get-client) :gf-future-cancel))]
+ (cb-client/delete (tf/get-client) :gf-future-cancel)
+ (cb-client/add (tf/get-client) :gf-future-cancel 1)
+ (let [rs (cb-future/future-cancel
+ (cb-client/async-get (tf/get-client) :gf-future-cancel))]
(is (instance? Boolean rs)))))
(deftest gf-future-cancelled?-test
(testing "GetFuture future-cancelled?."
- (cbc/delete (tf/get-client) :gf-future-cancelled)
- (cbc/add (tf/get-client) :gf-future-cancelled 1)
- (let [fut (cbc/async-get (tf/get-client) :gf-future-cancel)]
- (cbf/future-cancel fut)
- (is (true? (cbf/future-cancelled? fut))))))
+ (cb-client/delete (tf/get-client) :gf-future-cancelled)
+ (cb-client/add (tf/get-client) :gf-future-cancelled 1)
+ (let [fut (cb-client/async-get (tf/get-client) :gf-future-cancel)]
+ (cb-future/future-cancel fut)
+ (is (true? (cb-future/future-cancelled? fut))))))
(deftest gf-future-done?-test
(testing "GetFuture future-done?."
- (cbc/delete (tf/get-client) :gf-future-done)
- (cbc/add (tf/get-client) :gf-future-done 1)
- (let [fut (cbc/async-get (tf/get-client) :gf-future-done)]
+ (cb-client/delete (tf/get-client) :gf-future-done)
+ (cb-client/add (tf/get-client) :gf-future-done 1)
+ (let [fut (cb-client/async-get (tf/get-client) :gf-future-done)]
@fut
- (is (true? (cbf/future-done? fut))))))
+ (is (true? (cb-future/future-done? fut))))))
(deftest of-deref-test
(testing "OperationFuture deref."
- (cbc/delete (tf/get-client) :of-deref)
- (cbc/add (tf/get-client) :of-deref 1)
- (is (= (cbc/cas-val @(cbc/async-get-cas (tf/get-client) :of-deref)) 1))
- (is (= (-> (cbc/async-get-cas (tf/get-client) :of-deref)
- (deref 5000 :timeout)
- cbc/cas-val)
+ (cb-client/delete (tf/get-client) :of-deref)
+ (cb-client/add (tf/get-client) :of-deref 1)
+ (is (= (-> @(cb-client/async-get-cas (tf/get-client) :of-deref)
+ cb-client/cas-val)
+ 1))
+ (is (= (-> (cb-client/async-get-cas (tf/get-client) :of-deref)
+ (deref 5000 :timeout)
+ cb-client/cas-val)
1))))
(deftest of-realized?-test
(testing "OperationFuture realized?"
- (cbc/delete (tf/get-client) :of-realized)
- (cbc/add (tf/get-client) :of-realized 1)
- (let [fut (cbc/async-get-cas (tf/get-client) :of-realized)]
+ (cb-client/delete (tf/get-client) :of-realized)
+ (cb-client/add (tf/get-client) :of-realized 1)
+ (let [fut (cb-client/async-get-cas (tf/get-client) :of-realized)]
(is (true? (realized? (do @fut fut)))))))
(deftest of-get-future-test
(testing "OperationFuture get-future."
- (cbc/delete (tf/get-client) :of-get-future)
- (cbc/add (tf/get-client) :of-get-future 1)
- (let [fut (cbf/get-future (cbc/async-get-cas (tf/get-client) :of-get-future))]
+ (cb-client/delete (tf/get-client) :of-get-future)
+ (cb-client/add (tf/get-client) :of-get-future 1)
+ (let [fut (-> (cb-client/async-get-cas (tf/get-client) :of-get-future)
+ cb-future/get-future)]
(is (instance? OperationFuture fut)))))
(deftest of-future-get-test
(testing "OperationFuture future-get."
- (cbc/delete (tf/get-client) :of-future-get)
- (cbc/add (tf/get-client) :of-future-get 1)
- (is (= (-> (cbc/async-get-cas (tf/get-client) :of-future-get)
- cbf/future-get
- cbc/cas-val)
+ (cb-client/delete (tf/get-client) :of-future-get)
+ (cb-client/add (tf/get-client) :of-future-get 1)
+ (is (= (-> (cb-client/async-get-cas (tf/get-client) :of-future-get)
+ cb-future/future-get
+ cb-client/cas-val)
1))
- (is (= (-> (cbc/async-get-cas (tf/get-client) :of-future-get)
- (cbf/future-get 5000)
- cbc/cas-val)
+ (is (= (-> (cb-client/async-get-cas (tf/get-client) :of-future-get)
+ (cb-future/future-get 5000)
+ cb-client/cas-val)
1))))
(deftest of-future-status-test
(testing "OperationFuture future-status."
- (cbc/delete (tf/get-client) :of-future-status)
- (cbc/add (tf/get-client) :of-future-status 1)
- (let [st (cbf/future-status (cbc/async-get-cas (tf/get-client) :of-future-status))]
+ (cb-client/delete (tf/get-client) :of-future-status)
+ (cb-client/add (tf/get-client) :of-future-status 1)
+ (let [st (-> (cb-client/async-get-cas (tf/get-client) :of-future-status)
+ cb-future/future-status)]
(is (instance? CASOperationStatus st)))))
(deftest of-future-cancel-test
(testing "OperationFuture future-cancel."
- (cbc/delete (tf/get-client) :of-future-cancel)
- (cbc/add (tf/get-client) :of-future-cancel 1)
- (let [rs (cbf/future-cancel (cbc/async-get-cas (tf/get-client) :of-future-cancel))]
+ (cb-client/delete (tf/get-client) :of-future-cancel)
+ (cb-client/add (tf/get-client) :of-future-cancel 1)
+ (let [rs (-> (cb-client/async-get-cas (tf/get-client) :of-future-cancel)
+ cb-future/future-cancel)]
(is (instance? Boolean rs)))))
(deftest of-future-cancelled?-test
(testing "OperationFuture future-cancelled?."
- (cbc/delete (tf/get-client) :of-future-cancelled)
- (cbc/add (tf/get-client) :of-future-cancelled 1)
- (let [fut (cbc/async-get-cas (tf/get-client) :of-future-cancel)]
- (cbf/future-cancel fut)
- (is (true? (cbf/future-cancelled? fut))))))
+ (cb-client/delete (tf/get-client) :of-future-cancelled)
+ (cb-client/add (tf/get-client) :of-future-cancelled 1)
+ (let [fut (cb-client/async-get-cas (tf/get-client) :of-future-cancel)]
+ (cb-future/future-cancel fut)
+ (is (true? (cb-future/future-cancelled? fut))))))
(deftest of-future-done?-test
(testing "OperationFuture future-done?."
- (cbc/delete (tf/get-client) :of-future-done)
- (cbc/add (tf/get-client) :of-future-done 1)
- (let [fut (cbc/async-get (tf/get-client) :of-future-done)]
+ (cb-client/delete (tf/get-client) :of-future-done)
+ (cb-client/add (tf/get-client) :of-future-done 1)
+ (let [fut (cb-client/async-get (tf/get-client) :of-future-done)]
@fut
- (is (= (cbf/future-done? fut) true)))))
+ (is (= (cb-future/future-done? fut) true)))))
(deftest hf-deref-test
(testing "HttpFuture deref."
- (is (instance? View @(cbc/async-get-view (tf/get-client) tf/design-doc tf/view)))
- (is (-> (cbc/async-get-view (tf/get-client) tf/design-doc tf/view)
+ (is (->> @(cb-client/async-get-view (tf/get-client)
+ tf/design-doc tf/view)
+ (instance? View)))
+ (is (-> (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)
(deref 5000 :timeout)
(->> (instance? View))))))
(deftest hf-realized?-test
(testing "HttpFuture realized?"
- (let [fut (cbc/async-get-view (tf/get-client) tf/design-doc tf/view)]
+ (let [fut (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)]
(is (true? (realized? (do @fut fut)))))))
(deftest hf-get-future-test
(testing "HttpFuture get-future."
- (let [fut (cbf/get-future (cbc/async-get-view (tf/get-client) tf/design-doc tf/view))]
+ (let [fut (-> (cb-client/async-get-view (tf/get-client)
+ tf/design-doc
+ tf/view)
+ cb-future/get-future)]
(is (instance? HttpFuture fut)))))
(deftest hf-future-get-test
(testing "HttpFuture future-get."
- (cbc/delete (tf/get-client) :of-future-get)
- (cbc/add (tf/get-client) :of-future-get 1)
- (is (-> (cbc/async-get-view (tf/get-client) tf/design-doc tf/view)
- cbf/future-get
+ (cb-client/delete (tf/get-client) :of-future-get)
+ (cb-client/add (tf/get-client) :of-future-get 1)
+ (is (-> (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)
+ cb-future/future-get
(->> (instance? View))))
- (is (-> (cbc/async-get-view (tf/get-client) tf/design-doc tf/view)
- (cbf/future-get 5000)
+ (is (-> (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)
+ (cb-future/future-get 5000)
(->> (instance? View))))))
(deftest hf-future-status-test
(testing "HttpFuture future-status."
- (let [st (cbf/future-status (cbc/async-get-view (tf/get-client) tf/design-doc tf/view))]
+ (let [st (-> (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)
+ cb-future/future-status)]
(is (instance? OperationStatus st)))))
(deftest hf-future-cancel-test
(testing "HttpFuture future-cancel."
- (let [rs (cbf/future-cancel (cbc/async-get-view (tf/get-client) tf/design-doc tf/view))]
+ (let [rs (-> (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)
+ cb-future/future-cancel)]
(is (instance? Boolean rs)))))
(deftest hf-future-cancelled?-test
(testing "HttpFuture future-cancelled?."
- (let [fut (cbc/async-get-view (tf/get-client) tf/design-doc tf/view)]
- (cbf/future-cancel fut)
- (is (true? (cbf/future-cancelled? fut))))))
+ (let [fut (cb-client/async-get-view (tf/get-client) tf/design-doc tf/view)]
+ (cb-future/future-cancel fut)
+ (is (true? (cb-future/future-cancelled? fut))))))
(deftest hf-future-done?-test
(testing "HttpFuture future-done?."
- (let [fut (cbc/async-get (tf/get-client) tf/design-doc tf/view)]
+ (let [fut (cb-client/async-get (tf/get-client) tf/design-doc tf/view)]
@fut
- (is (true? (cbf/future-done? fut))))))
+ (is (true? (cb-future/future-done? fut))))))
View
293 test/couchbase_clj/test/query.clj
@@ -1,199 +1,198 @@
(ns couchbase-clj.test.query
- (:require [couchbase-clj.query :as cbq]
- [couchbase-clj.test.fixture :as tf])
- (:use [clojure.test]))
+ (:use [clojure.test])
+ (:require [couchbase-clj.query :as cb-query]))
;(deftest get-query-test)
(deftest reduce?-test
(testing "If a query will include documents."
- (let [q1 (cbq/create-query {:reduce true})
- q2 (cbq/create-query {:reduce false})]
- (is (true? (cbq/reduce? q1)))
- (is (false? (cbq/reduce? q2))))))
+ (let [q1 (cb-query/create-query {:reduce true})
+ q2 (cb-query/create-query {:reduce false})]
+ (is (true? (cb-query/reduce? q1)))
+ (is (false? (cb-query/reduce? q2))))))
(deftest include-docs?-test
(testing "If a query will include documents."
- (let [q1 (cbq/create-query {:include-docs true})
- q2 (cbq/create-query {:include-docs false})]
- (is (true? (cbq/include-docs? q1)))
- (is (false? (cbq/include-docs? q2))))))
+ (let [q1 (cb-query/create-query {:include-docs true})
+ q2 (cb-query/create-query {:include-docs false})]
+ (is (true? (cb-query/include-docs? q1)))
+ (is (false? (cb-query/include-docs? q2))))))
(deftest set-include-docs-test
(testing "Set include-docs option to a query."
- (let [q1 (cbq/create-query {:include-docs true})
- q2 (cbq/create-query {:include-docs false})]
- (is (true? (cbq/include-docs? q1)))
- (is (false? (cbq/include-docs? q2))))))
+ (let [q1 (cb-query/create-query {:include-docs true})
+ q2 (cb-query/create-query {:include-docs false})]
+ (is (true? (cb-query/include-docs? q1)))
+ (is (false? (cb-query/include-docs? q2))))))
(deftest set-desc-test
(testing "Set desc option to a query."
- (let [q1 (cbq/create-query {:desc true})
- q2 (cbq/create-query {:desc false})]
- (is (= (cbq/str q1) "?descending=true"))
- (is (= (cbq/str q2) "?descending=false")))))
+ (let [q1 (cb-query/create-query {:desc true})
+ q2 (cb-query/create-query {:desc false})]
+ (is (= (cb-query/str q1) "?descending=true"))
+ (is (= (cb-query/str q2) "?descending=false")))))
(deftest set-startkey-doc-id-test
(testing "Set startkey-doc-id option to a query."
- (let [q1 (cbq/create-query {:startkey-doc-id :doc1})
- q2 (cbq/create-query {:startkey-doc-id "doc2"})]
- (is (= (cbq/str q1) "?startkey_docid=doc1"))
- (is (= (cbq/str q2) "?startkey_docid=doc2")))))
+ (let [q1 (cb-query/create-query {:startkey-doc-id :doc1})
+ q2 (cb-query/create-query {:startkey-doc-id "doc2"})]
+ (is (= (cb-query/str q1) "?startkey_docid=doc1"))
+ (is (= (cb-query/str q2) "?startkey_docid=doc2")))))
(deftest set-endkey-doc-id-test
(testing "Set endkey-doc-id option to a query."
- (let [q1 (cbq/create-query {:endkey-doc-id :doc1})
- q2 (cbq/create-query {:endkey-doc-id "doc2"})]
- (is (= (cbq/str q1) "?endkey_docid=%22doc1%22"))
- (is (= (cbq/str q2) "?endkey_docid=%22doc2%22")))))
+ (let [q1 (cb-query/create-query {:endkey-doc-id :doc1})
+ q2 (cb-query/create-query {:endkey-doc-id "doc2"})]
+ (is (= (cb-query/str q1) "?endkey_docid=%22doc1%22"))
+ (is (= (cb-query/str q2) "?endkey_docid=%22doc2%22")))))
(deftest set-group-test
(testing "Set group option to a query."
- (let [q1 (cbq/create-query {:group true})
- q2 (cbq/create-query {:group false})]
- (is (= (cbq/str q1) "?group=true"))
- (is (= (cbq/str q2) "?group=false")))))
+ (let [q1 (cb-query/create-query {:group true})
+ q2 (cb-query/create-query {:group false})]
+ (is (= (cb-query/str q1) "?group=true"))
+ (is (= (cb-query/str q2) "?group=false")))))
(deftest set-group-level-test
(testing "Set group-level option to a query."
- (let [q1 (cbq/create-query {:group-level 1})]
- (is (= (cbq/str q1) "?group_level=1")))))
+ (let [q1 (cb-query/create-query {:group-level 1})]
+ (is (= (cb-query/str q1) "?group_level=1")))))
(deftest set-inclusive-end-test
(testing "Set inclusive-end option to a query"
- (let [q1 (cbq/create-query {:inclusive-end true})
- q2 (cbq/create-query {:inclusive-end false})]
- (is (= (cbq/str q1) "?inclusive_end=true"))
- (is (= (cbq/str q2) "?inclusive_end=false")))))
+ (let [q1 (cb-query/create-query {:inclusive-end true})
+ q2 (cb-query/create-query {:inclusive-end false})]
+ (is (= (cb-query/str q1) "?inclusive_end=true"))
+ (is (= (cb-query/str q2) "?inclusive_end=false")))))
(deftest set-key-test
(testing "Set key option to a query."
- (let [q1 (cbq/create-query {:key :key1})
- q2 (cbq/create-query {:key "key2"})
- q3 (cbq/create-query {:key 1})
- q4 (cbq/create-query {:key [1 2]})]
- (is (= (cbq/str q1) "?key=%22key1%22"))
- (is (= (cbq/str q2) "?key=%22key2%22"))
- (is (= (cbq/str q3) "?key=1"))
- (is (= (cbq/str q4) "?key=%5B1%2C2%5D")))))
+ (let [q1 (cb-query/create-query {:key :key1})
+ q2 (cb-query/create-query {:key "key2"})
+ q3 (cb-query/create-query {:key 1})
+ q4 (cb-query/create-query {:key [1 2]})]
+ (is (= (cb-query/str q1) "?key=%22key1%22"))
+ (is (= (cb-query/str q2) "?key=%22key2%22"))
+ (is (= (cb-query/str q3) "?key=1"))
+ (is (= (cb-query/str q4) "?key=%5B1%2C2%5D")))))
(deftest set-limit-test
(testing "Set limit option to a query."
- (let [q1 (cbq/create-query {:limit 100})]
- (is (= (cbq/str q1) "?limit=100")))))
+ (let [q1 (cb-query/create-query {:limit 100})]
+ (is (= (cb-query/str q1) "?limit=100")))))
(deftest set-range-test
(testing "Set range option to a query."
- (let [q1 (cbq/create-query {:range [:doc1 :doc2]})
- q2 (cbq/create-query {:range ["doc3" "doc4"]})
- q3 (cbq/create-query {:range [1 2]})
- q4 (cbq/create-query {:range [[1 2] [3 4]]})]
- (is (= (cbq/str q1) "?startkey=%22doc1%22&endkey=%22doc2%22"))
- (is (= (cbq/str q2) "?startkey=%22doc3%22&endkey=%22doc4%22"))
- (is (= (cbq/str q3) "?startkey=1&endkey=2"))
- (is (= (cbq/str q4) "?startkey=%5B1%2C2%5D&endkey=%5B3%2C4%5D")))))
+ (let [q1 (cb-query/create-query {:range [:doc1 :doc2]})
+ q2 (cb-query/create-query {:range ["doc3" "doc4"]})
+ q3 (cb-query/create-query {:range [1 2]})
+ q4 (cb-query/create-query {:range [[1 2] [3 4]]})]
+ (is (= (cb-query/str q1) "?startkey=%22doc1%22&endkey=%22doc2%22"))
+ (is (= (cb-query/str q2) "?startkey=%22doc3%22&endkey=%22doc4%22"))
+ (is (= (cb-query/str q3) "?startkey=1&endkey=2"))
+ (is (= (cb-query/str q4) "?startkey=%5B1%2C2%5D&endkey=%5B3%2C4%5D")))))
(deftest set-range-start-test
(testing "Set range-start option to a query."
- (let [q1 (cbq/create-query {:range-start :doc1})
- q2 (cbq/create-query {:range-start "doc2"})
- q3 (cbq/create-query {:range-start 1})
- q4 (cbq/create-query {:range-start [1 2]})]
- (is (= (cbq/str q1) "?startkey=%22doc1%22"))
- (is (= (cbq/str q2) "?startkey=%22doc2%22"))
- (is (= (cbq/str q3) "?startkey=1"))
- (is (= (cbq/str q4) "?startkey=%5B1%2C2%5D")))))
+ (let [q1 (cb-query/create-query {:range-start :doc1})
+ q2 (cb-query/create-query {:range-start "doc2"})
+ q3 (cb-query/create-query {:range-start 1})
+ q4 (cb-query/create-query {:range-start [1 2]})]
+ (is (= (cb-query/str q1) "?startkey=%22doc1%22"))
+ (is (= (cb-query/str q2) "?startkey=%22doc2%22"))
+ (is (= (cb-query/str q3) "?startkey=1"))
+ (is (= (cb-query/str q4) "?startkey=%5B1%2C2%5D")))))
(deftest set-range-end-test
(testing "Set range-end to a query."
- (let [q1 (cbq/create-query {:range-end :doc1})
- q2 (cbq/create-query {:range-end "doc2"})
- q3 (cbq/create-query {:range-end 2})
- q4 (cbq/create-query {:range-end [3 4]})]
- (is (= (cbq/str q1) "?endkey=%22doc1%22"))
- (is (= (cbq/str q2) "?endkey=%22doc2%22"))
- (is (= (cbq/str q3) "?endkey=2"))
- (is (= (cbq/str q4) "?endkey=%5B3%2C4%5D")))))
+ (let [q1 (cb-query/create-query {:range-end :doc1})
+ q2 (cb-query/create-query {:range-end "doc2"})
+ q3 (cb-query/create-query {:range-end 2})
+ q4 (cb-query/create-query {:range-end [3 4]})]
+ (is (= (cb-query/str q1) "?endkey=%22doc1%22"))
+ (is (= (cb-query/str q2) "?endkey=%22doc2%22"))
+ (is (= (cb-query/str q3) "?endkey=2"))
+ (is (= (cb-query/str q4) "?endkey=%5B3%2C4%5D")))))
(deftest set-reduce-test
(testing "Set reduce option to a query."
- (let [q1 (cbq/create-query {:reduce true})
- q2 (cbq/create-query {:reduce false})]
- (is (= (cbq/str q1) "?reduce=true"))
- (is (= (cbq/str q2) "?reduce=false")))))
+ (let [q1 (cb-query/create-query {:reduce true})
+ q2 (cb-query/create-query {:reduce false})]
+ (is (= (cb-query/str q1) "?reduce=true"))
+ (is (= (cb-query/str q2) "?reduce=false")))))
(deftest set-skip-test
(testing "Set skip option to a query."
- (let [q1 (cbq/create-query {:skip 1})
- q2 (cbq/create-query {:skip 100})]
- (is (= (cbq/str q1) "?skip=1"))
- (is (= (cbq/str q2) "?skip=100")))))
+ (let [q1 (cb-query/create-query {:skip 1})
+ q2 (cb-query/create-query {:skip 100})]
+ (is (= (cb-query/str q1) "?skip=1"))
+ (is (= (cb-query/str q2) "?skip=100")))))
(deftest set-stale-test
(testing "Set stale option to a query."
- (let [q1 (cbq/create-query {:stale :ok})
- q2 (cbq/create-query {:stale :false})
- q3 (cbq/create-query {:stale :update-after})
- q4 (cbq/create-query {:stale :true})
- q5 (cbq/create-query {:stale true})
- q6 (cbq/create-query {:stale false})
- q7 (cbq/create-query {:stale :else})]
- (is (= (cbq/str q1) "?stale=ok"))
- (is (= (cbq/str q2) "?stale=false"))
- (is (= (cbq/str q3) "?stale=update_after"))
- (is (= (cbq/str q4) "?stale=ok"))
- (is (= (cbq/str q5) "?stale=ok"))
- (is (= (cbq/str q6) "?stale=false"))
- (is (= (cbq/str q7) "?stale=update_after")))))
+ (let [q1 (cb-query/create-query {:stale :ok})
+ q2 (cb-query/create-query {:stale :false})
+ q3 (cb-query/create-query {:stale :update-after})
+ q4 (cb-query/create-query {:stale :true})
+ q5 (cb-query/create-query {:stale true})
+ q6 (cb-query/create-query {:stale false})
+ q7 (cb-query/create-query {:stale :else})]
+ (is (= (cb-query/str q1) "?stale=ok"))
+ (is (= (cb-query/str q2) "?stale=false"))
+ (is (= (cb-query/str q3) "?stale=update_after"))
+ (is (= (cb-query/str q4) "?stale=ok"))
+ (is (= (cb-query/str q5) "?stale=ok"))
+ (is (= (cb-query/str q6) "?stale=false"))
+ (is (= (cb-query/str q7) "?stale=update_after")))))
(deftest set-on-error-test
(testing "Set on-error option to a query."
- (let [q1 (cbq/create-query {:on-error :stop})
- q2 (cbq/create-query {:on-error :continue})
- q3 (cbq/create-query {:on-error :else})]
- (is (= (cbq/str q1) "?on_error=stop"))
- (is (= (cbq/str q2) "?on_error=continue"))
- (is (= (cbq/str q3) "?on_error=continue")))))
+ (let [q1 (cb-query/create-query {:on-error :stop})
+ q2 (cb-query/create-query {:on-error :continue})
+ q3 (cb-query/create-query {:on-error :else})]
+ (is (= (cb-query/str q1) "?on_error=stop"))
+ (is (= (cb-query/str q2) "?on_error=continue"))
+ (is (= (cb-query/str q3) "?on_error=continue")))))
(deftest assoc-test
(testing "Gettina an updated copy of the query."
- (let [q1 (cbq/create-query {:limit 1})
- q2 (cbq/assoc q1 {:limit 100
- :skip 10})]
- (is (= (cbq/str q2) "?limit=100&skip=10")))))
+ (let [q1 (cb-query/create-query {:limit 1})
+ q2 (cb-query/assoc q1 {:limit 100
+ :skip 10})]
+ (is (= (cb-query/str q2) "?limit=100&skip=10")))))
(deftest assoc!-test
(testing "Getting an updated query."
- (let [q1 (cbq/create-query {:limit 1})]
- (cbq/assoc! q1 {:limit 100
- :group-level 1})
- (is (= (cbq/str q1) "?limit=100&group_level=1")))))
+ (let [q1 (cb-query/create-query {:limit 1})]
+ (cb-query/assoc! q1 {:limit 100
+ :group-level 1})
+ (is (= (cb-query/str q1) "?limit=100&group_level=1")))))
(deftest str-tes
(testing "String conversion of a query."
- (let [q1 (cbq/create-query {:limit 1})]
- (is (= (cbq/str q1) "?limit=1")))))
+ (let [q1 (cb-query/create-query {:limit 1})]
+ (is (= (cb-query/str q1) "?limit=1")))))
(deftest create-query-test
(testing "Creation of a query."
- (let [q1 (cbq/create-query {:limit 1})
- q2 (cbq/create-query {:include-docs true
- :desc false
- :startkey-doc-id :doc1
- :endkey-doc-id :doc2
- :group false
- :group-level 1
- :inclusive-end false
- :key :key1
- :limit 100
- :range [:start-key :end-key]
- :range-start :start-key2
- :range-end :end-key2
- :reduce false
- :skip 1
- :stale false
- :on-error :continue})]
- (is (= (.toString (cbq/get-query q1)) "?limit=1"))
- (is (= (.toString (cbq/get-query q2))
+ (let [q1 (cb-query/create-query {:limit 1})
+ q2 (cb-query/create-query {:include-docs true
+ :desc false
+ :startkey-doc-id :doc1
+ :endkey-doc-id :doc2
+ :group false
+ :group-level 1
+ :inclusive-end false
+ :key :key1
+ :limit 100
+ :range [:start-key :end-key]
+ :range-start :start-key2
+ :range-end :end-key2
+ :reduce false
+ :skip 1
+ :stale false
+ :on-error :continue})]
+ (is (= (.toString (cb-query/get-query q1)) "?limit=1"))
+ (is (= (.toString (cb-query/get-query q2))
(str "?limit=100&endkey_docid=%22doc2%22&group_level=1"
"&startkey=%22start-key2%22&skip=1&descending=false"
"&reduce=false&inclusive_end=false&on_error=continue"
@@ -202,25 +201,25 @@
(deftest defquery
(testing "Creation of a query and binding to a Var."
- (cbq/defquery q1 {:limit 1})
- (cbq/defquery q2 {:include-docs true
- :desc false
- :startkey-doc-id :doc1
- :endkey-doc-id :doc2
- :group false
- :group-level 1
- :inclusive-end false
- :key :key1
- :limit 100
- :range [:start-key :end-key]
- :range-start :start-key2
- :range-end :end-key2
- :reduce false
- :skip 1
- :stale false
- :on-error :continue})
- (is (= (.toString (cbq/get-query q1)) "?limit=1"))
- (is (= (.toString (cbq/get-query q2))
+ (cb-query/defquery q1 {:limit 1})
+ (cb-query/defquery q2 {:include-docs true
+ :desc false
+ :startkey-doc-id :doc1
+ :endkey-doc-id :doc2
+ :group false
+ :group-level 1
+ :inclusive-end false
+ :key :key1
+ :limit 100
+ :range [:start-key :end-key]
+ :range-start :start-key2
+ :range-end :end-key2
+ :reduce false
+ :skip 1
+ :stale false
+ :on-error :continue})
+ (is (= (.toString (cb-query/get-query q1)) "?limit=1"))
+ (is (= (.toString (cb-query/get-query q2))
(str "?limit=100&endkey_docid=%22doc2%22&group_level=1"
"&startkey=%22start-key2%22&skip=1&descending=false"
"&reduce=false&inclusive_end=false&on_error=continue"
View
12 test/couchbase_clj/test/util.clj
@@ -1,17 +1,15 @@
(ns couchbase-clj.test.util
(:use [clojure.test])
(:require [clojure.data.json :as json]
- [couchbase-clj.util :as util]
- [couchbase-clj.client :as client]
- [couchbase-clj.test.fixture :as test-fixture]))
+ [couchbase-clj.util :as cb-util]))
(deftest read-json-test
(testing "convert json data to clojure data"
- (is (= {:a 1} (util/read-json (json/json-str {:a 1}))))
- (is (= [1 2 3] (util/read-json (json/json-str [1 2 3]))))
- (is (= nil (util/read-json nil)))))
+ (is (= {:a 1} (cb-util/read-json (json/json-str {:a 1}))))
+ (is (= [1 2 3] (cb-util/read-json (json/json-str [1 2 3]))))
+ (is (= nil (cb-util/read-json nil)))))
(deftest write-json-test
(testing "convert clojure data to json data"
- (is (= util/write-json json/json-str))))
+ (is (= cb-util/write-json json/json-str))))

0 comments on commit 03264d8

Please sign in to comment.
Something went wrong with that request. Please try again.