spec/riak/bucket_spec.rb in riak-client-0.7.1 vs spec/riak/bucket_spec.rb in riak-client-0.8.0.beta
- old
+ new
@@ -19,11 +19,11 @@
@bucket = Riak::Bucket.new(@client, "foo")
end
def do_load(overrides={})
@bucket.load({
- :body => '{"props":{"name":"foo","allow_mult":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_util","fun":"chash_std_keyfun"},"linkfun":{"mod":"jiak_object","fun":"mapreduce_linkfun"},"n_val":3,"old_vclock":86400,"small_vclock":10,"young_vclock":20},"keys":["bar"]}',
+ :body => '{"props":{"name":"foo","n_val":3,"allow_mult":false,"last_write_wins":false,"precommit":[],"postcommit":[],"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"old_vclock":86400,"young_vclock":20,"big_vclock":50,"small_vclock":10,"r":"quorum","w":"quorum","dw":"quorum","rw":"quorum"},"keys":["bar"]}',
:headers => {
"vary" => ["Accept-Encoding"],
"server" => ["MochiWeb/1.1 WebMachine/1.5.1 (hack the charles gibson)"],
"link" => ['</riak/foo/bar>; riaktag="contained"'],
"date" => ["Tue, 12 Jan 2010 15:30:43 GMT"],
@@ -51,11 +51,11 @@
end
describe "when loading data from an HTTP response" do
it "should load the bucket properties from the response body" do
do_load
- @bucket.props.should == {"name"=>"foo","allow_mult" => false,"big_vclock" => 50,"chash_keyfun" => {"mod" =>"riak_util","fun"=>"chash_std_keyfun"},"linkfun"=>{"mod"=>"jiak_object","fun"=>"mapreduce_linkfun"},"n_val"=>3,"old_vclock"=>86400,"small_vclock"=>10,"young_vclock"=>20}
+ @bucket.props.should == {"name"=>"foo", "n_val"=>3, "allow_mult"=>false, "last_write_wins"=>false, "precommit"=>[], "postcommit"=>[], "chash_keyfun"=>{"mod"=>"riak_core_util", "fun"=>"chash_std_keyfun"}, "linkfun"=>{"mod"=>"riak_kv_wm_link_walker", "fun"=>"mapreduce_linkfun"}, "old_vclock"=>86400, "young_vclock"=>20, "big_vclock"=>50, "small_vclock"=>10, "r"=>"quorum", "w"=>"quorum", "dw"=>"quorum", "rw"=>"quorum"}
end
it "should load the keys from the response body" do
do_load
@bucket.keys.should == ["bar"]
@@ -78,16 +78,16 @@
@http = mock("HTTPBackend")
@client.stub!(:http).and_return(@http)
end
it "should load the keys if not present" do
- @http.should_receive(:get).with(200, "/riak/", "foo", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
+ @http.should_receive(:get).with(200, "/riak/", "foo", {:props => false, :keys => true}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
@bucket.keys.should == ["bar"]
end
it "should allow reloading of the keys" do
- @http.should_receive(:get).with(200, "/riak/","foo", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
+ @http.should_receive(:get).with(200, "/riak/","foo", {:props => false, :keys => true}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
do_load # Ensures they're already loaded
@bucket.keys(:reload => true).should == ["bar"]
end
it "should allow streaming keys through block" do
@@ -99,17 +99,17 @@
end
all_keys.should == ["bar", "baz"]
end
it "should unescape key names" do
- @http.should_receive(:get).with(200, "/riak/","foo", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar%20baz"]}'})
+ @http.should_receive(:get).with(200, "/riak/","foo", {:props => false, :keys => true}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar%20baz"]}'})
@bucket.keys.should == ["bar baz"]
end
it "should escape the bucket name" do
@bucket.instance_variable_set :@name, "unescaped "
- @http.should_receive(:get).with(200, "/riak/","unescaped%20", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
+ @http.should_receive(:get).with(200, "/riak/","unescaped%20", {:props => false, :keys => true}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
@bucket.keys.should == ["bar"]
end
end
describe "setting the bucket properties" do
@@ -225,9 +225,27 @@
it "should set the N value" do
@bucket.should_receive(:props=).with(hash_including('n_val' => 1))
@bucket.n_value = 1
end
end
+
+ [:r, :w, :dw, :rw].each do |q|
+ describe "get/set the default #{q} quorum" do
+ before :each do
+ do_load
+ end
+
+ it "should extract the default #{q} quorum" do
+ @bucket.send(q).should == "quorum"
+ end
+
+ it "should set the #{q} quorum" do
+ @bucket.should_receive(:props=).with(hash_including("#{q}" => 1))
+ @bucket.send("#{q}=",1)
+ end
+ end
+ end
+
describe "checking whether a key exists" do
it "should return true if the object does exist" do
@client.http.should_receive(:head).and_return(:code => 200)
@bucket.exists?("foo").should be_true