zk 0.9.1 → 1.0.0.rc.1
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 +2 -2
- data/Gemfile +3 -4
- data/README.markdown +14 -5
- data/RELEASES.markdown +69 -1
- data/Rakefile +50 -18
- data/docs/examples/block_until_node_deleted_ex.rb +63 -0
- data/docs/examples/events_01.rb +36 -0
- data/docs/examples/events_02.rb +41 -0
- data/lib/{z_k → zk}/client/base.rb +87 -30
- data/lib/{z_k → zk}/client/conveniences.rb +0 -1
- data/lib/{z_k → zk}/client/state_mixin.rb +0 -0
- data/lib/zk/client/threaded.rb +196 -0
- data/lib/{z_k → zk}/client/unixisms.rb +0 -0
- data/lib/zk/client.rb +59 -0
- data/lib/zk/core_ext.rb +75 -0
- data/lib/{z_k → zk}/election.rb +0 -0
- data/lib/zk/event.rb +168 -0
- data/lib/{z_k → zk}/event_handler.rb +53 -28
- data/lib/zk/event_handler_subscription.rb +68 -0
- data/lib/{z_k → zk}/exceptions.rb +38 -23
- data/lib/zk/extensions.rb +79 -0
- data/lib/{z_k → zk}/find.rb +0 -0
- data/lib/{z_k → zk}/locker.rb +0 -0
- data/lib/{z_k → zk}/logging.rb +0 -0
- data/lib/{z_k → zk}/message_queue.rb +8 -4
- data/lib/{z_k → zk}/mongoid.rb +0 -0
- data/lib/{z_k → zk}/pool.rb +0 -0
- data/lib/zk/stat.rb +115 -0
- data/lib/{z_k → zk}/threadpool.rb +52 -4
- data/lib/zk/version.rb +3 -0
- data/lib/zk.rb +238 -1
- data/spec/message_queue_spec.rb +2 -2
- data/spec/shared/client_contexts.rb +8 -20
- data/spec/shared/client_examples.rb +136 -2
- data/spec/spec_helper.rb +4 -2
- data/spec/support/event_catcher.rb +11 -0
- data/spec/support/exist_matcher.rb +6 -0
- data/spec/support/logging.rb +2 -1
- data/spec/watch_spec.rb +194 -10
- data/spec/{z_k → zk}/client/locking_and_session_death_spec.rb +0 -32
- data/spec/zk/client_spec.rb +23 -0
- data/spec/{z_k → zk}/election_spec.rb +0 -0
- data/spec/{z_k → zk}/extensions_spec.rb +0 -0
- data/spec/{z_k → zk}/locker_spec.rb +0 -40
- data/spec/zk/module_spec.rb +185 -0
- data/spec/{z_k → zk}/mongoid_spec.rb +0 -2
- data/spec/{z_k → zk}/pool_spec.rb +0 -2
- data/spec/{z_k → zk}/threadpool_spec.rb +32 -4
- data/spec/zookeeper_spec.rb +1 -6
- data/zk.gemspec +2 -2
- metadata +64 -56
- data/lib/z_k/client/continuation_proxy.rb +0 -109
- data/lib/z_k/client/drop_box.rb +0 -98
- data/lib/z_k/client/multiplexed.rb +0 -28
- data/lib/z_k/client/threaded.rb +0 -76
- data/lib/z_k/client.rb +0 -35
- data/lib/z_k/event_handler_subscription.rb +0 -36
- data/lib/z_k/extensions.rb +0 -155
- data/lib/z_k/version.rb +0 -3
- data/lib/z_k.rb +0 -97
- data/spec/z_k/client/drop_box_spec.rb +0 -90
- data/spec/z_k/client/multiplexed_spec.rb +0 -20
- data/spec/z_k/client_spec.rb +0 -7
data/spec/watch_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ZK do
|
4
|
-
describe do
|
4
|
+
describe 'watchers' do
|
5
5
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@path = "/_testWatch"
|
10
|
-
wait_until { @zk.connected? }
|
6
|
+
mute_logger do
|
7
|
+
@cnx_str = "localhost:#{ZK_TEST_PORT}"
|
8
|
+
@zk = ZK.new(@cnx_str)
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
@path = "/_testWatch"
|
11
|
+
wait_until { @zk.connected? }
|
12
|
+
@zk.rm_rf(@path)
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
after do
|
@@ -147,9 +147,193 @@ describe ZK do
|
|
147
147
|
wait_while { events.empty? }
|
148
148
|
|
149
149
|
events.should_not be_empty
|
150
|
+
end
|
151
|
+
|
152
|
+
describe ':all' do
|
153
|
+
before do
|
154
|
+
mute_logger do
|
155
|
+
@other_path = "#{@path}2"
|
156
|
+
@zk.rm_rf(@other_path)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
after do
|
161
|
+
mute_logger do
|
162
|
+
@zk.rm_rf(@other_path)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it %[should receive all node events] do
|
167
|
+
events = []
|
168
|
+
|
169
|
+
sub = @zk.register(:all) do |ev|
|
170
|
+
logger.debug { "got event #{ev}" }
|
171
|
+
events << ev
|
172
|
+
end
|
150
173
|
|
174
|
+
@zk.stat(@path, :watch => true)
|
175
|
+
@zk.stat(@other_path, :watch => true)
|
176
|
+
|
177
|
+
@zk.create(@path)
|
178
|
+
@zk.create(@other_path, 'blah')
|
179
|
+
|
180
|
+
wait_until { events.length == 2 }.should be_true
|
181
|
+
end
|
151
182
|
end
|
152
|
-
|
183
|
+
|
184
|
+
describe %[event interest] do
|
185
|
+
context do # event catcher scope
|
186
|
+
before do
|
187
|
+
@events = EventCatcher.new
|
188
|
+
|
189
|
+
@zk.register(@path, :created) do |event|
|
190
|
+
@events.created << event
|
191
|
+
end
|
192
|
+
|
193
|
+
@zk.register(@path, :changed) do |event|
|
194
|
+
@events.changed << event
|
195
|
+
end
|
196
|
+
|
197
|
+
@zk.register(@path, :child) do |event|
|
198
|
+
@events.child << event
|
199
|
+
end
|
200
|
+
|
201
|
+
@zk.register(@path, :deleted) do |event|
|
202
|
+
@events.deleted << event
|
203
|
+
end
|
204
|
+
|
205
|
+
# this will catch all events, that way we don't have to wait for an
|
206
|
+
# event to *not* be delivered to one of the other callbacks (which is
|
207
|
+
# kinda stupid)
|
208
|
+
@zk.register(@path) do |event|
|
209
|
+
@events.all << event
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
it %[should deliver only the created event to the created block] do
|
214
|
+
@zk.stat(@path, :watch => true).should_not exist
|
215
|
+
|
216
|
+
@zk.create(@path)
|
217
|
+
wait_while { @events.created.empty? }.should be_false
|
218
|
+
@events.created.first.should be_node_created
|
219
|
+
|
220
|
+
@zk.stat(@path, :watch => true).should exist
|
221
|
+
|
222
|
+
@events.all.length.should == 1
|
223
|
+
|
224
|
+
@zk.delete(@path)
|
225
|
+
|
226
|
+
wait_until { @events.all.length > 1 }
|
227
|
+
|
228
|
+
# :deleted event was delivered, make sure it didn't get delivered to the :created block
|
229
|
+
@events.created.length.should == 1
|
230
|
+
end
|
231
|
+
|
232
|
+
it %[should deliver only the changed event to the changed block] do
|
233
|
+
@zk.create(@path)
|
234
|
+
|
235
|
+
@zk.stat(@path, :watch => true).should exist
|
236
|
+
|
237
|
+
@zk.set(@path, 'data')
|
238
|
+
|
239
|
+
wait_while { @events.changed.empty? }
|
240
|
+
|
241
|
+
@events.changed.first.should be_node_changed
|
242
|
+
|
243
|
+
@zk.stat(@path, :watch => true).should exist
|
244
|
+
|
245
|
+
@events.all.length.should == 1
|
246
|
+
|
247
|
+
@zk.delete(@path)
|
248
|
+
|
249
|
+
wait_until { @events.all.length > 1 }
|
250
|
+
|
251
|
+
# :deleted event was delivered, make sure it didn't get delivered to the :changed block
|
252
|
+
@events.changed.length.should == 1
|
253
|
+
end
|
254
|
+
|
255
|
+
it %[should deliver only the child event to the child block] do
|
256
|
+
@zk.create(@path)
|
257
|
+
|
258
|
+
@zk.children(@path, :watch => true).should be_empty
|
259
|
+
|
260
|
+
child_path = @zk.create("#{@path}/m", '', :sequence => true)
|
261
|
+
|
262
|
+
wait_while { @events.child.empty? }
|
263
|
+
|
264
|
+
@events.child.first.should be_node_child
|
265
|
+
|
266
|
+
@zk.stat(@path, :watch => true).should exist
|
267
|
+
|
268
|
+
@events.all.length.should == 1
|
269
|
+
|
270
|
+
@zk.set(@path, '') # equivalent to a 'touch'
|
271
|
+
|
272
|
+
wait_until { @events.all.length > 1 }
|
273
|
+
|
274
|
+
# :changed event was delivered, make sure it didn't get delivered to the :child block
|
275
|
+
@events.child.length.should == 1
|
276
|
+
end
|
277
|
+
|
278
|
+
it %[should deliver only the deleted event to the deleted block] do
|
279
|
+
@zk.create(@path)
|
280
|
+
|
281
|
+
@zk.stat(@path, :watch => true).should exist
|
282
|
+
|
283
|
+
@zk.delete(@path)
|
284
|
+
|
285
|
+
wait_while { @events.deleted.empty? }
|
286
|
+
|
287
|
+
@events.deleted.first.should be_node_deleted
|
288
|
+
|
289
|
+
@zk.stat(@path, :watch => true).should_not exist
|
290
|
+
|
291
|
+
@events.all.length.should == 1
|
292
|
+
|
293
|
+
@zk.create(@path)
|
294
|
+
|
295
|
+
wait_until { @events.all.length > 1 }
|
296
|
+
|
297
|
+
# :deleted event was delivered, make sure it didn't get delivered to the :created block
|
298
|
+
@events.deleted.length.should == 1
|
299
|
+
end
|
300
|
+
end # event catcher scope
|
301
|
+
|
302
|
+
it %[should deliver interested events to a block registered for multiple deliveries] do
|
303
|
+
@events = []
|
304
|
+
|
305
|
+
@zk.register(@path, [:created, :changed]) do |event|
|
306
|
+
@events << event
|
307
|
+
end
|
308
|
+
|
309
|
+
@zk.stat(@path, :watch => true).should_not exist
|
310
|
+
|
311
|
+
@zk.create(@path)
|
312
|
+
|
313
|
+
wait_while { @events.empty? }
|
314
|
+
|
315
|
+
@events.length.should == 1
|
316
|
+
|
317
|
+
@events.first.should be_node_created
|
318
|
+
|
319
|
+
@zk.stat(@path, :watch => true).should exist
|
320
|
+
|
321
|
+
@zk.set(@path, 'blah')
|
322
|
+
|
323
|
+
wait_until { @events.length > 1 }
|
324
|
+
|
325
|
+
@events.length.should == 2
|
326
|
+
|
327
|
+
@events.last.should be_node_changed
|
328
|
+
end
|
329
|
+
|
330
|
+
it %[should barf if an invalid event name is given] do
|
331
|
+
lambda do
|
332
|
+
@zk.register(@path, :tripping) { }
|
333
|
+
end.should raise_error(ArgumentError)
|
334
|
+
end
|
335
|
+
end # event interest
|
336
|
+
end # watchers
|
153
337
|
|
154
338
|
describe 'state watcher' do
|
155
339
|
describe 'live-fire test' do
|
@@ -178,7 +362,7 @@ describe ZK do
|
|
178
362
|
m.should_receive(:state).and_return(ZookeeperConstants::ZOO_CONNECTED_STATE)
|
179
363
|
end
|
180
364
|
end
|
181
|
-
end
|
365
|
+
end # registered listeners
|
182
366
|
end
|
183
367
|
end
|
184
368
|
|
@@ -73,36 +73,4 @@ shared_examples_for 'locking and session death' do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe 'threaded client and locking behavior' do
|
77
|
-
include_context 'threaded client connection'
|
78
|
-
|
79
|
-
before do
|
80
|
-
@path = '/test'
|
81
|
-
@zk.create('/test') rescue ZK::Exceptions::NodeExists
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'block_until_node_deleted' do
|
85
|
-
it %[should raise an EventDispatchThreadException if called in the context of the event dispatch thread] do
|
86
|
-
@exception = nil
|
87
|
-
|
88
|
-
@zk.register(@path) do |event|
|
89
|
-
@zk.event_dispatch_thread?.should be_true
|
90
|
-
|
91
|
-
begin
|
92
|
-
@zk.block_until_node_deleted(@path)
|
93
|
-
rescue Exception => e
|
94
|
-
@exception = e
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
@zk.exists?(@path, :watch => true)
|
99
|
-
|
100
|
-
@zk.set(@path, 'blah')
|
101
|
-
|
102
|
-
wait_until(2) { @exception }.should be_kind_of(ZK::Exceptions::EventDispatchThreadException)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
it_should_behave_like 'locking and session death'
|
107
|
-
end
|
108
76
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZK::Client::Threaded do
|
4
|
+
include_context 'threaded client connection'
|
5
|
+
it_should_behave_like 'client'
|
6
|
+
|
7
|
+
describe :close! do
|
8
|
+
describe 'from a threadpool thread' do
|
9
|
+
it %[should do the right thing and not fail] do
|
10
|
+
# this is an extra special case where the user obviously hates us
|
11
|
+
|
12
|
+
@zk.should be_kind_of(ZK::Client::Threaded) # yeah yeah, just be sure
|
13
|
+
|
14
|
+
@zk.defer do
|
15
|
+
@zk.close!
|
16
|
+
end
|
17
|
+
|
18
|
+
wait_until { @zk.closed? }.should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
File without changes
|
File without changes
|
@@ -464,46 +464,6 @@ describe "ZK::Locker chrooted" do
|
|
464
464
|
it_should_behave_like 'ExclusiveLocker'
|
465
465
|
it_should_behave_like 'shared-exclusive interaction'
|
466
466
|
end
|
467
|
-
|
468
|
-
describe "when the root doesn't exist" do
|
469
|
-
let(:lock_name) { 'master' }
|
470
|
-
|
471
|
-
it %[should raise a NonExistentRootError] do
|
472
|
-
@got_lock = false
|
473
|
-
|
474
|
-
lambda do
|
475
|
-
zk.with_lock(lock_name) do
|
476
|
-
@got_lock = true
|
477
|
-
end
|
478
|
-
end.should raise_error(ZK::Exceptions::NonExistentRootError)
|
479
|
-
|
480
|
-
@got_lock.should_not be_true
|
481
|
-
end
|
482
|
-
end
|
483
467
|
end
|
484
468
|
|
485
|
-
describe 'ZK::Locker Multiplexed client', :client => :multiplexed do
|
486
|
-
let(:zk) { ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}") }
|
487
|
-
let(:zk2) { ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}") }
|
488
|
-
let(:zk3) { ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}") }
|
489
|
-
|
490
|
-
let(:connections) { [zk, zk2, zk3] }
|
491
|
-
|
492
|
-
let(:path) { "shlock" }
|
493
|
-
let(:root_lock_path) { "/_zklocking/#{path}" }
|
494
|
-
|
495
|
-
before do
|
496
|
-
wait_until{ connections.all?(&:connected?) }
|
497
|
-
# pending "Mutliplexed client locking is broken"
|
498
|
-
end
|
499
|
-
|
500
|
-
after do
|
501
|
-
connections.each { |c| c.close! }
|
502
|
-
wait_until { !connections.any?(&:connected?) }
|
503
|
-
end
|
504
|
-
|
505
|
-
it_should_behave_like 'SharedLocker'
|
506
|
-
it_should_behave_like 'ExclusiveLocker'
|
507
|
-
it_should_behave_like 'shared-exclusive interaction'
|
508
|
-
end # ZK::Locker
|
509
469
|
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# tests for the top-level module methods of ZK
|
4
|
+
|
5
|
+
describe ZK do
|
6
|
+
describe :new do
|
7
|
+
let(:chroot_path) { '/zktest/path/to/chroot' }
|
8
|
+
|
9
|
+
after do
|
10
|
+
mute_logger do
|
11
|
+
@zk.close! if @zk and not @zk.closed?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe %[with a chrooted connection string and a :chroot => '/path'] do
|
16
|
+
it %[should raise an ArgumentError] do
|
17
|
+
lambda { @zk = ZK.new('localhost:2181/zktest', :chroot => '/zktest') }.should raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'with no arguments' do
|
22
|
+
before { @zk = ZK.new }
|
23
|
+
|
24
|
+
it %[should create a default connection] do
|
25
|
+
@zk.should be_connected
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe %[with a chroot] do
|
30
|
+
before do
|
31
|
+
mute_logger do
|
32
|
+
@unchroot = ZK.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
mute_logger do
|
38
|
+
@unchroot.rm_rf('/zktest')
|
39
|
+
@unchroot.close! if @unchroot and not @unchroot.closed?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe %[that doesn't exist] do
|
44
|
+
before { @unchroot.rm_rf('/zktest') }
|
45
|
+
|
46
|
+
describe %[with no host and a :chroot => '/path' argument] do
|
47
|
+
before { @zk = ZK.new(:chroot => chroot_path) }
|
48
|
+
|
49
|
+
it %[should use the default connection string, create the chroot and return the connection] do
|
50
|
+
@zk.exists?('/').should be_true
|
51
|
+
@zk.create('/blah', 'data')
|
52
|
+
|
53
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe %[as a connection string] do
|
58
|
+
describe %[and no explicit option] do
|
59
|
+
before do
|
60
|
+
@zk = ZK.new("localhost:2181#{chroot_path}") # implicit create
|
61
|
+
end
|
62
|
+
|
63
|
+
it %[should create the chroot path and then return the connection] do
|
64
|
+
@zk.exists?('/').should be_true
|
65
|
+
@zk.create('/blah', 'data')
|
66
|
+
|
67
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe %[and an explicit :chroot => :create] do
|
72
|
+
before do
|
73
|
+
@zk = ZK.new("localhost:2181#{chroot_path}", :chroot => :create)
|
74
|
+
end
|
75
|
+
|
76
|
+
it %[should create the chroot path and then return the connection] do
|
77
|
+
@zk.exists?('/').should be_true
|
78
|
+
@zk.create('/blah', 'data')
|
79
|
+
|
80
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe %[and :chroot => :check] do
|
85
|
+
it %[should barf with a ChrootPathDoesNotExistError] do
|
86
|
+
lambda do
|
87
|
+
# assign in case of a bug, that way this connection will get torn down
|
88
|
+
@zk = ZK.new("localhost:2181#{chroot_path}", :chroot => :check)
|
89
|
+
end.should raise_error(ZK::Exceptions::ChrootPathDoesNotExistError)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe %[and :chroot => :do_nothing] do
|
94
|
+
it %[should return a connection in a weird state] do
|
95
|
+
@zk = ZK.new("localhost:2181#{chroot_path}", :chroot => :do_nothing)
|
96
|
+
lambda { @zk.get('/') }.should raise_error(ZK::Exceptions::NoNode)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe %[and :chroot => '/path'] do
|
101
|
+
before { @zk = ZK.new("localhost:2181", :chroot => chroot_path) }
|
102
|
+
|
103
|
+
it %[should create the chroot path and then return the connection] do
|
104
|
+
@zk.exists?('/').should be_true
|
105
|
+
@zk.create('/blah', 'data')
|
106
|
+
|
107
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end # as a connection string
|
111
|
+
end # that doesn't exist
|
112
|
+
|
113
|
+
describe %[that exists] do
|
114
|
+
before { @unchroot.mkdir_p(chroot_path) }
|
115
|
+
|
116
|
+
describe %[with no host and a :chroot => '/path' argument] do
|
117
|
+
before { @zk = ZK.new(:chroot => chroot_path) }
|
118
|
+
|
119
|
+
it %[should use the default connection string and totally work] do
|
120
|
+
@zk.exists?('/').should be_true
|
121
|
+
@zk.create('/blah', 'data')
|
122
|
+
|
123
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe %[as a connection string] do
|
128
|
+
describe %[and no explicit option] do
|
129
|
+
before do
|
130
|
+
@zk = ZK.new("localhost:2181#{chroot_path}") # implicit create
|
131
|
+
end
|
132
|
+
|
133
|
+
it %[should totally work] do
|
134
|
+
@zk.exists?('/').should be_true
|
135
|
+
@zk.create('/blah', 'data')
|
136
|
+
|
137
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe %[and an explicit :chroot => :create] do
|
142
|
+
before do
|
143
|
+
@zk = ZK.new("localhost:2181#{chroot_path}", :chroot => :create)
|
144
|
+
end
|
145
|
+
|
146
|
+
it %[should totally work] do
|
147
|
+
@zk.exists?('/').should be_true
|
148
|
+
@zk.create('/blah', 'data')
|
149
|
+
|
150
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe %[and :chroot => :check] do
|
155
|
+
it %[should totally work] do
|
156
|
+
lambda do
|
157
|
+
# assign in case of a bug, that way this connection will get torn down
|
158
|
+
@zk = ZK.new("localhost:2181#{chroot_path}", :chroot => :check)
|
159
|
+
end.should_not raise_error
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe %[and :chroot => :do_nothing] do
|
164
|
+
it %[should totally work] do
|
165
|
+
@zk = ZK.new("localhost:2181#{chroot_path}", :chroot => :do_nothing)
|
166
|
+
lambda { @zk.get('/') }.should_not raise_error
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe %[and :chroot => '/path'] do
|
171
|
+
before { @zk = ZK.new("localhost:2181", :chroot => chroot_path) }
|
172
|
+
|
173
|
+
it %[should totally work] do
|
174
|
+
@zk.exists?('/').should be_true
|
175
|
+
@zk.create('/blah', 'data')
|
176
|
+
|
177
|
+
@unchroot.get("#{chroot_path}/blah").first.should == 'data'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end # as a connection string
|
181
|
+
end # that exists
|
182
|
+
end # with a chroot
|
183
|
+
end # :new
|
184
|
+
end # ZK
|
185
|
+
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ZK::Threadpool do
|
4
|
-
|
5
4
|
before do
|
6
5
|
@threadpool = ZK::Threadpool.new
|
7
6
|
end
|
@@ -20,7 +19,6 @@ describe ZK::Threadpool do
|
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
22
|
describe :defer do
|
25
23
|
it %[should run the given block on a thread in the threadpool] do
|
26
24
|
@th = nil
|
@@ -39,9 +37,28 @@ describe ZK::Threadpool do
|
|
39
37
|
lambda { @threadpool.defer(bad_obj) }.should raise_error(ArgumentError)
|
40
38
|
end
|
41
39
|
|
42
|
-
it %[should barf if the threadpool is not running] do
|
40
|
+
it %[should not barf if the threadpool is not running] do
|
43
41
|
@threadpool.shutdown
|
44
|
-
lambda { @threadpool.defer { "hai!" } }.
|
42
|
+
lambda { @threadpool.defer { "hai!" } }.should_not raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe :on_exception do
|
47
|
+
it %[should register a callback that will be called if an exception is raised on the threadpool] do
|
48
|
+
@ary = []
|
49
|
+
|
50
|
+
@threadpool.on_exception { |exc| @ary << exc }
|
51
|
+
|
52
|
+
@threadpool.defer { raise "ZOMG!" }
|
53
|
+
|
54
|
+
wait_while(2) { @ary.empty? }
|
55
|
+
|
56
|
+
@ary.length.should == 1
|
57
|
+
|
58
|
+
e = @ary.shift
|
59
|
+
|
60
|
+
e.should be_kind_of(RuntimeError)
|
61
|
+
e.message.should == 'ZOMG!'
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|
@@ -70,5 +87,16 @@ describe ZK::Threadpool do
|
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
90
|
+
describe :on_threadpool? do
|
91
|
+
it %[should return true if we're currently executing on one of the threadpool threads] do
|
92
|
+
@a = []
|
93
|
+
@threadpool.defer { @a << @threadpool.on_threadpool? }
|
94
|
+
|
95
|
+
wait_while(2) { @a.empty? }
|
96
|
+
@a.should_not be_empty
|
97
|
+
|
98
|
+
@a.first.should be_true
|
99
|
+
end
|
100
|
+
end
|
73
101
|
end
|
74
102
|
|
data/spec/zookeeper_spec.rb
CHANGED
@@ -117,12 +117,7 @@ shared_examples_for 'ZK basic' do
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
describe 'basic
|
121
|
-
include_context 'multiplexed client connection'
|
122
|
-
it_should_behave_like 'ZK basic'
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'basic threaded', :client => :threaded do
|
120
|
+
describe 'basic threaded', :threaded => true do
|
126
121
|
include_context 'threaded client connection'
|
127
122
|
it_should_behave_like 'ZK basic'
|
128
123
|
end
|
data/zk.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "zk/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "zk"
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{A high-level wrapper around the zookeeper driver}
|
13
13
|
s.description = s.summary + "\n"
|
14
14
|
|
15
|
-
s.add_runtime_dependency 'slyphon-zookeeper', '~> 0.
|
15
|
+
s.add_runtime_dependency 'slyphon-zookeeper', '~> 0.9.2'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|