riak-client 0.8.2 → 0.8.3

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.
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  require File.expand_path("../../spec_helper", File.dirname(__FILE__))
15
+ require 'riak/cache_store'
15
16
 
16
17
  describe Riak::CacheStore do
17
18
  before :all do
@@ -137,7 +138,7 @@ describe Riak::CacheStore do
137
138
  end
138
139
 
139
140
  it "should return the default value when fetching on miss" do
140
- @cache.fetch('foo'){'baz'}.should == 'baz'
141
+ @cache.fetch('foo'){ 'baz' }.should == 'baz'
141
142
  end
142
143
 
143
144
  it "should return the default value when forcing a miss" do
@@ -144,15 +144,21 @@ describe Riak::Client do
144
144
  @client = Riak::Client.new
145
145
  end
146
146
 
147
- it "should choose the Curb backend if Curb is available" do
148
- @client.should_receive(:require).with('curb').and_return(true)
149
- @client.http.should be_instance_of(Riak::Client::CurbBackend)
147
+ it "should choose the selected backend" do
148
+ @client.http_backend = :NetHTTP
149
+ @client.http.should be_instance_of(Riak::Client::NetHTTPBackend)
150
+
151
+ unless defined? JRUBY_VERSION
152
+ @client = Riak::Client.new
153
+ @client.http_backend = :Curb
154
+ @client.http.should be_instance_of(Riak::Client::CurbBackend)
155
+ end
150
156
  end
151
157
 
152
- it "should choose the Net::HTTP backend if Curb is unavailable" do
153
- @client.should_receive(:require).with('curb').and_raise(LoadError)
154
- @client.should_receive(:warn).and_return(true)
155
- @client.http.should be_instance_of(Riak::Client::NetHTTPBackend)
158
+ it "should raise an error when the chosen backend is not valid" do
159
+ Riak::Client::NetHTTPBackend.should_receive(:configured?).and_return(false)
160
+ @client = Riak::Client.new(:http_backend => :NetHTTP)
161
+ lambda { @client.http }.should raise_error
156
162
  end
157
163
  end
158
164
 
@@ -233,13 +239,13 @@ describe Riak::Client do
233
239
  @http.should_receive(:delete).with([204,404], "/luwak", "greeting.txt")
234
240
  @client.delete_file("greeting.txt")
235
241
  end
236
-
242
+
237
243
  it "should return true if the file exists" do
238
244
  @client = Riak::Client.new
239
245
  @client.http.should_receive(:head).and_return(:code => 200)
240
246
  @client.file_exists?("foo").should be_true
241
247
  end
242
-
248
+
243
249
  it "should return false if the file doesn't exist" do
244
250
  @client = Riak::Client.new
245
251
  @client.http.should_receive(:head).and_return(:code => 404)
@@ -18,8 +18,8 @@ begin
18
18
  rescue LoadError
19
19
  warn "Skipping CurbBackend specs, curb library not found."
20
20
  else
21
- $server = MockServer.new
22
- at_exit { $server.stop }
21
+ $mock_server = DrbMockServer
22
+ $mock_server.maybe_start
23
23
 
24
24
  describe Riak::Client::CurbBackend do
25
25
  def setup_http_mock(method, uri, options={})
@@ -31,17 +31,21 @@ else
31
31
  body = options[:body] || []
32
32
  headers = options[:headers] || {}
33
33
  headers['Content-Type'] ||= "text/plain"
34
- $server.attach do |env|
35
- env["REQUEST_METHOD"].should == method
36
- env["PATH_INFO"].should == path
37
- env["QUERY_STRING"].should == query
38
- [status, headers, Array(body)]
39
- end
34
+ @_mock_set = [status, headers, method, path, query, body]
35
+ $mock_server.expect(*@_mock_set)
40
36
  end
41
37
 
42
38
  before :each do
43
- @client = Riak::Client.new(:port => $server.port) # Point to our mock
44
- @backend = Riak::Client::CurbBackend.new(@client)
39
+ @client = Riak::Client.new(:port => $mock_server.port, :http_backend => :Curb) # Point to our mock
40
+ @backend = @client.http
41
+ @_mock_set = false
42
+ end
43
+
44
+ after :each do
45
+ if @_mock_set
46
+ $mock_server.satisfied.should be_true("Expected #{@_mock_set.inspect}, failed")
47
+ end
48
+ Thread.current[:curl_easy_handle] = nil
45
49
  end
46
50
 
47
51
  it_should_behave_like "HTTP backend"
@@ -68,10 +72,5 @@ else
68
72
  @backend.post(200, "/riak/", "foo", file, {})
69
73
  end.should_not raise_error
70
74
  end
71
-
72
- after :each do
73
- $server.detach
74
- Thread.current[:curl_easy_handle] = nil
75
- end
76
75
  end
