Sha256: 3762c56f7c56bc6f379fbe7d1e4f7abc55ae0ec46ff58ba49f8e521453b2352a

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require File.expand_path("../spec_helper", File.dirname(__FILE__))
require 'riak/client/beefcake/messages'

describe Riak::Client::BeefcakeProtobuffsBackend do
  before :each do
    @client = Riak::Client.new
    @backend = Riak::Client::BeefcakeProtobuffsBackend.new(@client)
    @backend.instance_variable_set(:@server_config, {})
  end

  it "should only write to the socket one time per request" do
    exp_bucket, exp_keys = 'foo', ['bar']
    mock_socket = mock("mock TCP socket")

    @backend.stub!(:socket).and_return(mock_socket)
    mock_socket.should_receive(:write).exactly(1).with do |param|
      len, code = param[0,5].unpack("NC")
      req = Riak::Client::BeefcakeProtobuffsBackend::RpbListKeysReq.decode(param[5..-1])
      code == 17 && req.bucket == exp_bucket
    end

    responses = Array.new(2) do |index|
      resp = Riak::Client::BeefcakeProtobuffsBackend::RpbListKeysResp.new
      if index == 0
        resp.keys = exp_keys
      else
        resp.done = true
      end
      resp
    end

    responses.each do |response|
      encoded_response = response.encode
      mock_socket.should_receive(:read).exactly(1).with(5).and_return([1 + encoded_response.length, 18].pack("NC"))
      mock_socket.should_receive(:read).exactly(1).with(encoded_response.length).and_return(encoded_response)
    end

    @backend.list_keys(exp_bucket).should == exp_keys
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riak-client-0.9.4 spec/riak/beefcake_protobuffs_backend_spec.rb