spec/riak/bucket_spec.rb in riak-client-0.9.8 vs spec/riak/bucket_spec.rb in riak-client-1.0.0.beta
- old
+ new
@@ -1,19 +1,6 @@
-# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-require File.expand_path("../spec_helper", File.dirname(__FILE__))
+require 'spec_helper'
describe Riak::Bucket do
before :each do
@client = Riak::Client.new
@backend = mock("Backend")
@@ -36,40 +23,36 @@
bucket.name.should == "foo"
end
end
describe "accessing keys" do
- it "should load the keys if not present" do
+ it "should list the keys" do
@backend.should_receive(:list_keys).with(@bucket).and_return(["bar"])
@bucket.keys.should == ["bar"]
end
- it "should allow reloading of the keys" do
- @backend.should_receive(:list_keys).with(@bucket).and_return(["bar"])
- @bucket.instance_variable_set(:@keys, ["foo"])
- @bucket.keys(:reload => true).should == ["bar"]
- end
-
it "should allow streaming keys through block" do
@backend.should_receive(:list_keys).with(@bucket).and_yield([]).and_yield(["bar"]).and_yield(["baz"])
all_keys = []
@bucket.keys do |list|
all_keys.concat(list)
end
all_keys.should == ["bar", "baz"]
end
- it "should invalidate the key cache when streaming" do
- @backend.should_receive(:list_keys).once.and_return(['a'])
- @backend.should_receive(:list_keys).once.and_yield(['b'])
- @backend.should_receive(:list_keys).once.and_return(['c'])
- @bucket.keys.should == ['a']
- keys = []
- @bucket.keys {|kl| keys.concat(kl) }
- keys.should == ['b']
- @bucket.keys.should == ['c']
+ it "should not cache the list of keys" do
+ @backend.should_receive(:list_keys).with(@bucket).twice.and_return(["bar"])
+ 2.times { @bucket.keys.should == ['bar'] }
end
+
+ it "should warn about the expense of list-keys when warnings are not disabled" do
+ Riak.disable_list_keys_warnings = false
+ @backend.stub!(:list_keys).and_return(%w{test test2})
+ @bucket.should_receive(:warn)
+ @bucket.keys
+ Riak.disable_list_keys_warnings = true
+ end
end
describe "setting the bucket properties" do
it "should prefetch the properties when they are not present" do
@backend.stub!(:set_bucket_props)
@@ -102,16 +85,16 @@
end
end
describe "fetching an object" do
it "should fetch the object via the backend" do
- @backend.should_receive(:fetch_object).with(@bucket, "db", nil).and_return(nil)
+ @backend.should_receive(:fetch_object).with(@bucket, "db", {}).and_return(nil)
@bucket.get("db")
end
it "should use the specified R quroum" do
- @backend.should_receive(:fetch_object).with(@bucket, "db", 2).and_return(nil)
+ @backend.should_receive(:fetch_object).with(@bucket, "db", {:r => 2}).and_return(nil)
@bucket.get("db", :r => 2)
end
end
describe "creating a new blank object" do
@@ -124,11 +107,11 @@
end
describe "fetching or creating a new object" do
it "should return the existing object if present" do
@object = mock("RObject")
- @backend.should_receive(:fetch_object).with(@bucket,"db", nil).and_return(@object)
+ @backend.should_receive(:fetch_object).with(@bucket,"db", {}).and_return(@object)
@bucket.get_or_new('db').should == @object
end
it "should create a new blank object if the key does not exist" do
@backend.should_receive(:fetch_object).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, "File not found"))
@@ -142,15 +125,22 @@
lambda { @bucket.get_or_new('db') }.should raise_error(Riak::HTTPFailedRequest)
end
it "should pass along the given R quorum parameter" do
@object = mock("RObject")
- @backend.should_receive(:fetch_object).with(@bucket,"db", "all").and_return(@object)
+ @backend.should_receive(:fetch_object).with(@bucket,"db", {:r => "all"}).and_return(@object)
@bucket.get_or_new('db', :r => "all").should == @object
end
end
+ describe "querying an index" do
+ it "should list the matching keys" do
+ @backend.should_receive(:get_index).with(@bucket, "test_bin", "testing").and_return(["bar"])
+ @bucket.get_index("test_bin", "testing").should == ["bar"]
+ end
+ end
+
describe "get/set allow_mult property" do
before :each do
@backend.stub!(:get_bucket_props).and_return({"allow_mult" => false})
end
@@ -208,15 +198,15 @@
end
end
describe "deleting an object" do
it "should delete a key from within the bucket" do
- @backend.should_receive(:delete_object).with(@bucket, "bar", nil)
+ @backend.should_receive(:delete_object).with(@bucket, "bar", {})
@bucket.delete('bar')
end
it "should use the specified RW quorum" do
- @backend.should_receive(:delete_object).with(@bucket, "bar", "all")
+ @backend.should_receive(:delete_object).with(@bucket, "bar", {:rw => "all"})
@bucket.delete('bar', :rw => "all")
end
end
end