spec/riak/map_reduce_spec.rb in riak-client-0.9.8 vs spec/riak/map_reduce_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::MapReduce do
before :each do
@client = Riak::Client.new
@backend = mock("Backend")
@@ -47,63 +34,34 @@
it "should add bucket/key pairs to the inputs" do
@mr.add("foo","bar")
@mr.inputs.should == [["foo","bar"]]
end
- it "should add bucket/key pairs to the inputs" do
- @mr.add("[foo]","(bar)")
- @mr.inputs.should == [["%5Bfoo%5D","%28bar%29"]]
- end
-
it "should add an array containing a bucket/key pair to the inputs" do
@mr.add(["foo","bar"])
@mr.inputs.should == [["foo","bar"]]
end
- it "should add an escaped array containing a bucket/key pair to the inputs" do
- @mr.add(["[foo]","(bar)"])
- @mr.inputs.should == [["%5Bfoo%5D","%28bar%29"]]
- end
-
it "should add an object to the inputs by its bucket and key" do
bucket = Riak::Bucket.new(@client, "foo")
obj = Riak::RObject.new(bucket, "bar")
@mr.add(obj)
@mr.inputs.should == [["foo", "bar"]]
end
- it "should add an object to the inputs by its escaped bucket and key" do
- bucket = Riak::Bucket.new(@client, "[foo]")
- obj = Riak::RObject.new(bucket, "(bar)")
- @mr.add(obj)
- @mr.inputs.should == [["%5Bfoo%5D", "%28bar%29"]]
- end
-
it "should add an array containing a bucket/key/key-data triple to the inputs" do
@mr.add(["foo","bar",1000])
@mr.inputs.should == [["foo","bar",1000]]
end
- it "should add an escaped array containing a bucket/key/key-data triple to the inputs" do
- @mr.add(["[foo]","(bar)","[]()"])
- @mr.inputs.should == [["%5Bfoo%5D", "%28bar%29","[]()"]]
- end
-
it "should use a bucket name as the single input" do
@mr.add(Riak::Bucket.new(@client, "foo"))
@mr.inputs.should == "foo"
@mr.add("docs")
@mr.inputs.should == "docs"
end
- it "should use an escaped bucket name as the single input" do
- @mr.add(Riak::Bucket.new(@client, "[foo]"))
- @mr.inputs.should == "%5Bfoo%5D"
- @mr.add("docs")
- @mr.inputs.should == "docs"
- end
-
it "should accept a list of key-filters along with a bucket" do
@mr.add("foo", [[:tokenize, "-", 3], [:string_to_int], [:between, 2009, 2010]])
@mr.inputs.should == {:bucket => "foo", :key_filters => [[:tokenize, "-", 3], [:string_to_int], [:between, 2009, 2010]]}
end
@@ -112,9 +70,149 @@
tokenize "-", 3
string_to_int
between 2009, 2010
end
@mr.inputs.should == {:bucket => "foo", :key_filters => [[:tokenize, "-", 3], [:string_to_int], [:between, 2009, 2010]]}
+ end
+
+ context "using secondary indexes as inputs" do
+ it "should set the inputs for equality" do
+ @mr.index("foo", "email_bin", "sean@basho.com").should == @mr
+ @mr.inputs.should == {:bucket => "foo", :index => "email_bin", :key => "sean@basho.com"}
+ end
+
+ it "should set the inputs for a range" do
+ @mr.index("foo", "rank_int", 10..20).should == @mr
+ @mr.inputs.should == {:bucket => "foo", :index => "rank_int", :start => 10, :end => 20}
+ end
+
+ it "should raise an error when given an invalid query" do
+ expect { @mr.index("foo", "rank_int", 1.0348) }.to raise_error(ArgumentError)
+ expect { @mr.index("foo", "rank_int", Range.new(1.03, 1.05)) }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "escaping" do
+ before { @oldesc, Riak.escaper = Riak.escaper, CGI }
+ after { Riak.escaper = @oldesc }
+
+ context "when url_decoding is false" do
+ before { @urldecode, Riak.url_decoding = Riak.url_decoding, false }
+ after { Riak.url_decoding = @urldecode }
+
+ it "should add bucket/key pairs to the inputs with bucket and key escaped" do
+ @mr.add("[foo]","(bar)")
+ @mr.inputs.should == [["%5Bfoo%5D","%28bar%29"]]
+ end
+
+ it "should add an escaped array containing a bucket/key pair to the inputs" do
+ @mr.add(["[foo]","(bar)"])
+ @mr.inputs.should == [["%5Bfoo%5D","%28bar%29"]]
+ end
+
+ it "should add an object to the inputs by its escaped bucket and key" do
+ bucket = Riak::Bucket.new(@client, "[foo]")
+ obj = Riak::RObject.new(bucket, "(bar)")
+ @mr.add(obj)
+ @mr.inputs.should == [["%5Bfoo%5D", "%28bar%29"]]
+ end
+
+ it "should add an escaped array containing a bucket/key/key-data triple to the inputs" do
+ @mr.add(["[foo]","(bar)","[]()"])
+ @mr.inputs.should == [["%5Bfoo%5D", "%28bar%29","[]()"]]
+ end
+
+ it "should use an escaped bucket name as the single input" do
+ @mr.add(Riak::Bucket.new(@client, "[foo]"))
+ @mr.inputs.should == "%5Bfoo%5D"
+ @mr.add("docs")
+ @mr.inputs.should == "docs"
+ end
+ end
+
+ context "when url_decoding is true" do
+ before { @urldecode, Riak.url_decoding = Riak.url_decoding, true }
+ after { Riak.url_decoding = @urldecode }
+
+ it "should add bucket/key pairs to the inputs with bucket and key unescaped" do
+ @mr.add("[foo]","(bar)")
+ @mr.inputs.should == [["[foo]","(bar)"]]
+ end
+
+ it "should add an unescaped array containing a bucket/key pair to the inputs" do
+ @mr.add(["[foo]","(bar)"])
+ @mr.inputs.should == [["[foo]","(bar)"]]
+ end
+
+ it "should add an object to the inputs by its unescaped bucket and key" do
+ bucket = Riak::Bucket.new(@client, "[foo]")
+ obj = Riak::RObject.new(bucket, "(bar)")
+ @mr.add(obj)
+ @mr.inputs.should == [["[foo]","(bar)"]]
+ end
+
+ it "should add an unescaped array containing a bucket/key/key-data triple to the inputs" do
+ @mr.add(["[foo]","(bar)","[]()"])
+ @mr.inputs.should == [["[foo]","(bar)","[]()"]]
+ end
+
+ it "should use an unescaped bucket name as the single input" do
+ @mr.add(Riak::Bucket.new(@client, "[foo]"))
+ @mr.inputs.should == "[foo]"
+ @mr.add("docs")
+ @mr.inputs.should == "docs"
+ end
+ end
+ end
+
+ context "escaping" do
+ before { @oldesc, Riak.escaper = Riak.escaper, CGI }
+ after { Riak.escaper = @oldesc }
+
+ it "should add bucket/key pairs to the inputs with bucket and key escaped" do
+ @mr.add("[foo]","(bar)")
+ @mr.inputs.should == [["%5Bfoo%5D","%28bar%29"]]
+ end
+
+ it "should add an escaped array containing a bucket/key pair to the inputs" do
+ @mr.add(["[foo]","(bar)"])
+ @mr.inputs.should == [["%5Bfoo%5D","%28bar%29"]]
+ end
+
+ it "should add an object to the inputs by its escaped bucket and key" do
+ bucket = Riak::Bucket.new(@client, "[foo]")
+ obj = Riak::RObject.new(bucket, "(bar)")
+ @mr.add(obj)
+ @mr.inputs.should == [["%5Bfoo%5D", "%28bar%29"]]
+ end
+
+ it "should add an escaped array containing a bucket/key/key-data triple to the inputs" do
+ @mr.add(["[foo]","(bar)","[]()"])
+ @mr.inputs.should == [["%5Bfoo%5D", "%28bar%29","[]()"]]
+ end
+
+ it "should use an escaped bucket name as the single input" do
+ @mr.add(Riak::Bucket.new(@client, "[foo]"))
+ @mr.inputs.should == "%5Bfoo%5D"
+ @mr.add("docs")
+ @mr.inputs.should == "docs"
+ end
+ end
+
+ context "when adding an input that will result in full-bucket mapreduce" do
+ before { Riak.disable_list_keys_warnings = false }
+ after { Riak.disable_list_keys_warnings = true }
+
+ it "should warn about list-keys on buckets" do
+ @mr.should_receive(:warn).twice
+ @mr.add("foo")
+ @mr.add(Riak::Bucket.new(@client, "foo"))
+ end
+
+ it "should warn about list-keys on key-filters" do
+ @mr.should_receive(:warn)
+ @mr.filter("foo") { matches "bar" }
+ end
end
end
[:map, :reduce].each do |type|
describe "adding #{type} phases" do