77
76
  end
@@ -0,0 +1,76 @@
1
+ # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
15
+
16
+ begin
17
+ require 'excon'
18
+ rescue LoadError
19
+ warn "Skipping ExconBackend specs, excon library not found."
20
+ else
21
+ $mock_server = DrbMockServer
22
+ $mock_server.maybe_start
23
+
24
+ describe Riak::Client::ExconBackend do
25
+ def setup_http_mock(method, uri, options={})
26
+ method = method.to_s.upcase
27
+ uri = URI.parse(uri)
28
+ path = uri.path || "/"
29
+ query = uri.query || ""
30
+ status = options[:status] ? Array(options[:status]).first.to_i : 200
31
+ body = options[:body] || []
32
+ headers = options[:headers] || {}
33
+ headers['Content-Type'] ||= "text/plain"
34
+ @_mock_set = [status, headers, method, path, query, body]
35
+ $mock_server.expect(*@_mock_set)
36
+ end
37
+
38
+ before :each do
39
+ @client = Riak::Client.new(:port => $mock_server.port, :http_backend => :Excon) # Point to our mock
40
+ @backend = @client.http
41
+ @_mock_set = false
42
+ end
43
+
44
+ after :each do
45
+ if @_mock_set
46
+ $mock_server.satisfied.should be_true("Expected #{@_mock_set.inspect}, failed")
47
+ end
48
+ end
49
+
50
+ it_should_behave_like "HTTP backend"
51
+
52
+ it "should split long headers into 8KB chunks" do
53
+ # TODO: This doesn't actually inspect the emitted headers. How
54
+ # can it?
55
+ setup_http_mock(:put, @backend.path("/riak/","foo").to_s, :body => "ok")
56
+ lambda do
57
+ @backend.put(200, "/riak/", "foo", "body",{"Long-Header" => (["12345678"*10]*100).join(", ") })
58
+ end.should_not raise_error
59
+ end
60
+
61
+ it "should support IO objects as the request body" do
62
+ file = File.open(File.expand_path("../../fixtures/cat.jpg", __FILE__), 'rb')
63
+ lambda do
64
+ setup_http_mock(:put, @backend.path("/riak/","foo").to_s, :body => "ok")
65
+ @backend.put(200, "/riak/", "foo", file, {})
66
+ $mock_server.satisfied.should be_true
67
+ end.should_not raise_error
68
+ file.rewind # Have to rewind the file or we hang
69
+ lambda do
70
+ setup_http_mock(:post, @backend.path("/riak/","foo").to_s, :body => "ok")
71
+ @backend.post(200, "/riak/", "foo", file, {})
72
+ $mock_server.satisfied.should be_true
73
+ end.should_not raise_error
74
+ end
75
+ end
76
+ end
@@ -32,20 +32,6 @@ describe Riak::Link do
32
32
  result[1].key.should == nil
33
33
  result[1].rel.should == "up"
34
34
  end
35
-
36
- it "should set url properly, and set bucket and key to nil for non-Riak links" do
37
- result = Riak::Link.parse('<http://www.example.com/123.html>; riaktag="tag", </riak/foo>; rel="up"')
38
- result[0].url.should == "http://www.example.com/123.html"
39
- result[0].bucket.should == nil
40
- result[0].key.should == nil
41
- result[0].rel.should == "tag"
42
-
43
- result = Riak::Link.parse('<http://www.example.com/>; riaktag="tag", </riak/foo>; rel="up"')
44
- result[0].url.should == "http://www.example.com/"
45
- result[0].bucket.should == nil
46
- result[0].key.should == nil
47
- result[0].rel.should == "tag"
48
- end
49
35
  end
50
36
 
51
37
  it "should convert to a string appropriate for use in the Link header" do
@@ -79,4 +65,12 @@ describe Riak::Link do
79
65
  link.bucket.should == "bucket"
80
66
  link.key.should == "key"
81
67
  end
68
+
69
+ it "should construct from bucket, key and tag" do
70
+ link = Riak::Link.new("bucket", "key", "tag")
71
+ link.bucket.should == "bucket"
72
+ link.key.should == "key"
73
+ link.tag.should == "tag"
74
+ link.url.should == "/riak/bucket/key"
75
+ end
82
76
  end
@@ -88,15 +88,11 @@ describe Riak::RObject do
88
88
 
89
89
  it "should serialize into a JSON blob" do
90
90
  @object.serialize({"foo" => "bar"}).should == '{"foo":"bar"}'
91
- @object.serialize(2).should == "2"
92
- @object.serialize("Some text").should == '"Some text"'
93
91
  @object.serialize([1,2,3]).should == "[1,2,3]"
94
92
  end
95
93
 
96
94
  it "should deserialize a JSON blob" do
