riak-client 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -134,8 +134,8 @@ module Riak
134
134
  private
135
135
  def write_protobuff(code, message)
136
136
  encoded = message.encode
137
- socket.write([encoded.length+1, MESSAGE_CODES.index(code)].pack("NC"))
138
- socket.write(encoded)
137
+ header = [encoded.length+1, MESSAGE_CODES.index(code)].pack("NC")
138
+ socket.write(header + encoded)
139
139
  end
140
140
 
141
141
  def decode_response(*args)
@@ -62,7 +62,7 @@ module Riak
62
62
  http.use_ssl = true
63
63
  http.verify_mode = OpenSSL::SSL.const_get("VERIFY_#{@client.ssl_options[:verify_mode].upcase}")
64
64
  if @client.ssl_options[:pem]
65
- http.cert = OpenSSL::X510::Certificate.new(@client.ssl_options[:pem])
65
+ http.cert = OpenSSL::X509::Certificate.new(@client.ssl_options[:pem])
66
66
  http.key = OpenSSL::PKey::RSA.new(@client.ssl_options[:pem], @client.ssl_options[:pem_password])
67
67
  end
68
68
  http.ca_file = @client.ssl_options[:ca_file] if @client.ssl_options[:ca_file]
@@ -75,7 +75,13 @@ module Riak
75
75
  end
76
76
 
77
77
  def socket
78
- Thread.current[:riakpbc_socket] ||= TCPSocket.new(@client.host, @client.pb_port)
78
+ Thread.current[:riakpbc_socket] ||= new_socket
79
+ end
80
+
81
+ def new_socket
82
+ socket = TCPSocket.new(@client.host, @client.pb_port)
83
+ socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
84
+ socket
79
85
  end
80
86
 
81
87
  def reset_socket
data/lib/riak/json.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Load JSON
3
2
  unless defined? JSON
4
3
  begin
@@ -7,3 +6,12 @@ unless defined? JSON
7
6
  require 'json'
8
7
  end
9
8
  end
9
+
10
+ module Riak
11
+ class << self
12
+ # Options that will be passed to the JSON parser and encoder.
13
+ # Defaults to {:max_nesting => 20}
14
+ attr_accessor :json_options
15
+ end
16
+ self.json_options = {:max_nesting => 20}
17
+ end
data/lib/riak/robject.rb CHANGED
@@ -199,7 +199,7 @@ module Riak
199
199
  return payload if IO === payload
200
200
  case @content_type
201
201
  when /json/
202
- payload.to_json
202
+ payload.to_json(Riak.json_options)
203
203
  when /yaml/
204
204
  YAML.dump(payload)
205
205
  when "application/x-ruby-marshal"
@@ -219,7 +219,7 @@ module Riak
219
219
  def deserialize(body)
220
220
  case @content_type
221
221
  when /json/
222
- JSON.parse(body)
222
+ JSON.parse(body, Riak.json_options)
223
223
  when /yaml/
224
224
  YAML.load(body)
225
225
  when "application/x-ruby-marshal"
data/riak-client.gemspec CHANGED
@@ -2,19 +2,19 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{riak-client}
5
- s.version = "0.9.3"
5
+ s.version = "0.9.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sean Cribbs"]
9
- s.date = %q{2011-04-18}
9
+ s.date = %q{2011-05-10}
10
10
  s.description = %q{riak-client is a rich client for Riak, the distributed database by Basho. It supports the full HTTP interface including storage operations, bucket configuration, link-walking and map-reduce.}
11
11
  s.email = %q{sean@basho.com}
