riak-client 1.0.0.beta → 1.0.0
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.
- data/.gitignore +7 -4
- data/Gemfile +12 -17
- data/Guardfile +1 -1
- data/LICENSE +16 -0
- data/README.markdown +178 -0
- data/RELEASE_NOTES.md +99 -0
- data/Rakefile +25 -1
- data/erl_src/riak_kv_test014_backend.beam +0 -0
- data/erl_src/riak_kv_test014_backend.erl +189 -0
- data/erl_src/riak_kv_test_backend.beam +0 -0
- data/erl_src/riak_kv_test_backend.erl +37 -19
- data/lib/riak/client.rb +322 -272
- data/lib/riak/client/beefcake_protobuffs_backend.rb +6 -10
- data/lib/riak/client/decaying.rb +28 -0
- data/lib/riak/client/excon_backend.rb +27 -11
- data/lib/riak/client/http_backend.rb +71 -2
- data/lib/riak/client/http_backend/configuration.rb +17 -3
- data/lib/riak/client/http_backend/transport_methods.rb +3 -3
- data/lib/riak/client/net_http_backend.rb +18 -14
- data/lib/riak/client/node.rb +111 -0
- data/lib/riak/client/pool.rb +180 -0
- data/lib/riak/client/protobuffs_backend.rb +15 -5
- data/lib/riak/client/search.rb +9 -3
- data/lib/riak/link.rb +5 -7
- data/lib/riak/locale/en.yml +1 -0
- data/lib/riak/node/configuration.rb +1 -0
- data/lib/riak/node/defaults.rb +19 -6
- data/lib/riak/node/generation.rb +9 -2
- data/lib/riak/node/log.rb +2 -2
- data/lib/riak/node/version.rb +22 -16
- data/lib/riak/robject.rb +19 -3
- data/lib/riak/serializers.rb +1 -1
- data/lib/riak/test_server.rb +10 -2
- data/lib/riak/version.rb +1 -1
- data/riak-client.gemspec +3 -3
- data/spec/failover/failover.rb +59 -0
- data/spec/integration/riak/http_backends_spec.rb +2 -2
- data/spec/integration/riak/node_spec.rb +16 -24
- data/spec/integration/riak/protobuffs_backends_spec.rb +1 -1
- data/spec/integration/riak/test_server_spec.rb +4 -3
- data/spec/integration/riak/threading_spec.rb +193 -0
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +23 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +4 -2
- data/spec/riak/bucket_spec.rb +2 -1
- data/spec/riak/client_spec.rb +80 -181
- data/spec/riak/excon_backend_spec.rb +3 -2
- data/spec/riak/http_backend/configuration_spec.rb +37 -5
- data/spec/riak/http_backend/object_methods_spec.rb +1 -1
- data/spec/riak/http_backend/transport_methods_spec.rb +2 -2
- data/spec/riak/http_backend_spec.rb +53 -3
- data/spec/riak/map_reduce_spec.rb +1 -1
- data/spec/riak/net_http_backend_spec.rb +1 -2
- data/spec/riak/node_spec.rb +173 -0
- data/spec/riak/pool_spec.rb +306 -0
- data/spec/riak/robject_spec.rb +8 -4
- data/spec/riak/search_spec.rb +66 -15
- data/spec/riak/serializers_spec.rb +12 -1
- data/spec/spec_helper.rb +9 -1
- data/spec/support/http_backend_implementation_examples.rb +6 -2
- data/spec/support/sometimes.rb +46 -0
- data/spec/support/test_server.rb +50 -19
- data/spec/support/unified_backend_examples.rb +11 -10
- data/spec/support/version_filter.rb +14 -0
- metadata +40 -29
- data/lib/active_support/cache/riak_store.rb +0 -2
- data/lib/riak/cache_store.rb +0 -84
- data/lib/riak/client/pump.rb +0 -30
- data/lib/riak/util/fiber1.8.rb +0 -48
- data/spec/integration/riak/cache_store_spec.rb +0 -129
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'riak/client/beefcake/object_methods'
|
3
|
+
require 'riak/client/beefcake/messages'
|
4
|
+
|
5
|
+
describe Riak::Client::BeefcakeProtobuffsBackend::ObjectMethods do
|
6
|
+
before :each do
|
7
|
+
@client = Riak::Client.new
|
8
|
+
@backend = Riak::Client::BeefcakeProtobuffsBackend.new(@client, @client.node)
|
9
|
+
@bucket = Riak::Bucket.new(@client, "bucket")
|
10
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "loading object data from the response" do
|
14
|
+
it "should load the key" do
|
15
|
+
content = stub(:value => '', :vtag => nil, :content_type => nil, :links => nil, :usermeta => nil, :last_mod => nil, :indexes => nil, :charset => nil)
|
16
|
+
pbuf = stub(:vclock => nil, :content => [content], :value => nil, :key => 'akey')
|
17
|
+
o = @backend.load_object(pbuf, @object)
|
18
|
+
o.should == @object
|
19
|
+
o.key.should == pbuf.key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -4,7 +4,8 @@ require 'riak/client/beefcake/messages'
|
|
4
4
|
describe Riak::Client::BeefcakeProtobuffsBackend do
|
5
5
|
before :each do
|
6
6
|
@client = Riak::Client.new
|
7
|
-
@
|
7
|
+
@node = @client.nodes.first
|
8
|
+
@backend = Riak::Client::BeefcakeProtobuffsBackend.new(@client, @node)
|
8
9
|
@backend.instance_variable_set(:@server_config, {})
|
9
10
|
end
|
10
11
|
|
@@ -42,7 +43,8 @@ end
|
|
42
43
|
describe Riak::Client::BeefcakeProtobuffsBackend, '#mapred' do
|
43
44
|
before(:each) do
|
44
45
|
@client = Riak::Client.new
|
45
|
-
@
|
46
|
+
@node = @client.nodes.first
|
47
|
+
@backend = Riak::Client::BeefcakeProtobuffsBackend.new(@client, @node)
|
46
48
|
@backend.instance_variable_set(:@server_config, {})
|
47
49
|
end
|
48
50
|
|
data/spec/riak/bucket_spec.rb
CHANGED
@@ -4,7 +4,8 @@ describe Riak::Bucket do
|
|
4
4
|
before :each do
|
5
5
|
@client = Riak::Client.new
|
6
6
|
@backend = mock("Backend")
|
7
|
-
@client.stub!(:backend).
|
7
|
+
@client.stub!(:backend).and_yield(@backend)
|
8
|
+
@client.stub!(:http).and_yield(@backend)
|
8
9
|
@bucket = Riak::Bucket.new(@client, "foo")
|
9
10
|
end
|
10
11
|
|
data/spec/riak/client_spec.rb
CHANGED
@@ -2,11 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Riak::Client do
|
4
4
|
describe "when initializing" do
|
5
|
-
it "should default
|
5
|
+
it "should default a single local node" do
|
6
6
|
client = Riak::Client.new
|
7
|
-
client.
|
8
|
-
client.http_port.should == 8098
|
9
|
-
client.pb_port.should == 8087
|
7
|
+
client.nodes.should == [Riak::Client::Node.new(client)]
|
10
8
|
end
|
11
9
|
|
12
10
|
it "should accept a protocol" do
|
@@ -16,17 +14,20 @@ describe Riak::Client do
|
|
16
14
|
|
17
15
|
it "should accept a host" do
|
18
16
|
client = Riak::Client.new :host => "riak.basho.com"
|
19
|
-
client.
|
17
|
+
client.nodes.size.should == 1
|
18
|
+
client.nodes.first.host.should == "riak.basho.com"
|
20
19
|
end
|
21
20
|
|
22
21
|
it "should accept an HTTP port" do
|
23
22
|
client = Riak::Client.new :http_port => 9000
|
24
|
-
client.
|
23
|
+
client.nodes.size.should == 1
|
24
|
+
client.nodes.first.http_port.should == 9000
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should accept a Protobuffs port" do
|
28
28
|
client = Riak::Client.new :pb_port => 9000
|
29
|
-
client.
|
29
|
+
client.nodes.size.should == 1
|
30
|
+
client.nodes.first.pb_port.should == 9000
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should warn on setting :port" do
|
@@ -38,7 +39,8 @@ describe Riak::Client do
|
|
38
39
|
|
39
40
|
it "should accept basic_auth" do
|
40
41
|
client = Riak::Client.new :basic_auth => "user:pass"
|
41
|
-
client.
|
42
|
+
client.nodes.size.should == 1
|
43
|
+
client.nodes.first.basic_auth.should eq("user:pass")
|
42
44
|
end
|
43
45
|
|
44
46
|
it "should accept a client ID" do
|
@@ -52,34 +54,22 @@ describe Riak::Client do
|
|
52
54
|
|
53
55
|
it "should accept a path prefix" do
|
54
56
|
client = Riak::Client.new(:prefix => "/jiak/")
|
55
|
-
client.prefix.should == "/jiak/"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should default the prefix to /riak/ if not specified" do
|
59
|
-
Riak::Client.new.prefix.should == "/riak/"
|
57
|
+
client.nodes.first.http_paths[:prefix].should == "/jiak/"
|
60
58
|
end
|
61
59
|
|
62
60
|
it "should accept a mapreduce path" do
|
63
61
|
client = Riak::Client.new(:mapred => "/mr")
|
64
|
-
client.http_paths[:mapred].should == "/mr"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should default the mapreduce path to /mapred if not specified" do
|
68
|
-
Riak::Client.new.http_paths[:mapred].should == "/mapred"
|
62
|
+
client.nodes.first.http_paths[:mapred].should == "/mr"
|
69
63
|
end
|
70
64
|
|
71
65
|
it "should accept a luwak path" do
|
72
66
|
client = Riak::Client.new(:luwak => "/beans")
|
73
|
-
client.http_paths[:luwak].should == "/beans"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should default the luwak path to /luwak if not specified" do
|
77
|
-
Riak::Client.new.http_paths[:luwak].should == "/luwak"
|
67
|
+
client.nodes.first.http_paths[:luwak].should == "/beans"
|
78
68
|
end
|
79
69
|
|
80
70
|
it "should accept a solr path" do
|
81
71
|
client = Riak::Client.new(:solr => "/solar")
|
82
|
-
client.http_paths[:solr].should == "/solar"
|
72
|
+
client.nodes.first.http_paths[:solr].should == "/solar"
|
83
73
|
end
|
84
74
|
end
|
85
75
|
|
@@ -104,86 +94,18 @@ describe Riak::Client do
|
|
104
94
|
lambda { @client.protocol = 'invalid-protocol' }.should(
|
105
95
|
raise_error(ArgumentError, /^'invalid-protocol' is not a valid protocol/))
|
106
96
|
end
|
107
|
-
|
108
|
-
it "should reset the unified backend when changing the protocol" do
|
109
|
-
old = @client.backend
|
110
|
-
@client.protocol = "pbc"
|
111
|
-
old.should_not eq(@client.backend)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "setting the host" do
|
116
|
-
it "should allow setting the host" do
|
117
|
-
@client.should respond_to(:host=)
|
118
|
-
@client.host = "riak.basho.com"
|
119
|
-
@client.host.should == "riak.basho.com"
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should require the host to be an IP or hostname" do
|
123
|
-
[238472384972, ""].each do |invalid|
|
124
|
-
lambda { @client.host = invalid }.should raise_error(ArgumentError)
|
125
|
-
end
|
126
|
-
["127.0.0.1", "10.0.100.5", "localhost", "otherhost.local", "riak.basho.com"].each do |valid|
|
127
|
-
lambda { @client.host = valid }.should_not raise_error
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
[:http, :pb].each do |protocol|
|
133
|
-
describe "setting the #{protocol} port" do
|
134
|
-
it "should allow setting the #{protocol} port" do
|
135
|
-
@client.should respond_to("#{protocol}_port=")
|
136
|
-
@client.send("#{protocol}_port=", 9000)
|
137
|
-
@client.send("#{protocol}_port").should == 9000
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should require the port to be a valid number" do
|
141
|
-
[-1,65536,"foo"].each do |invalid|
|
142
|
-
lambda { @client.send("#{protocol}_port=",invalid) }.should raise_error(ArgumentError)
|
143
|
-
end
|
144
|
-
[0,1,65535,8098].each do |valid|
|
145
|
-
lambda { @client.send("#{protocol}_port=", valid) }.should_not raise_error
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "setting the port" do
|
152
|
-
before do
|
153
|
-
@client.stub!(:warn).and_return(true)
|
154
|
-
end
|
155
|
-
it "should raise a deprecation warning" do
|
156
|
-
@client.should_receive(:warn).and_return(true)
|
157
|
-
@client.port = 9000
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should set the port for the selected protocol" do
|
161
|
-
@client.protocol = "pbc"
|
162
|
-
@client.port = 9000
|
163
|
-
@client.pb_port.should == 9000
|
164
|
-
end
|
165
97
|
end
|
166
98
|
|
167
99
|
describe "setting http auth" do
|
168
100
|
it "should allow setting basic_auth" do
|
169
101
|
@client.should respond_to(:basic_auth=)
|
170
102
|
@client.basic_auth = "user:pass"
|
171
|
-
@client.
|
172
|
-
|
173
|
-
|
174
|
-
it "should require that basic auth splits into two even parts" do
|
175
|
-
lambda { @client.basic_auth ="user" }.should raise_error(ArgumentError, "basic auth must be set using 'user:pass'")
|
103
|
+
@client.nodes.each do |node|
|
104
|
+
node.basic_auth.should eq("user:pass")
|
105
|
+
end
|
176
106
|
end
|
177
107
|
end
|
178
108
|
|
179
|
-
it "should allow setting the prefix" do
|
180
|
-
@client.http_paths.should be_kind_of(Hash)
|
181
|
-
@client.http_paths.include?(:prefix).should == true
|
182
|
-
@client.should respond_to(:prefix=)
|
183
|
-
@client.prefix = "/another-prefix"
|
184
|
-
@client.prefix.should == "/another-prefix"
|
185
|
-
end
|
186
|
-
|
187
109
|
describe "setting the client id" do
|
188
110
|
it "should accept a string unmodified" do
|
189
111
|
@client.client_id = "foo"
|
@@ -207,16 +129,25 @@ describe Riak::Client do
|
|
207
129
|
|
208
130
|
it "should choose the selected backend" do
|
209
131
|
@client.http_backend = :NetHTTP
|
210
|
-
@client.http
|
132
|
+
@client.http do |h|
|
133
|
+
h.should be_instance_of(Riak::Client::NetHTTPBackend)
|
134
|
+
end
|
211
135
|
|
212
136
|
@client = Riak::Client.new
|
213
137
|
@client.http_backend = :Excon
|
214
|
-
@client.http
|
138
|
+
@client.http do |h|
|
139
|
+
h.should be_instance_of(Riak::Client::ExconBackend)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should clear the existing HTTP connections when changed" do
|
144
|
+
@client.http_pool.should_receive(:clear)
|
145
|
+
@client.http_backend = :Excon
|
215
146
|
end
|
216
147
|
|
217
148
|
it "should raise an error when the chosen backend is not valid" do
|
218
149
|
Riak::Client::NetHTTPBackend.should_receive(:configured?).and_return(false)
|
219
|
-
lambda { @client.http }.should raise_error
|
150
|
+
lambda { @client.http { |x| } }.should raise_error
|
220
151
|
end
|
221
152
|
end
|
222
153
|
|
@@ -227,12 +158,19 @@ describe Riak::Client do
|
|
227
158
|
|
228
159
|
it "should choose the selected backend" do
|
229
160
|
@client.protobuffs_backend = :Beefcake
|
230
|
-
@client.protobuffs
|
161
|
+
@client.protobuffs do |p|
|
162
|
+
p.should be_instance_of(Riak::Client::BeefcakeProtobuffsBackend)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should teardown the existing Protobuffs connections when changed" do
|
167
|
+
@client.protobuffs_pool.should_receive(:clear)
|
168
|
+
@client.protobuffs_backend = :Beefcake
|
231
169
|
end
|
232
170
|
|
233
171
|
it "should raise an error when the chosen backend is not valid" do
|
234
172
|
Riak::Client::BeefcakeProtobuffsBackend.should_receive(:configured?).and_return(false)
|
235
|
-
lambda { @client.protobuffs }.should raise_error
|
173
|
+
lambda { @client.protobuffs { |x| } }.should raise_error
|
236
174
|
end
|
237
175
|
end
|
238
176
|
|
@@ -244,13 +182,17 @@ describe Riak::Client do
|
|
244
182
|
it "should use HTTP when the protocol is http or https" do
|
245
183
|
%w[http https].each do |p|
|
246
184
|
@client.protocol = p
|
247
|
-
@client.backend
|
185
|
+
@client.backend do |b|
|
186
|
+
b.should be_kind_of(Riak::Client::HTTPBackend)
|
187
|
+
end
|
248
188
|
end
|
249
189
|
end
|
250
190
|
|
251
191
|
it "should use Protobuffs when the protocol is pbc" do
|
252
192
|
@client.protocol = "pbc"
|
253
|
-
@client.backend
|
193
|
+
@client.backend do |b|
|
194
|
+
b.should be_kind_of(Riak::Client::ProtobuffsBackend)
|
195
|
+
end
|
254
196
|
end
|
255
197
|
end
|
256
198
|
|
@@ -258,7 +200,7 @@ describe Riak::Client do
|
|
258
200
|
before :each do
|
259
201
|
@client = Riak::Client.new
|
260
202
|
@backend = mock("Backend")
|
261
|
-
@client.stub!(:backend).
|
203
|
+
@client.stub!(:backend).and_yield(@backend)
|
262
204
|
end
|
263
205
|
|
264
206
|
it "should return a bucket object" do
|
@@ -282,7 +224,7 @@ describe Riak::Client do
|
|
282
224
|
before do
|
283
225
|
@client = Riak::Client.new
|
284
226
|
@backend = mock("Backend")
|
285
|
-
@client.stub!(:backend).
|
227
|
+
@client.stub!(:backend).and_yield(@backend)
|
286
228
|
end
|
287
229
|
|
288
230
|
after { Riak.disable_list_keys_warnings = true }
|
@@ -309,83 +251,46 @@ describe Riak::Client do
|
|
309
251
|
before :each do
|
310
252
|
@client = Riak::Client.new
|
311
253
|
@http = mock(Riak::Client::HTTPBackend)
|
312
|
-
@
|
254
|
+
@http.stub!(:node).and_return(@client.node)
|
255
|
+
@client.stub!(:http).and_yield(@http)
|
313
256
|
end
|
314
257
|
|
315
|
-
it "should store the file
|
316
|
-
@http.should_receive(:
|
258
|
+
it "should store the file via the HTTP interface" do
|
259
|
+
@http.should_receive(:store_file).with("text/plain", "Hello, world").and_return("123456789")
|
317
260
|
@client.store_file("text/plain", "Hello, world").should == "123456789"
|
318
261
|
end
|
319
|
-
|
320
|
-
it "should store the file in Luwak and return the key/filename when the filename is given" do
|
321
|
-
@http.should_receive(:put).with(204, "/luwak", "greeting.txt", anything, {"Content-Type" => "text/plain"}).and_return(:code => 204, :headers => {})
|
322
|
-
@client.store_file("greeting.txt", "text/plain", "Hello, world").should == "greeting.txt"
|
323
|
-
end
|
324
262
|
end
|
325
263
|
|
326
264
|
describe "retrieving a file" do
|
327
265
|
before :each do
|
328
266
|
@client = Riak::Client.new
|
329
267
|
@http = mock(Riak::Client::HTTPBackend)
|
330
|
-
@
|
331
|
-
@
|
268
|
+
@http.stub!(:node).and_return(@client.node)
|
269
|
+
@client.stub!(:http).and_yield(@http)
|
332
270
|
end
|
333
271
|
|
334
|
-
it "should
|
335
|
-
|
336
|
-
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should stream the data through the given block, returning nil" do
|
340
|
-
string = ""
|
341
|
-
result = @client.get_file("greeting.txt"){|chunk| string << chunk }
|
342
|
-
result.should be_nil
|
343
|
-
string.should == "Hello, world!"
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should expose the original key and content-type on the temporary file" do
|
347
|
-
file = @client.get_file("greeting.txt")
|
348
|
-
file.content_type.should == "text/plain"
|
349
|
-
file.original_filename.should == "greeting.txt"
|
272
|
+
it "should fetch via HTTP" do
|
273
|
+
@http.should_receive(:get_file).with("greeting.txt")
|
274
|
+
@client.get_file("greeting.txt")
|
350
275
|
end
|
351
276
|
end
|
352
277
|
|
353
278
|
it "should delete a file" do
|
354
279
|
@client = Riak::Client.new
|
355
280
|
@http = mock(Riak::Client::HTTPBackend)
|
356
|
-
@
|
357
|
-
@
|
281
|
+
@http.stub!(:node).and_return(@client.nodes.first)
|
282
|
+
@client.stub!(:http).and_yield(@http)
|
283
|
+
@http.should_receive(:delete_file).with("greeting.txt")
|
358
284
|
@client.delete_file("greeting.txt")
|
359
285
|
end
|
360
286
|
|
361
|
-
it "should
|
362
|
-
@client = Riak::Client.new
|
363
|
-
@client.http.should_receive(:head).and_return(:code => 200)
|
364
|
-
@client.file_exists?("foo").should be_true
|
365
|
-
end
|
366
|
-
|
367
|
-
it "should return false if the file doesn't exist" do
|
368
|
-
@client = Riak::Client.new
|
369
|
-
@client.http.should_receive(:head).and_return(:code => 404)
|
370
|
-
@client.file_exists?("foo").should be_false
|
371
|
-
end
|
372
|
-
|
373
|
-
it "should escape the filename when storing, retrieving or deleting files" do
|
287
|
+
it "should detect if file exists via HTTP" do
|
374
288
|
@client = Riak::Client.new
|
375
289
|
@http = mock(Riak::Client::HTTPBackend)
|
376
|
-
@
|
377
|
-
|
378
|
-
@http.should_receive(:
|
379
|
-
@client.
|
380
|
-
# Get escapes keys
|
381
|
-
@http.should_receive(:get).with(200, "/luwak", "docs%2FA%20Big%20PDF.pdf").and_yield("foo").and_return(:headers => {"content-type" => ["text/plain"]}, :code => 200)
|
382
|
-
@client.get_file("docs/A Big PDF.pdf")
|
383
|
-
# Streamed get escapes keys
|
384
|
-
@http.should_receive(:get).with(200, "/luwak", "docs%2FA%20Big%20PDF.pdf").and_yield("foo").and_return(:headers => {"content-type" => ["text/plain"]}, :code => 200)
|
385
|
-
@client.get_file("docs/A Big PDF.pdf"){|chunk| chunk}
|
386
|
-
# Put escapes keys
|
387
|
-
@http.should_receive(:put).with(204, "/luwak", "docs%2FA%20Big%20PDF.pdf", "foo", {"Content-Type" => "text/plain"})
|
388
|
-
@client.store_file("docs/A Big PDF.pdf", "text/plain", "foo")
|
290
|
+
@http.stub!(:node).and_return(@client.nodes.first)
|
291
|
+
@client.stub!(:http).and_yield(@http)
|
292
|
+
@http.should_receive(:file_exists?).and_return(true)
|
293
|
+
@client.file_exists?("foo").should be_true
|
389
294
|
end
|
390
295
|
end
|
391
296
|
|
@@ -399,12 +304,12 @@ describe Riak::Client do
|
|
399
304
|
end
|
400
305
|
|
401
306
|
it "should not have ssl options by default" do
|
402
|
-
@client.ssl_options.should be_nil
|
307
|
+
@client.nodes.first.ssl_options.should be_nil
|
403
308
|
end
|
404
309
|
|
405
310
|
it "should have a blank hash for ssl options if the protocol is set to https" do
|
406
311
|
@client.protocol = 'https'
|
407
|
-
@client.ssl_options.should be_a(Hash)
|
312
|
+
@client.nodes.first.ssl_options.should be_a(Hash)
|
408
313
|
end
|
409
314
|
|
410
315
|
# The api should have an ssl= method for setting up all of the ssl
|
@@ -416,18 +321,18 @@ describe Riak::Client do
|
|
416
321
|
@client.should_not respond_to(:ssl)
|
417
322
|
end
|
418
323
|
|
419
|
-
it "should
|
324
|
+
it "should not allow writing ssl options via ssl_options=" do
|
420
325
|
@client.should_not respond_to(:ssl_options=)
|
421
326
|
end
|
422
327
|
|
423
328
|
it "should allow setting ssl to true" do
|
424
329
|
@client.ssl = true
|
425
|
-
@client.ssl_options[:verify_mode].should eq('none')
|
330
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq('none')
|
426
331
|
end
|
427
332
|
|
428
333
|
it "should allow setting ssl options as a hash" do
|
429
334
|
@client.ssl = {:verify_mode => "peer"}
|
430
|
-
@client.ssl_options[:verify_mode].should eq('peer')
|
335
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq('peer')
|
431
336
|
end
|
432
337
|
|
433
338
|
it "should set the protocol to https when setting ssl to true" do
|
@@ -443,9 +348,9 @@ describe Riak::Client do
|
|
443
348
|
|
444
349
|
it "should should clear ssl options when setting ssl to false" do
|
445
350
|
@client.ssl = true
|
446
|
-
@client.ssl_options.should_not be_nil
|
351
|
+
@client.nodes.first.ssl_options.should_not be_nil
|
447
352
|
@client.ssl = false
|
448
|
-
@client.ssl_options.should be_nil
|
353
|
+
@client.nodes.first.ssl_options.should be_nil
|
449
354
|
end
|
450
355
|
|
451
356
|
it "should set the protocol to https when setting ssl options" do
|
@@ -455,12 +360,12 @@ describe Riak::Client do
|
|
455
360
|
|
456
361
|
it "should allow setting the verify_mode to none" do
|
457
362
|
@client.ssl = {:verify_mode => "none"}
|
458
|
-
@client.ssl_options[:verify_mode].should eq("none")
|
363
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq("none")
|
459
364
|
end
|
460
365
|
|
461
366
|
it "should allow setting the verify_mode to peer" do
|
462
367
|
@client.ssl = {:verify_mode => "peer"}
|
463
|
-
@client.ssl_options[:verify_mode].should eq("peer")
|
368
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq("peer")
|
464
369
|
end
|
465
370
|
|
466
371
|
it "should not allow setting the verify_mode to anything else" do
|
@@ -469,50 +374,44 @@ describe Riak::Client do
|
|
469
374
|
|
470
375
|
it "should default verify_mode to none" do
|
471
376
|
@client.ssl = true
|
472
|
-
@client.ssl_options[:verify_mode].should eq("none")
|
473
|
-
end
|
474
|
-
|
475
|
-
it "should let the backend know if ssl is enabled" do
|
476
|
-
@client.should_not be_ssl_enabled
|
477
|
-
@client.ssl = true
|
478
|
-
@client.should be_ssl_enabled
|
377
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq("none")
|
479
378
|
end
|
480
379
|
|
481
380
|
it "should allow setting the pem" do
|
482
381
|
@client.ssl = {:pem => 'i-am-a-pem'}
|
483
|
-
@client.ssl_options[:pem].should eq('i-am-a-pem')
|
382
|
+
@client.nodes.first.ssl_options[:pem].should eq('i-am-a-pem')
|
484
383
|
end
|
485
384
|
|
486
385
|
it "should set them pem from the contents of pem_file" do
|
487
386
|
filepath = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test.pem'))
|
488
387
|
@client.ssl = {:pem_file => filepath}
|
489
|
-
@client.ssl_options[:pem].should eq("i-am-a-pem\n")
|
388
|
+
@client.nodes.first.ssl_options[:pem].should eq("i-am-a-pem\n")
|
490
389
|
end
|
491
390
|
|
492
391
|
it "should allow setting the pem_password" do
|
493
392
|
@client.ssl = {:pem_password => 'pem-pass'}
|
494
|
-
@client.ssl_options[:pem_password].should eq('pem-pass')
|
393
|
+
@client.nodes.first.ssl_options[:pem_password].should eq('pem-pass')
|
495
394
|
end
|
496
395
|
|
497
396
|
it "should allow setting the ca_file" do
|
498
397
|
@client.ssl = {:ca_file => '/path/to/ca.crt'}
|
499
|
-
@client.ssl_options[:ca_file].should eq('/path/to/ca.crt')
|
398
|
+
@client.nodes.first.ssl_options[:ca_file].should eq('/path/to/ca.crt')
|
500
399
|
end
|
501
400
|
|
502
401
|
it "should allow setting the ca_path" do
|
503
402
|
@client.ssl = {:ca_path => '/path/to/certs/'}
|
504
|
-
@client.ssl_options[:ca_path].should eq('/path/to/certs/')
|
403
|
+
@client.nodes.first.ssl_options[:ca_path].should eq('/path/to/certs/')
|
505
404
|
end
|
506
405
|
|
507
406
|
%w[pem ca_file ca_path].each do |option|
|
508
407
|
it "should default the verify_mode to peer when setting the #{option}" do
|
509
408
|
@client.ssl = {option.to_sym => 'test-data'}
|
510
|
-
@client.ssl_options[:verify_mode].should eq("peer")
|
409
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq("peer")
|
511
410
|
end
|
512
411
|
|
513
412
|
it "should allow setting the verify mode when setting the #{option}" do
|
514
413
|
@client.ssl = {option.to_sym => 'test-data', :verify_mode => "none"}
|
515
|
-
@client.ssl_options[:verify_mode].should eq("none")
|
414
|
+
@client.nodes.first.ssl_options[:verify_mode].should eq("none")
|
516
415
|
end
|
517
416
|
end
|
518
417
|
end
|