97
95
  @object.deserialize('{"foo":"bar"}').should == {"foo" => "bar"}
98
- @object.deserialize("2").should == 2
99
- @object.deserialize('"Some text"').should == "Some text"
100
96
  @object.deserialize('[1,2,3]').should == [1,2,3]
101
97
  end
102
98
  end
@@ -69,12 +69,12 @@ describe "Search mixins" do
69
69
 
70
70
  it "should build a Solr <add> request" do
71
71
  expect_update_body('<add><doc><field name="id">1</field><field name="field">value</field></doc></add>')
72
- @client.index({:id => 1, :field => "value"})
72
+ @client.index({'id' => 1, 'field' => "value"})
73
73
  end
74
74
 
75
75
  it "should include multiple documents in the <add> request" do
76
76
  expect_update_body('<add><doc><field name="id">1</field><field name="field">value</field></doc><doc><field name="id">2</field><field name="foo">bar</field></doc></add>')
77
- @client.index({:id => 1, :field => "value"}, {:id => 2, :foo => "bar"})
77
+ @client.index({'id' => 1, 'field' => "value"}, {'id' => 2, 'foo' => "bar"})
78
78
  end
79
79
  end
80
80
  describe "removing documents" do
@@ -0,0 +1,39 @@
1
+ require 'drb/drb'
2
+ DRBURI="druby://localhost:8787"
3
+
4
+ module DrbMockServer
5
+ extend self
6
+
7
+ def start_client
8
+ # JRuby doesn't support fork
9
+ if defined? JRUBY_VERSION
10
+ @server = MockServer.new
11
+ at_exit { @server.stop }
12
+ else
13
+ child_pid = Process.fork do
14
+ start_server
15
+ end
16
+ sleep 1
17
+ at_exit { Process.kill("HUP", child_pid); Process.wait2 }
18
+ DRb.start_service
19
+ @server = DRbObject.new_with_uri(DRBURI)
20
+ end
21
+ true
22
+ end
23
+
24
+ def maybe_start
25
+ start_client unless @server
26
+ end
27
+
28
+ def method_missing(meth, *args, &block)
29
+ @server.send(meth, *args, &block)
30
+ end
31
+
32
+ private
33
+ def start_server
34
+ server = MockServer.new
35
+ DRb.start_service(DRBURI, server)
36
+ Signal.trap("HUP") { server.stop; exit }
37
+ DRb.thread.join
38
+ end
39
+ end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +19,8 @@ require 'rack'
18
19
 
19
20
  class MockServer
20
21
  attr_accessor :port
21
-
22
+ attr_accessor :satisfied
23
+
22
24
  def initialize(pause = 1)
23
25
  self.port = 4000 + rand(61535)
24
26
  @block = nil
@@ -33,6 +35,15 @@ class MockServer
33
35
  Thread.kill(@thread)
34
36
  end
35
37
 
38
+ def expect(status, headers, method, path, query, body)
39
+ attach do |env|
40
+ @satisfied = (env["REQUEST_METHOD"] == method &&
41
+ env["PATH_INFO"] == path &&
42
+ env["QUERY_STRING"] == query)
43
+ [status, headers, Array(body)]
44
+ end
45
+ end
46
+
36
47
  def attach(&block)
37
48
  @block = block
38
49
  end
@@ -46,8 +57,10 @@ class MockServer
46
57
  raise "Specify a handler for the request using attach(block), the block should return a valid rack response and can test expectations" unless @block
47
58
  @block.call(env)
48
59
  rescue Exception => e
49
- @parent_thread.raise e
50
- [ 500, { 'Content-Type' => 'text/plain', 'Content-Length' => '13' }, [ 'Bad test code' ]]
60
+ @satisfied = false
61
+ # @parent_thread.raise e
62
+ body = "Bad test code\n#{e.inspect}\n#{e.backtrace}"
63
+ [ 500, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [ body ]]
51
64
  end
52
65
  end
53
66
 
@@ -0,0 +1,2 @@
1
+ bin_dir: /Users/sean/Development/riak/rel/riak/bin
2
+ temp_dir: /Users/sean/Development/ripple/.riaktest
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 2
9
- version: 0.8.2
8
+ - 3
9
+ version: 0.8.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sean Cribbs
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-22 00:00:00 -04:00
17
+ date: 2010-12-13 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -75,19 +75,19 @@ dependencies:
75
75
  type: :development
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: activesupport
78
+ name: excon
79
79
  prerelease: false
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ">="
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
85
  segments:
86
- - 2
86
+ - 0
87
87
  - 3
88
- - 5
89
- version: 2.3.5
90
- type: :runtime
88
+ - 4
89
+ version: 0.3.4
90
+ type: :development
91
91
  version_requirements: *id005
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: i18n
@@ -95,7 +95,7 @@ dependencies:
95
95
  requirement: &id006 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