12
- s.files = ["erl_src/riak_kv_test_backend.beam", "erl_src/riak_kv_test_backend.erl", "Gemfile", "lib/active_support/cache/riak_store.rb", "lib/riak/bucket.rb", "lib/riak/cache_store.rb", "lib/riak/client/beefcake/messages.rb", "lib/riak/client/beefcake/object_methods.rb", "lib/riak/client/beefcake_protobuffs_backend.rb", "lib/riak/client/curb_backend.rb", "lib/riak/client/excon_backend.rb", "lib/riak/client/http_backend/configuration.rb", "lib/riak/client/http_backend/key_streamer.rb", "lib/riak/client/http_backend/object_methods.rb", "lib/riak/client/http_backend/request_headers.rb", "lib/riak/client/http_backend/transport_methods.rb", "lib/riak/client/http_backend.rb", "lib/riak/client/net_http_backend.rb", "lib/riak/client/protobuffs_backend.rb", "lib/riak/client/pump.rb", "lib/riak/client.rb", "lib/riak/core_ext/blank.rb", "lib/riak/core_ext/extract_options.rb", "lib/riak/core_ext/slice.rb", "lib/riak/core_ext/stringify_keys.rb", "lib/riak/core_ext/symbolize_keys.rb", "lib/riak/core_ext/to_param.rb", "lib/riak/core_ext.rb", "lib/riak/failed_request.rb", "lib/riak/i18n.rb", "lib/riak/json.rb", "lib/riak/link.rb", "lib/riak/locale/en.yml", "lib/riak/map_reduce/filter_builder.rb", "lib/riak/map_reduce/phase.rb", "lib/riak/map_reduce.rb", "lib/riak/map_reduce_error.rb", "lib/riak/robject.rb", "lib/riak/search.rb", "lib/riak/test_server.rb", "lib/riak/util/escape.rb", "lib/riak/util/fiber1.8.rb", "lib/riak/util/headers.rb", "lib/riak/util/multipart/stream_parser.rb", "lib/riak/util/multipart.rb", "lib/riak/util/tcp_socket_extensions.rb", "lib/riak/util/translation.rb", "lib/riak/walk_spec.rb", "lib/riak.rb", "Rakefile", "riak-client.gemspec", "spec/fixtures/cat.jpg", "spec/fixtures/multipart-blank.txt", "spec/fixtures/multipart-mapreduce.txt", "spec/fixtures/multipart-with-body.txt", "spec/fixtures/server.cert.crt", "spec/fixtures/server.cert.key", "spec/fixtures/test.pem", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/curb_backend_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb", "spec/spec_helper.rb", "spec/support/drb_mock_server.rb", "spec/support/http_backend_implementation_examples.rb", "spec/support/mock_server.rb", "spec/support/mocks.rb", "spec/support/test_server.yml.example", "spec/support/unified_backend_examples.rb"]
12
+ s.files = ["erl_src/riak_kv_test_backend.beam", "erl_src/riak_kv_test_backend.erl", "Gemfile", "lib/active_support/cache/riak_store.rb", "lib/riak/bucket.rb", "lib/riak/cache_store.rb", "lib/riak/client/beefcake/messages.rb", "lib/riak/client/beefcake/object_methods.rb", "lib/riak/client/beefcake_protobuffs_backend.rb", "lib/riak/client/curb_backend.rb", "lib/riak/client/excon_backend.rb", "lib/riak/client/http_backend/configuration.rb", "lib/riak/client/http_backend/key_streamer.rb", "lib/riak/client/http_backend/object_methods.rb", "lib/riak/client/http_backend/request_headers.rb", "lib/riak/client/http_backend/transport_methods.rb", "lib/riak/client/http_backend.rb", "lib/riak/client/net_http_backend.rb", "lib/riak/client/protobuffs_backend.rb", "lib/riak/client/pump.rb", "lib/riak/client.rb", "lib/riak/core_ext/blank.rb", "lib/riak/core_ext/extract_options.rb", "lib/riak/core_ext/slice.rb", "lib/riak/core_ext/stringify_keys.rb", "lib/riak/core_ext/symbolize_keys.rb", "lib/riak/core_ext/to_param.rb", "lib/riak/core_ext.rb", "lib/riak/failed_request.rb", "lib/riak/i18n.rb", "lib/riak/json.rb", "lib/riak/link.rb", "lib/riak/locale/en.yml", "lib/riak/map_reduce/filter_builder.rb", "lib/riak/map_reduce/phase.rb", "lib/riak/map_reduce.rb", "lib/riak/map_reduce_error.rb", "lib/riak/robject.rb", "lib/riak/search.rb", "lib/riak/test_server.rb", "lib/riak/util/escape.rb", "lib/riak/util/fiber1.8.rb", "lib/riak/util/headers.rb", "lib/riak/util/multipart/stream_parser.rb", "lib/riak/util/multipart.rb", "lib/riak/util/tcp_socket_extensions.rb", "lib/riak/util/translation.rb", "lib/riak/walk_spec.rb", "lib/riak.rb", "Rakefile", "riak-client.gemspec", "spec/fixtures/cat.jpg", "spec/fixtures/multipart-blank.txt", "spec/fixtures/multipart-mapreduce.txt", "spec/fixtures/multipart-with-body.txt", "spec/fixtures/server.cert.crt", "spec/fixtures/server.cert.key", "spec/fixtures/test.pem", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/beefcake_protobuffs_backend_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/curb_backend_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb", "spec/spec_helper.rb", "spec/support/drb_mock_server.rb", "spec/support/http_backend_implementation_examples.rb", "spec/support/mock_server.rb", "spec/support/mocks.rb", "spec/support/test_server.yml.example", "spec/support/unified_backend_examples.rb"]
13
13
  s.homepage = %q{http://seancribbs.github.com/ripple}
14
14
  s.require_paths = ["lib"]
15
15
  s.rubygems_version = %q{1.7.2}
16
16
  s.summary = %q{riak-client is a rich client for Riak, the distributed database by Basho.}
17
- s.test_files = ["lib/riak/walk_spec.rb", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/curb_backend_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb"]
17
+ s.test_files = ["lib/riak/walk_spec.rb", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/beefcake_protobuffs_backend_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/curb_backend_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb"]
18
18
 
19
19
  if s.respond_to? :specification_version then
20
20
  s.specification_version = 3
@@ -0,0 +1,40 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+ require 'riak/client/beefcake/messages'
3
+
4
+ describe Riak::Client::BeefcakeProtobuffsBackend do
5
+ before :each do
6
+ @client = Riak::Client.new
7
+ @backend = Riak::Client::BeefcakeProtobuffsBackend.new(@client)
8
+ @backend.instance_variable_set(:@server_config, {})
9
+ end
10
+
11
+ it "should only write to the socket one time per request" do
12
+ exp_bucket, exp_keys = 'foo', ['bar']
13
+ mock_socket = mock("mock TCP socket")
14
+
15
+ @backend.stub!(:socket).and_return(mock_socket)
16
+ mock_socket.should_receive(:write).exactly(1).with do |param|
17
+ len, code = param[0,5].unpack("NC")
18
+ req = Riak::Client::BeefcakeProtobuffsBackend::RpbListKeysReq.decode(param[5..-1])
19
+ code == 17 && req.bucket == exp_bucket
20
+ end
21
+
22
+ responses = Array.new(2) do |index|
23
+ resp = Riak::Client::BeefcakeProtobuffsBackend::RpbListKeysResp.new
24
+ if index == 0
25
+ resp.keys = exp_keys
26
+ else
27
+ resp.done = true
28
+ end
29
+ resp
30
+ end
31
+
32
+ responses.each do |response|
33
+ encoded_response = response.encode
34
+ mock_socket.should_receive(:read).exactly(1).with(5).and_return([1 + encoded_response.length, 18].pack("NC"))
35
+ mock_socket.should_receive(:read).exactly(1).with(encoded_response.length).and_return(encoded_response)
36
+ end
37
+
38
+ @backend.list_keys(exp_bucket).should == exp_keys
39
+ end
40
+ end
@@ -95,6 +95,22 @@ describe Riak::RObject do
95
95
  @object.deserialize('{"foo":"bar"}').should == {"foo" => "bar"}
96
96
  @object.deserialize('[1,2,3]').should == [1,2,3]
97
97
  end
98
+
99
+ it "should respect the max nesting option" do
100
+ # Sadly, this spec will not fail for me when using yajl-ruby
101
+ # on Ruby 1.9, even when passing the options to #to_json is
102
+ # not implemented.
103
+ Riak.json_options = {:max_nesting => 51}
104
+ h = {}
105
+ p = h
106
+ (1..50).each do |i|
107
+ p['a'] = {}
108
+ p = p['a']
109
+ end
110
+ s = h.to_json(Riak.json_options)
111
+ lambda { @object.serialize(h) }.should_not raise_error
112
+ lambda { @object.deserialize(s) }.should_not raise_error
113
+ end
98
114
  end
99
115
 
100
116
  describe "when the content type is application/x-ruby-marshal" do
data/spec/spec_helper.rb CHANGED
@@ -40,4 +40,7 @@ RSpec.configure do |config|
40
40
  config.before(:each) do
41
41
  FakeWeb.clean_registry
42
42
  end
43
+
44
+ config.filter_run :focus => true
45
+ config.run_all_when_everything_filtered = true
43
46
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: riak-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.3
5
+ version: 0.9.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sean Cribbs
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-18 00:00:00 Z
13
+ date: 2011-05-10 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -171,6 +171,7 @@ files:
171
171
  - spec/integration/riak/http_backends_spec.rb
172
172
  - spec/integration/riak/protobuffs_backends_spec.rb
173
173
  - spec/integration/riak/test_server_spec.rb
174
+ - spec/riak/beefcake_protobuffs_backend_spec.rb
174
175
  - spec/riak/bucket_spec.rb
175
176
  - spec/riak/client_spec.rb
176
177
  - spec/riak/curb_backend_spec.rb
@@ -231,6 +232,7 @@ test_files:
231
232
  - spec/integration/riak/http_backends_spec.rb
232
233
  - spec/integration/riak/protobuffs_backends_spec.rb
233
234
  - spec/integration/riak/test_server_spec.rb
235
+ - spec/riak/beefcake_protobuffs_backend_spec.rb
234
236
  - spec/riak/bucket_spec.rb
235
237
  - spec/riak/client_spec.rb
236
238
  - spec/riak/curb_backend_spec.rb