spec/riak/client_spec.rb in riak-client-2.0.0.rc1 vs spec/riak/client_spec.rb in riak-client-2.0.0.rc2

- old
+ new

@@ -1,6 +1,7 @@ require 'spec_helper' +require 'riak/errors/protobuffs_error' describe Riak::Client, test_client: true do describe "when initializing" do it "should default a single local node" do client = Riak::Client.new @@ -25,10 +26,20 @@ end it "should create a client ID if not specified" do expect(Riak::Client.new(pb_port: test_client.nodes.first.pb_port).client_id).not_to be_nil end + + it "should accept multiple nodes" do + client = Riak::Client.new :nodes => [ + {:host => 'riak1.basho.com'}, + {:host => 'riak2.basho.com', :pb_port => 1234}, + {:host => 'riak3.basho.com', :pb_port => 5678} + ] + expect(client.nodes.size).to eq(3) + expect(client.nodes.first.host).to eq("riak1.basho.com") + end end it "should expose a Stamp object" do expect(subject).to respond_to(:stamp) expect(subject.stamp).to be_kind_of(Riak::Stamp) @@ -171,6 +182,40 @@ buckets = @client.buckets timeout: 1234 expect(buckets.size).to eq(2) end end + + describe "when receiving errors from the backend" + before do + @client = Riak::Client.new + end + + it "should retry on recoverable errors" do + call_count = 0 + + begin + @client.backend do |b| + call_count += 1 + raise Riak::ProtobuffsFailedHeader + end + rescue RuntimeError + end + + expect(call_count).to eq(3) + end + + it "should throw a RuntimeError if it runs out of retries" do + error = nil + begin + @client.backend do |b| + raise Riak::ProtobuffsFailedHeader + end + rescue RuntimeError => e + error = e + end + + expect(error).not_to be_nil + expect(error).to be_instance_of(RuntimeError) + end + end