- - - ~>
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  segments:
101
101
  - 0
@@ -104,8 +104,23 @@ dependencies:
104
104
  version: 0.4.0
105
105
  type: :runtime
106
106
  version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: builder
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ segments:
116
+ - 2
117
+ - 1
118
+ - 2
119
+ version: 2.1.2
120
+ type: :runtime
121
+ version_requirements: *id007
107
122
  description: 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.
108
- email: seancribbs@gmail.com
123
+ email: sean@basho.com
109
124
  executables: []
110
125
 
111
126
  extensions: []
@@ -116,14 +131,21 @@ files:
116
131
  - erl_src/riak_kv_test_backend.beam
117
132
  - erl_src/riak_kv_test_backend.erl
118
133
  - Gemfile
119
- - Gemfile.lock
120
134
  - lib/active_support/cache/riak_store.rb
121
135
  - lib/riak/bucket.rb
122
136
  - lib/riak/cache_store.rb
123
137
  - lib/riak/client/curb_backend.rb
138
+ - lib/riak/client/excon_backend.rb
124
139
  - lib/riak/client/http_backend.rb
125
140
  - lib/riak/client/net_http_backend.rb
126
141
  - lib/riak/client.rb
142
+ - lib/riak/core_ext/blank.rb
143
+ - lib/riak/core_ext/extract_options.rb
144
+ - lib/riak/core_ext/slice.rb
145
+ - lib/riak/core_ext/stringify_keys.rb
146
+ - lib/riak/core_ext/symbolize_keys.rb
147
+ - lib/riak/core_ext/to_param.rb
148
+ - lib/riak/core_ext.rb
127
149
  - lib/riak/failed_request.rb
128
150
  - lib/riak/i18n.rb
129
151
  - lib/riak/invalid_response.rb
@@ -143,6 +165,7 @@ files:
143
165
  - lib/riak/walk_spec.rb
144
166
  - lib/riak.rb
145
167
  - Rakefile
168
+ - riak-client.gemspec
146
169
  - spec/fixtures/cat.jpg
147
170
  - spec/fixtures/multipart-blank.txt
148
171
  - spec/fixtures/multipart-with-body.txt
@@ -152,6 +175,7 @@ files:
152
175
  - spec/riak/client_spec.rb
153
176
  - spec/riak/curb_backend_spec.rb
154
177
  - spec/riak/escape_spec.rb
178
+ - spec/riak/excon_backend_spec.rb
155
179
  - spec/riak/headers_spec.rb
156
180
  - spec/riak/http_backend_spec.rb
157
181
  - spec/riak/link_spec.rb
@@ -162,9 +186,11 @@ files:
162
186
  - spec/riak/search_spec.rb
163
187
  - spec/riak/walk_spec_spec.rb
164
188
  - spec/spec_helper.rb
189
+ - spec/support/drb_mock_server.rb
165
190
  - spec/support/http_backend_implementation_examples.rb
166
191
  - spec/support/mock_server.rb
167
192
  - spec/support/mocks.rb
193
+ - spec/support/test_server.yml.example
168
194
  has_rdoc: true
169
195
  homepage: http://seancribbs.github.com/ripple
170
196
  licenses: []
@@ -190,20 +216,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
216
  segments:
191
217
  - 0
192
218
  version: "0"
193
- requirements:
194
- - `gem install curb` for better HTTP performance
219
+ requirements: []
220
+
195
221
  rubyforge_project:
196
222
  rubygems_version: 1.3.7
197
223
  signing_key:
198
224
  specification_version: 3
199
225
  summary: riak-client is a rich client for Riak, the distributed database by Basho.
200
226
  test_files:
227
+ - lib/riak/walk_spec.rb
201
228
  - spec/integration/riak/cache_store_spec.rb
202
229
  - spec/integration/riak/test_server_spec.rb
203
230
  - spec/riak/bucket_spec.rb
204
231
  - spec/riak/client_spec.rb
205
232
  - spec/riak/curb_backend_spec.rb
206
233
  - spec/riak/escape_spec.rb
234
+ - spec/riak/excon_backend_spec.rb
207
235
  - spec/riak/headers_spec.rb
208
236
  - spec/riak/http_backend_spec.rb
209
237
  - spec/riak/link_spec.rb
@@ -213,7 +241,3 @@ test_files:
213
241
  - spec/riak/object_spec.rb
214
242
  - spec/riak/search_spec.rb
215
243
  - spec/riak/walk_spec_spec.rb
216
- - spec/spec_helper.rb
217
- - spec/support/http_backend_implementation_examples.rb
218
- - spec/support/mock_server.rb
219
- - spec/support/mocks.rb