Permalink
Browse files

Straightening that buckets shit after writing a guide on them: fix a …

…bug, rename buckets/create => buckets/update

Writing doc guides is an epic win for project quality, including # of bugs and stupid API decisions
  • Loading branch information...
1 parent c3af04f commit 59b113394564f4fdc65317fd4df105feab110d19 @michaelklishin committed May 3, 2012
View
@@ -1,6 +1,9 @@
## Changes between Welle 1.0.0-alpha4 and 1.0.0-alpha5
-No changes yet.
+### clojurewerkz.welle.buckets/create is now clojurewerkz.welle.buckets/update
+
+`clojurewerkz.welle.buckets/update` better reflects what the function really does. However, `clojurewerkz.welle.buckets/create` may
+reflect the intent a bit better in certain cases so it is kept for backwards compatibility.
## Changes between Welle 1.0.0-alpha3 and 1.0.0-alpha4
@@ -15,8 +15,14 @@
;; API
;;
-(defn ^Bucket create
- "Creates a bucket"
+(defn fetch
+ "Fetches bucket properties"
+ [^String bucket-name]
+ (merge {:name bucket-name}
+ (from-bucket-properties (.fetchBucket *riak-client* bucket-name))))
+
+(defn update
+ "Updates bucket properties"
[^String bucket-name &{ :keys [allow-siblings last-write-wins n-val ^String backend
small-vclock big-vclock young-vclock old-vclock
r pr w dw pw rw
@@ -25,13 +31,20 @@
(merge {:name bucket-name}
(from-bucket-properties (.fetchBucket *riak-client* bucket-name))))
+(defn ^{:deprecated true} create
+ "The same as update. This name reveals the intent a bit better in some cases.
+ Kept for backwards compatibility, will be removed in the future"
+ [& args]
+ (apply update args))
+
(defn list
"Returns buckets in the cluster as a set"
[]
- (-> ^ListBucketsResponse (.listBuckets *riak-client*) .getBuckets))
+ (set (.listBuckets *riak-client*)))
(defn keys-in
- "Returns list of keys in the bucket. This is an expensive operation and typically should be avoided."
+ "Returns list of keys in the bucket. With any non-trivial number of keys, this is a VERY EXPENSIVE operation
+ and typically should be avoided"
[^String bucket-name]
(.listKeys *riak-client* bucket-name))
@@ -330,7 +330,7 @@
(throw (UnsupportedOperationException. (str "Deserializer for content type " content-type " is not defined"))))
-
+(def ^{:private true} not-nil? (comp not nil?))
(defn ^com.basho.riak.client.bucket.BucketProperties
to-bucket-properties
@@ -367,9 +367,9 @@
(.bigVClock big-vclock)
(.oldVClock old-vclock)
(.youngVClock young-vclock))]
- (when not-found-ok (.notFoundOK bldr not-found-ok))
- (when last-write-wins (.lastWriteWins bldr last-write-wins))
- (when basic-quorum (.basicQuorum bldr basic-quorum))
+ (when (not-nil? not-found-ok) (.notFoundOK bldr not-found-ok))
+ (when (not-nil? last-write-wins) (.lastWriteWins bldr last-write-wins))
+ (when (not-nil? basic-quorum) (.basicQuorum bldr basic-quorum))
(.build bldr)))
(defn from-bucket-properties
@@ -1,7 +1,8 @@
(ns clojurewerkz.welle.test.buckets-test
(:use clojure.test clojurewerkz.welle.conversion)
(:require [clojurewerkz.welle.core :as wc]
- [clojurewerkz.welle.buckets :as wb])
+ [clojurewerkz.welle.buckets :as wb]
+ [clojurewerkz.welle.kv :as kv])
(:import [com.basho.riak.client IRiakClient IRiakObject]
[com.basho.riak.client.bucket Bucket WriteBucket]
[com.basho.riak.client.operations StoreObject FetchObject]))
@@ -15,39 +16,66 @@
(is (contains? props prop))))
;;
-;; buckets/create
+;; buckets/update
;;
(deftest test-create-a-new-bucket-with-default-options
(let [bucket-name "clojurewerkz.welle.buckets/create-bucket-1"
- bucket-props (wb/create bucket-name)]
+ bucket-props (wb/update bucket-name)]
(has-bucket-props bucket-props)))
(deftest test-create-a-new-bucket-with-allow-siblings
(let [bucket-name "clojurewerkz.welle.buckets/create-bucket-2"
- bucket-props (wb/create bucket-name :allow-siblings true)]
+ bucket-props (wb/update bucket-name :allow-siblings true)]
(has-bucket-props bucket-props)
(is (:allow-siblings bucket-props))))
(deftest test-create-a-new-bucket-with-last-write-wins
(let [bucket-name "clojurewerkz.welle.buckets/create-bucket-3"
- bucket-props (wb/create bucket-name :last-write-wins true)]
+ bucket-props (wb/update bucket-name :last-write-wins true)]
(has-bucket-props bucket-props)
(is (:last-write-wins bucket-props))))
(deftest test-create-a-new-bucket-with-explicitly-set-n-val
(let [bucket-name "clojurewerkz.welle.buckets/create-bucket-4"
- bucket-props (wb/create bucket-name :n-val 4)]
+ bucket-props (wb/update bucket-name :n-val 4)]
(has-bucket-props bucket-props)
(is (= 4 (:n-val bucket-props)))))
(deftest test-create-a-new-bucket-with-explicitly-cap-values
(let [bucket-name "clojurewerkz.welle.buckets/create-bucket-5"
- bucket-props (wb/create bucket-name :r 1 :pr 2 :w 3 :dw 4 :pw 5 :rw 6)]
+ bucket-props (wb/update bucket-name :r 1 :pr 2 :w 3 :dw 4 :pw 5 :rw 6)]
(has-bucket-props bucket-props)
(are [k v] (is (= (to-quorum v) (k bucket-props)))
- :r 1 :pr 2 :w 3 :dw 4 :pw 5 :rw 6)))
+ :r 1 :pr 2 :w 3 :dw 4 :pw 5 :rw 6)))
+
+
+;;
+;; buckets/list
+;;
+
+(deftest test-listing-buckets
+ (wb/update "welle.test.a-bucket" :r 1)
+ ;; Riak does not seem to actually create a bucket until you store something in it. MK.
+ (kv/store "welle.test.a-bucket" "key" "value" :content-type "text/plain")
+ (let [buckets (wb/list)]
+ (is (set? buckets))
+ (is (buckets "welle.test.a-bucket"))))
+
+
+;;
+;; buckets/fetch, buckets/update
+;;
+
+(deftest test-fetching-bucket-properties
+ (let [bucket-name "welle.test.a-bucket"]
+ (wb/update bucket-name :r 1 :last-write-wins true)
+ (kv/store bucket-name "key" "value" :content-type "text/plain")
+ ;; stricter true/false assertions because of the way properties builder treats nils. MK.
+ (is (true? (:last-write-wins (wb/fetch bucket-name))))
+ (wb/update bucket-name :last-write-wins false)
+ (is (false? (:last-write-wins (wb/fetch bucket-name))))))
@@ -85,7 +85,7 @@
(def ^{:private true :const true} bucket-name "welle.test.cache_entries")
(use-fixtures :each (fn [f]
- (wb/create bucket-name :last-write-wins true :r 1 :w 1)
+ (wb/update bucket-name :last-write-wins true :r 1 :w 1)
(f)
(drain bucket-name)))
@@ -118,50 +118,90 @@
(is (= vclock (.getVClock ro))))))
(deftest test-to-bucket-properties
- (let [allow-siblings true
- last-write-wins true
- n-val 5
- backend "bitcask"
- big-vclock 10
- small-vclock 1
- old-vclock 3
- young-vclock 5
- not-found-ok true
- basic-quorum true
- r 1
- w 2
- pr 3
- dw 4
- rw 5
- pw 6
- enable-search false
- props (to-bucket-properties {:allow-siblings allow-siblings
- :last-write-wins last-write-wins
- :not-found-ok true
- :basic-quorum true
- :r r
- :w w
- :pr pr
- :dw dw
- :rw rw
- :pw pw
- :backend "bitcask"
- :big-vclock 10
- :small-vclock 1
- :old-vclock 3
- :young-vclock 5
- :enable-search enable-search})]
- (is (= (.getR props) (to-quorum 1)))
- (is (= (.getW props) (to-quorum 2)))
- (is (= (.getPR props) (to-quorum 3)))
- (is (= (.getDW props) (to-quorum 4)))
- (is (= (.getRW props) (to-quorum 5)))
- (is (= (.getPW props) (to-quorum 6)))
- (is (.getNotFoundOK props))
- (is (.getBasicQuorum props))
- (is (.getAllowSiblings props))
- (is (.getLastWriteWins props))
- (is (not (.getSearch props)))))
+ (testing "case 1"
+ (let [allow-siblings true
+ last-write-wins true
+ n-val 5
+ backend "bitcask"
+ big-vclock 10
+ small-vclock 1
+ old-vclock 3
+ young-vclock 5
+ not-found-ok true
+ basic-quorum true
+ r 1
+ w 2
+ pr 3
+ dw 4
+ rw 5
+ pw 6
+ enable-search false
+ props (to-bucket-properties {:allow-siblings allow-siblings
+ :last-write-wins last-write-wins
+ :not-found-ok true
+ :basic-quorum true
+ :r r
+ :w w
+ :pr pr
+ :dw dw
+ :rw rw
+ :pw pw
+ :backend "bitcask"
+ :big-vclock 10
+ :small-vclock 1
+ :old-vclock 3
+ :young-vclock 5
+ :enable-search enable-search})]
+ (is (= (.getR props) (to-quorum 1)))
+ (is (= (.getW props) (to-quorum 2)))
+ (is (= (.getPR props) (to-quorum 3)))
+ (is (= (.getDW props) (to-quorum 4)))
+ (is (= (.getRW props) (to-quorum 5)))
+ (is (= (.getPW props) (to-quorum 6)))
+ ;; we must use stricter true/false assertions here because of the way builder
+ ;; treats nils. MK.
+ (is (true? (.getNotFoundOK props)))
+ (is (true? (.getBasicQuorum props)))
+ (is (true? (.getAllowSiblings props)))
+ (is (true? (.getLastWriteWins props)))
+ (is (false? (.getSearch props)))))
+ (testing "case 2"
+ (let [allow-siblings false
+ last-write-wins false
+ n-val 5
+ backend "bitcask"
+ big-vclock 10
+ small-vclock 1
+ old-vclock 3
+ young-vclock 5
+ not-found-ok true
+ basic-quorum true
+ r 1
+ w 2
+ pr 3
+ dw 4
+ rw 5
+ pw 6
+ enable-search true
+ props (to-bucket-properties {:allow-siblings allow-siblings
+ :last-write-wins last-write-wins
+ :not-found-ok true
+ :basic-quorum true
+ :r r
+ :w w
+ :pr pr
+ :dw dw
+ :rw rw
+ :pw pw
+ :backend "bitcask"
+ :big-vclock 10
+ :small-vclock 1
+ :old-vclock 3
+ :young-vclock 5
+ :enable-search enable-search})]
+ (is (false? (.getAllowSiblings props)))
+ (is (false? (.getLastWriteWins props)))
+ (is (true? (.getSearch props))))))
(deftest test-to-vclock
(testing "with byte array inputs"
@@ -12,7 +12,7 @@
(deftest ^{:2i true} test-indexes-on-converted-riak-objects
(let [bucket-name "clojurewerkz.welle.test.indices-test"
- bucket (wb/create bucket-name)
+ bucket (wb/update bucket-name)
k (str (UUID/randomUUID))
v "value"
indexes {:email #{"john@example.com"}
@@ -26,7 +26,7 @@
(deftest ^{:2i true} test-basic-index-query-with-a-single-string-value
(let [bucket-name "clojurewerkz.welle.test.indices-test"
- bucket (wb/create bucket-name)
+ bucket (wb/update bucket-name)
k (str (UUID/randomUUID))
v (.getBytes "value")
indexes {:email #{"johndoe@example.com" "timsmith@example.com"}}
@@ -42,7 +42,7 @@
(deftest ^{:2i true} test-basic-index-query-with-a-range-of-string-values
(let [bucket-name "clojurewerkz.welle.test.indices-test"
- bucket (wb/create bucket-name)
+ bucket (wb/update bucket-name)
k1 (str (UUID/randomUUID))
k2 (str (UUID/randomUUID))
k3 (str (UUID/randomUUID))
@@ -60,7 +60,7 @@
(deftest ^{:2i true} test-basic-index-query-with-a-single-integer-value
(let [bucket-name "clojuyrewerkz.welle.test.indices-test"
- bucket (wb/create bucket-name)
+ bucket (wb/update bucket-name)
k (str (UUID/randomUUID))
v "value"
indexes {:age 27}
@@ -75,7 +75,7 @@
(deftest ^{:2i true} test-basic-index-query-with-a-range-of-integer-values
(let [bucket-name "clojurewerkz.welle.test.indices-test"
- bucket (wb/create bucket-name)
+ bucket (wb/update bucket-name)
k1 (str (UUID/randomUUID))
k2 (str (UUID/randomUUID))
k3 (str (UUID/randomUUID))
Oops, something went wrong.

0 comments on commit 59b1133

Please sign in to comment.