Permalink
Browse files

First pass at unified backend integration specs, fixing some oversigh…

…ts in existing specs.
  • Loading branch information...
1 parent d5c3403 commit e085ef266de0aa48e88c27d0bee3ce3b8b3a979c @seancribbs seancribbs committed Mar 25, 2011
View
@@ -1 +1,2 @@
--color
+--fail-fast
@@ -14,6 +14,7 @@
require 'riak'
require 'tempfile'
require 'delegate'
+require 'riak/failed_request'
module Riak
# A client connection to Riak.
@@ -48,7 +48,7 @@ def perform(method, uri, headers, expect, data=nil) #:nodoc:
if return_body?(method, response.code, block_given?)
result[:body] = response.body
else
- raise HTTPFailedRequest.new(method, expect, response.code.to_i, response.to_hash, response.body)
+ raise Riak::HTTPFailedRequest.new(method, expect, response.code.to_i, response.to_hash, response.body)
end
end
end
@@ -25,15 +25,15 @@ class Pump
def initialize(block)
@fiber = Fiber.new do
loop do
- block.call *Fiber.yield
+ block.call Fiber.yield
end
end
@fiber.resume
end
- def pump(*input)
- @fiber.resume *input
- input.first.size if input.size == 1 # For curb
+ def pump(input)
+ @fiber.resume input
+ input.size if input.respond_to?(:size) # for curb
end
def to_proc
@@ -45,8 +45,7 @@ def accept(chunk)
# Returns a Proc that can be passed to an HTTP request method.
def to_proc
- parser = self
- Proc.new {|chunk| parser.accept(chunk) }
+ method(:accept).to_proc
end
private
@@ -0,0 +1,45 @@
+# Copyright 2010 Sean Cribbs 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__))
+
+describe "HTTP" do
+ before :all do
+ if $test_server
+ @web_port = 9000
+ $test_server.start
+ end
+ end
+
+ before do
+ @web_port ||= 8098
+ @client = Riak::Client.new(:port => @web_port)
+ end
+
+ after do
+ $test_server.recycle if $test_server.started?
+ end
+
+ [:CurbBackend, :ExconBackend, :NetHTTPBackend].each do |klass|
+ bklass = Riak::Client.const_get(klass)
+ if bklass.configured?
+ describe klass.to_s do
+ before do
+ @backend = bklass.new(@client)
+ end
+
+ it_should_behave_like "Unified backend API"
+ end
+ end
+ end
+end
@@ -120,15 +120,15 @@
end
it "should create a new blank object if the key does not exist" do
- @backend.should_receive(:fetch_object).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "File not found"))
+ @backend.should_receive(:fetch_object).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, "File not found"))
obj = @bucket.get_or_new('db')
obj.key.should == 'db'
obj.data.should be_blank
end
it "should bubble up non-ok non-missing errors" do
- @backend.should_receive(:fetch_object).and_raise(Riak::FailedRequest.new(:get, 200, 500, {}, "File not found"))
- lambda { @bucket.get_or_new('db') }.should raise_error(Riak::FailedRequest)
+ @backend.should_receive(:fetch_object).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 500, {}, "File not found"))
+ lambda { @bucket.get_or_new('db') }.should raise_error(Riak::HTTPFailedRequest)
end
it "should pass along the given R quorum parameter" do
@@ -192,7 +192,7 @@
end
it "should return false if the object doesn't exist" do
- @backend.should_receive(:fetch_object).and_raise(Riak::FailedRequest.new(:get, [200,300], 404, {}, "not found"))
+ @backend.should_receive(:fetch_object).and_raise(Riak::HTTPFailedRequest.new(:get, [200,300], 404, {}, "not found"))
@bucket.exists?("foo").should be_false
end
end
@@ -39,7 +39,7 @@
@backend.send(resource).should == @client.send(alternate)
end
it "should fallback to client.#{alternate} if request fails" do
- @backend.should_receive(:get).with(200, "/", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, ""))
+ @backend.should_receive(:get).with(200, "/", {}, {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, ""))
@backend.send(resource).should == @client.send(alternate)
end
end
@@ -57,7 +57,7 @@
@backend.send(resource).should == default
end
it "should fallback to #{default.inspect} if request fails" do
- @backend.should_receive(:get).with(200, "/", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, ""))
+ @backend.should_receive(:get).with(200, "/", {}, {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, ""))
@backend.send(resource).should == default
end
end
@@ -76,7 +76,7 @@
end
it "should raise an exception when the response code is not 200 or 304" do
- @backend.should_receive(:get).and_raise(Riak::FailedRequest.new(:get, 200, 500, {}, ''))
+ @backend.should_receive(:get).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 500, {}, ''))
lambda { @backend.reload_object(@object) }.should raise_error(Riak::FailedRequest)
end
@@ -250,7 +250,7 @@
end
it "should interpret failed requests with JSON content-types as map reduce errors" do
- @backend.stub!(:mapred).and_raise(Riak::FailedRequest.new(:post, 200, 500, {"content-type" => ["application/json"]}, '{"error":"syntax error"}'))
+ @backend.stub!(:mapred).and_raise(Riak::HTTPFailedRequest.new(:post, 200, 500, {"content-type" => ["application/json"]}, '{"error":"syntax error"}'))
lambda { @mr.run }.should raise_error(Riak::MapReduceError)
begin
@mr.run
@@ -262,7 +262,7 @@
end
it "should re-raise non-JSON error responses" do
- @backend.stub!(:mapred).and_raise(Riak::FailedRequest.new(:post, 200, 500, {"content-type" => ["text/plain"]}, 'Oops, you bwoke it.'))
+ @backend.stub!(:mapred).and_raise(Riak::HTTPFailedRequest.new(:post, 200, 500, {"content-type" => ["text/plain"]}, 'Oops, you bwoke it.'))
lambda { @mr.run }.should raise_error(Riak::FailedRequest)
end
end
@@ -374,7 +374,7 @@
end
it "should pass through a failed request exception" do
- @backend.should_receive(:delete_object).and_raise(Riak::FailedRequest.new(:delete, [204,404], 500, {}, ""))
+ @backend.should_receive(:delete_object).and_raise(Riak::HTTPFailedRequest.new(:delete, [204,404], 500, {}, ""))
lambda { @object.delete }.should raise_error(Riak::FailedRequest)
end
end
Oops, something went wrong.

0 comments on commit e085ef2

Please sign in to comment.