slyphon-zookeeper 0.3.0-java → 0.8.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/Rakefile +25 -5
- data/ext/c_zookeeper.rb +214 -0
- data/ext/dbg.h +18 -2
- data/ext/depend +1 -2
- data/ext/zookeeper_base.rb +73 -99
- data/ext/zookeeper_c.c +52 -41
- data/ext/zookeeper_lib.c +90 -78
- data/ext/zookeeper_lib.h +0 -1
- data/java/zookeeper_base.rb +72 -154
- data/lib/zookeeper/common/queue_with_pipe.rb +78 -0
- data/lib/zookeeper/common.rb +73 -9
- data/lib/zookeeper/constants.rb +28 -0
- data/lib/zookeeper/em_client.rb +13 -138
- data/lib/zookeeper/exceptions.rb +4 -1
- data/lib/zookeeper.rb +51 -15
- data/slyphon-zookeeper.gemspec +1 -1
- data/spec/c_zookeeper_spec.rb +50 -0
- data/spec/chrooted_connection_spec.rb +121 -0
- data/spec/em_spec.rb +0 -61
- data/spec/shared/all_success_return_values.rb +10 -0
- data/spec/shared/connection_examples.rb +1007 -0
- data/spec/spec_helper.rb +42 -19
- data/spec/zookeeper_spec.rb +8 -1033
- metadata +16 -6
data/spec/zookeeper_spec.rb
CHANGED
@@ -1,1049 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared/connection_examples'
|
2
3
|
|
3
|
-
shared_examples_for "all success return values" do
|
4
|
-
it %[should have a return code of Zookeeper::ZOK] do
|
5
|
-
@rv[:rc].should == Zookeeper::ZOK
|
6
|
-
end
|
7
|
-
|
8
|
-
it %[should have a req_id integer] do
|
9
|
-
@rv[:req_id].should be_kind_of(Integer)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
shared_examples_for "all" do
|
14
|
-
def ensure_node(path, data)
|
15
|
-
if zk.stat(:path => path)[:stat].exists?
|
16
|
-
zk.set(:path => path, :data => data)
|
17
|
-
else
|
18
|
-
zk.create(:path => path, :data => data)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
before :each do
|
23
|
-
ensure_node(path, data)
|
24
|
-
end
|
25
|
-
|
26
|
-
after :each do
|
27
|
-
ensure_node(path, data)
|
28
|
-
end
|
29
|
-
|
30
|
-
after :all do
|
31
|
-
Zookeeper.logger.warn "running shared examples after :all"
|
32
|
-
# close the chrooted connection
|
33
|
-
zk.delete(:path => path)
|
34
|
-
zk.close
|
35
|
-
|
36
|
-
wait_until do
|
37
|
-
begin
|
38
|
-
!zk.connected?
|
39
|
-
rescue RuntimeError
|
40
|
-
true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# unfortunately, we can't test w/o exercising other parts of the driver, so
|
46
|
-
# if "set" is broken, this test will fail as well (but whaddyagonnado?)
|
47
|
-
describe :get do
|
48
|
-
describe :sync do
|
49
|
-
it_should_behave_like "all success return values"
|
50
|
-
|
51
|
-
before do
|
52
|
-
@rv = zk.get(:path => path)
|
53
|
-
end
|
54
|
-
|
55
|
-
it %[should return the data] do
|
56
|
-
@rv[:data].should == data
|
57
|
-
end
|
58
|
-
|
59
|
-
it %[should return a stat] do
|
60
|
-
@rv[:stat].should_not be_nil
|
61
|
-
@rv[:stat].should be_kind_of(ZookeeperStat::Stat)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe :sync_watch do
|
66
|
-
it_should_behave_like "all success return values"
|
67
|
-
|
68
|
-
before do
|
69
|
-
@event = nil
|
70
|
-
@watcher = Zookeeper::WatcherCallback.new
|
71
|
-
|
72
|
-
@rv = zk.get(:path => path, :watcher => @watcher, :watcher_context => path)
|
73
|
-
end
|
74
|
-
|
75
|
-
it %[should return the data] do
|
76
|
-
@rv[:data].should == data
|
77
|
-
end
|
78
|
-
|
79
|
-
it %[should set a watcher on the node] do
|
80
|
-
# test the watcher by changing node data
|
81
|
-
zk.set(:path => path, :data => 'blah')[:rc].should be_zero
|
82
|
-
|
83
|
-
wait_until(1.0) { @watcher.completed? }
|
84
|
-
|
85
|
-
@watcher.path.should == path
|
86
|
-
@watcher.context.should == path
|
87
|
-
@watcher.should be_completed
|
88
|
-
@watcher.type.should == Zookeeper::ZOO_CHANGED_EVENT
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe :async do
|
93
|
-
before do
|
94
|
-
@cb = Zookeeper::DataCallback.new
|
95
|
-
|
96
|
-
@rv = zk.get(:path => path, :callback => @cb, :callback_context => path)
|
97
|
-
wait_until(1.0) { @cb.completed? }
|
98
|
-
@cb.should be_completed
|
99
|
-
end
|
100
|
-
|
101
|
-
it_should_behave_like "all success return values"
|
102
|
-
|
103
|
-
it %[should have a return code of ZOK] do
|
104
|
-
@cb.return_code.should == Zookeeper::ZOK
|
105
|
-
end
|
106
|
-
|
107
|
-
it %[should have the stat object in the callback] do
|
108
|
-
@cb.stat.should_not be_nil
|
109
|
-
@cb.stat.should be_kind_of(ZookeeperStat::Stat)
|
110
|
-
end
|
111
|
-
|
112
|
-
it %[should have the data] do
|
113
|
-
@cb.data.should == data
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe :async_watch do
|
118
|
-
it_should_behave_like "all success return values"
|
119
|
-
|
120
|
-
before do
|
121
|
-
@cb = Zookeeper::DataCallback.new
|
122
|
-
@watcher = Zookeeper::WatcherCallback.new
|
123
|
-
|
124
|
-
@rv = zk.get(:path => path, :callback => @cb, :callback_context => path, :watcher => @watcher, :watcher_context => path)
|
125
|
-
wait_until(1.0) { @cb.completed? }
|
126
|
-
@cb.should be_completed
|
127
|
-
end
|
128
|
-
|
129
|
-
it %[should have the stat object in the callback] do
|
130
|
-
@cb.stat.should_not be_nil
|
131
|
-
@cb.stat.should be_kind_of(ZookeeperStat::Stat)
|
132
|
-
end
|
133
|
-
|
134
|
-
it %[should have the data] do
|
135
|
-
@cb.data.should == data
|
136
|
-
end
|
137
|
-
|
138
|
-
it %[should have a return code of ZOK] do
|
139
|
-
@cb.return_code.should == Zookeeper::ZOK
|
140
|
-
end
|
141
|
-
|
142
|
-
it %[should set a watcher on the node] do
|
143
|
-
zk.set(:path => path, :data => 'blah')[:rc].should be_zero
|
144
|
-
|
145
|
-
wait_until(2) { @watcher.completed? }
|
146
|
-
|
147
|
-
@watcher.should be_completed
|
148
|
-
|
149
|
-
@watcher.path.should == path
|
150
|
-
@watcher.context.should == path
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe 'bad arguments' do
|
155
|
-
it %[should barf with a BadArguments error] do
|
156
|
-
lambda { zk.get(:bad_arg => 'what!?') }.should raise_error(ZookeeperExceptions::ZookeeperException::BadArguments)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end # get
|
160
|
-
|
161
|
-
describe :set do
|
162
|
-
before do
|
163
|
-
@new_data = "Four score and \007 years ago"
|
164
|
-
@stat = zk.stat(:path => path)[:stat]
|
165
|
-
end
|
166
|
-
|
167
|
-
describe :sync do
|
168
|
-
describe 'without version' do
|
169
|
-
it_should_behave_like "all success return values"
|
170
|
-
|
171
|
-
before do
|
172
|
-
@rv = zk.set(:path => path, :data => @new_data)
|
173
|
-
end
|
174
|
-
|
175
|
-
it %[should return the new stat] do
|
176
|
-
@rv[:stat].should_not be_nil
|
177
|
-
@rv[:stat].should be_kind_of(ZookeeperStat::Stat)
|
178
|
-
@rv[:stat].version.should > @stat.version
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe 'with current version' do
|
183
|
-
it_should_behave_like "all success return values"
|
184
|
-
|
185
|
-
before do
|
186
|
-
@rv = zk.set(:path => path, :data => @new_data, :version => @stat.version)
|
187
|
-
end
|
188
|
-
|
189
|
-
it %[should return the new stat] do
|
190
|
-
@rv[:stat].should_not be_nil
|
191
|
-
@rv[:stat].should be_kind_of(ZookeeperStat::Stat)
|
192
|
-
@rv[:stat].version.should > @stat.version
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
describe 'with outdated version' do
|
197
|
-
before do
|
198
|
-
# need to do a couple of sets to ramp up the version
|
199
|
-
3.times { |n| @stat = zk.set(:path => path, :data => "#{@new_data}#{n}")[:stat] }
|
200
|
-
|
201
|
-
@rv = zk.set(:path => path, :data => @new_data, :version => 0)
|
202
|
-
end
|
203
|
-
|
204
|
-
it %[should have a return code of ZBADVERSION] do
|
205
|
-
@rv[:rc].should == Zookeeper::ZBADVERSION
|
206
|
-
end
|
207
|
-
|
208
|
-
it %[should return a stat with !exists] do
|
209
|
-
@rv[:stat].exists.should be_false
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe 'error' do
|
214
|
-
it %[should barf if the data size is too large], :input_size => true do
|
215
|
-
large_data = '0' * (1024 ** 2)
|
216
|
-
|
217
|
-
lambda { zk.set(:path => path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end # sync
|
221
|
-
|
222
|
-
describe :async do
|
223
|
-
before do
|
224
|
-
@cb = Zookeeper::StatCallback.new
|
225
|
-
end
|
226
|
-
|
227
|
-
describe 'without version' do
|
228
|
-
it_should_behave_like "all success return values"
|
229
|
-
|
230
|
-
before do
|
231
|
-
@rv = zk.set(:path => path, :data => @new_data, :callback => @cb, :callback_context => path)
|
232
|
-
|
233
|
-
wait_until(2) { @cb.completed? }
|
234
|
-
@cb.should be_completed
|
235
|
-
end
|
236
|
-
|
237
|
-
it %[should have the stat in the callback] do
|
238
|
-
@cb.stat.should_not be_nil
|
239
|
-
@cb.stat.version.should > @stat.version
|
240
|
-
end
|
241
|
-
|
242
|
-
it %[should have a return code of ZOK] do
|
243
|
-
@cb.return_code.should == Zookeeper::ZOK
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe 'with current version' do
|
248
|
-
it_should_behave_like "all success return values"
|
249
|
-
|
250
|
-
before do
|
251
|
-
@rv = zk.set(:path => path, :data => @new_data, :callback => @cb, :callback_context => path, :version => @stat.version)
|
252
|
-
|
253
|
-
wait_until(2) { @cb.completed? }
|
254
|
-
@cb.should be_completed
|
255
|
-
end
|
256
|
-
|
257
|
-
it %[should have the stat in the callback] do
|
258
|
-
@cb.stat.should_not be_nil
|
259
|
-
@cb.stat.version.should > @stat.version
|
260
|
-
end
|
261
|
-
|
262
|
-
it %[should have a return code of ZOK] do
|
263
|
-
@cb.return_code.should == Zookeeper::ZOK
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
describe 'with outdated version' do
|
268
|
-
before do
|
269
|
-
# need to do a couple of sets to ramp up the version
|
270
|
-
3.times { |n| @stat = zk.set(:path => path, :data => "#{@new_data}#{n}")[:stat] }
|
271
|
-
|
272
|
-
@rv = zk.set(:path => path, :data => @new_data, :callback => @cb, :callback_context => path, :version => 0)
|
273
|
-
|
274
|
-
wait_until(2) { @cb.completed? }
|
275
|
-
@cb.should be_completed
|
276
|
-
end
|
277
|
-
|
278
|
-
it %[should have a return code of ZBADVERSION] do
|
279
|
-
@cb.return_code.should == Zookeeper::ZBADVERSION
|
280
|
-
end
|
281
|
-
|
282
|
-
it %[should return a stat with !exists] do
|
283
|
-
@cb.stat.exists.should be_false
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
describe 'error' do
|
288
|
-
it %[should barf if the data size is too large], :input_size => true do
|
289
|
-
large_data = '0' * (1024 ** 2)
|
290
|
-
|
291
|
-
lambda { zk.set(:path => path, :data => large_data, :callback => @cb, :callback_context => path) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
end # async
|
296
|
-
end # set
|
297
|
-
|
298
|
-
describe :get_children do
|
299
|
-
before do
|
300
|
-
@children = %w[child0 child1 child2]
|
301
|
-
|
302
|
-
@children.each do |name|
|
303
|
-
zk.create(:path => "#{path}/#{name}", :data => name)
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
after do
|
308
|
-
@children.each do |name|
|
309
|
-
zk.delete(:path => "#{path}/#{name}")
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
describe :sync do
|
314
|
-
it_should_behave_like "all success return values"
|
315
|
-
|
316
|
-
before do
|
317
|
-
@rv = zk.get_children(:path => path)
|
318
|
-
end
|
319
|
-
|
320
|
-
it %[should have an array of names of the children] do
|
321
|
-
@rv[:children].should be_kind_of(Array)
|
322
|
-
@rv[:children].length.should == 3
|
323
|
-
@rv[:children].sort.should == @children.sort
|
324
|
-
end
|
325
|
-
|
326
|
-
# "Three shall be the number of the counting, and the number of the counting shall be 3"
|
327
|
-
|
328
|
-
it %[should have a stat object whose num_children is 3] do
|
329
|
-
@rv[:stat].should_not be_nil
|
330
|
-
@rv[:stat].should be_kind_of(ZookeeperStat::Stat)
|
331
|
-
@rv[:stat].num_children.should == 3
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
describe :sync_watch do
|
336
|
-
it_should_behave_like "all success return values"
|
337
|
-
|
338
|
-
before do
|
339
|
-
@addtl_child = 'child3'
|
340
|
-
|
341
|
-
@watcher = Zookeeper::WatcherCallback.new
|
342
|
-
|
343
|
-
@rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path)
|
344
|
-
end
|
345
|
-
|
346
|
-
after do
|
347
|
-
zk.delete(:path => "#{path}/#{@addtl_child}")
|
348
|
-
end
|
349
|
-
|
350
|
-
it %[should have an array of names of the children] do
|
351
|
-
@rv[:children].should be_kind_of(Array)
|
352
|
-
@rv[:children].length.should == 3
|
353
|
-
@rv[:children].sort.should == @children.sort
|
354
|
-
end
|
355
|
-
|
356
|
-
it %[should have a stat object whose num_children is 3] do
|
357
|
-
@rv[:stat].should_not be_nil
|
358
|
-
@rv[:stat].should be_kind_of(ZookeeperStat::Stat)
|
359
|
-
@rv[:stat].num_children.should == 3
|
360
|
-
end
|
361
|
-
|
362
|
-
it %[should set a watcher for children on the node] do
|
363
|
-
@watcher.should_not be_completed
|
364
|
-
|
365
|
-
zk.create(:path => "#{path}/#{@addtl_child}", :data => '')[:rc].should == Zookeeper::ZOK
|
366
|
-
|
367
|
-
wait_until { @watcher.completed? }
|
368
|
-
@watcher.should be_completed
|
369
|
-
|
370
|
-
@watcher.path.should == path
|
371
|
-
@watcher.context.should == path
|
372
|
-
@watcher.type.should == Zookeeper::ZOO_CHILD_EVENT
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
describe :async do
|
377
|
-
it_should_behave_like "all success return values"
|
378
|
-
|
379
|
-
before do
|
380
|
-
@cb = ZookeeperCallbacks::StringsCallback.new
|
381
|
-
@rv = zk.get_children(:path => path, :callback => @cb, :callback_context => path)
|
382
|
-
|
383
|
-
wait_until { @cb.completed? }
|
384
|
-
@cb.should be_completed
|
385
|
-
end
|
386
|
-
|
387
|
-
it %[should succeed] do
|
388
|
-
@cb.return_code.should == Zookeeper::ZOK
|
389
|
-
end
|
390
|
-
|
391
|
-
it %[should return an array of children] do
|
392
|
-
@cb.children.should be_kind_of(Array)
|
393
|
-
@cb.children.length.should == 3
|
394
|
-
@cb.children.sort.should == @children.sort
|
395
|
-
end
|
396
|
-
|
397
|
-
it %[should have a stat object whose num_children is 3] do
|
398
|
-
@cb.stat.should_not be_nil
|
399
|
-
@cb.stat.should be_kind_of(ZookeeperStat::Stat)
|
400
|
-
@cb.stat.num_children.should == 3
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
describe :async_watch do
|
405
|
-
it_should_behave_like "all success return values"
|
406
|
-
|
407
|
-
before do
|
408
|
-
@addtl_child = 'child3'
|
409
|
-
|
410
|
-
@watcher = Zookeeper::WatcherCallback.new
|
411
|
-
@cb = ZookeeperCallbacks::StringsCallback.new
|
412
|
-
|
413
|
-
@rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path, :callback => @cb, :callback_context => path)
|
414
|
-
wait_until { @cb.completed? }
|
415
|
-
@cb.should be_completed
|
416
|
-
end
|
417
|
-
|
418
|
-
after do
|
419
|
-
zk.delete(:path => "#{path}/#{@addtl_child}")
|
420
|
-
end
|
421
|
-
|
422
|
-
it %[should succeed] do
|
423
|
-
@cb.return_code.should == Zookeeper::ZOK
|
424
|
-
end
|
425
|
-
|
426
|
-
it %[should return an array of children] do
|
427
|
-
@cb.children.should be_kind_of(Array)
|
428
|
-
@cb.children.length.should == 3
|
429
|
-
@cb.children.sort.should == @children.sort
|
430
|
-
end
|
431
|
-
|
432
|
-
it %[should have a stat object whose num_children is 3] do
|
433
|
-
@cb.stat.should_not be_nil
|
434
|
-
@cb.stat.should be_kind_of(ZookeeperStat::Stat)
|
435
|
-
@cb.stat.num_children.should == 3
|
436
|
-
end
|
437
|
-
|
438
|
-
it %[should set a watcher for children on the node] do
|
439
|
-
@watcher.should_not be_completed
|
440
|
-
|
441
|
-
zk.create(:path => "#{path}/#{@addtl_child}", :data => '')[:rc].should == Zookeeper::ZOK
|
442
|
-
|
443
|
-
wait_until { @watcher.completed? }
|
444
|
-
@watcher.should be_completed
|
445
|
-
|
446
|
-
@watcher.path.should == path
|
447
|
-
@watcher.context.should == path
|
448
|
-
@watcher.type.should == Zookeeper::ZOO_CHILD_EVENT
|
449
|
-
end
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
# NOTE: the jruby version of stat on non-existent node will have a
|
454
|
-
# return_code of 0, but the C version will have a return_code of -101
|
455
|
-
describe :stat do
|
456
|
-
describe :sync do
|
457
|
-
it_should_behave_like "all success return values"
|
458
|
-
|
459
|
-
before do
|
460
|
-
@rv = zk.stat(:path => path)
|
461
|
-
end
|
462
|
-
|
463
|
-
it %[should have a stat object] do
|
464
|
-
@rv[:stat].should be_kind_of(Zookeeper::Stat)
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
describe :sync_watch do
|
469
|
-
it_should_behave_like "all success return values"
|
470
|
-
|
471
|
-
before do
|
472
|
-
@watcher = Zookeeper::WatcherCallback.new
|
473
|
-
|
474
|
-
@rv = zk.stat(:path => path, :watcher => @watcher, :watcher_context => path)
|
475
|
-
end
|
476
|
-
|
477
|
-
it %[should have a stat object] do
|
478
|
-
@rv[:stat].should be_kind_of(Zookeeper::Stat)
|
479
|
-
end
|
480
|
-
|
481
|
-
it %[should set a watcher for data changes on the node] do
|
482
|
-
@watcher.should_not be_completed
|
483
|
-
|
484
|
-
zk.set(:path => path, :data => 'skunk')[:rc].should == Zookeeper::ZOK
|
485
|
-
|
486
|
-
wait_until { @watcher.completed? }
|
487
|
-
@watcher.should be_completed
|
488
|
-
|
489
|
-
@watcher.path.should == path
|
490
|
-
@watcher.context.should == path
|
491
|
-
@watcher.type.should == Zookeeper::ZOO_CHANGED_EVENT
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
describe :async do
|
496
|
-
it_should_behave_like "all success return values"
|
497
|
-
|
498
|
-
before do
|
499
|
-
@cb = ZookeeperCallbacks::StatCallback.new
|
500
|
-
@rv = zk.stat(:path => path, :callback => @cb, :callback_context => path)
|
501
|
-
|
502
|
-
wait_until { @cb.completed? }
|
503
|
-
@cb.should be_completed
|
504
|
-
end
|
505
|
-
|
506
|
-
it %[should succeed] do
|
507
|
-
@cb.return_code.should == Zookeeper::ZOK
|
508
|
-
end
|
509
|
-
|
510
|
-
it %[should have a stat object] do
|
511
|
-
@cb.stat.should be_kind_of(Zookeeper::Stat)
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
515
|
-
describe :async_watch do
|
516
|
-
it_should_behave_like "all success return values"
|
517
|
-
|
518
|
-
before do
|
519
|
-
@addtl_child = 'child3'
|
520
|
-
|
521
|
-
@watcher = Zookeeper::WatcherCallback.new
|
522
|
-
|
523
|
-
@cb = ZookeeperCallbacks::StatCallback.new
|
524
|
-
@rv = zk.stat(:path => path, :callback => @cb, :callback_context => path, :watcher => @watcher, :watcher_context => path)
|
525
|
-
|
526
|
-
wait_until { @cb.completed? }
|
527
|
-
@cb.should be_completed
|
528
|
-
end
|
529
|
-
|
530
|
-
after do
|
531
|
-
zk.delete(:path => "#{path}/#{@addtl_child}")
|
532
|
-
end
|
533
|
-
|
534
|
-
it %[should succeed] do
|
535
|
-
@cb.return_code.should == Zookeeper::ZOK
|
536
|
-
end
|
537
|
-
|
538
|
-
it %[should have a stat object] do
|
539
|
-
@cb.stat.should be_kind_of(Zookeeper::Stat)
|
540
|
-
end
|
541
|
-
|
542
|
-
it %[should set a watcher for data changes on the node] do
|
543
|
-
@watcher.should_not be_completed
|
544
|
-
|
545
|
-
zk.set(:path => path, :data => 'skunk')[:rc].should == Zookeeper::ZOK
|
546
|
-
|
547
|
-
wait_until { @watcher.completed? }
|
548
|
-
@watcher.should be_completed
|
549
|
-
|
550
|
-
@watcher.path.should == path
|
551
|
-
@watcher.context.should == path
|
552
|
-
@watcher.type.should == Zookeeper::ZOO_CHANGED_EVENT
|
553
|
-
end
|
554
|
-
end
|
555
|
-
end # stat
|
556
|
-
|
557
|
-
describe :create do
|
558
|
-
before do
|
559
|
-
# remove the path set up by the global 'before' block
|
560
|
-
zk.delete(:path => path)
|
561
|
-
end
|
562
|
-
|
563
|
-
describe :sync do
|
564
|
-
describe 'error' do
|
565
|
-
it %[should barf if the data size is too large], :input_size => true do
|
566
|
-
large_data = '0' * (1024 ** 2)
|
567
|
-
|
568
|
-
lambda { zk.create(:path => path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
describe :default_flags do
|
573
|
-
it_should_behave_like "all success return values"
|
574
|
-
|
575
|
-
before do
|
576
|
-
@rv = zk.create(:path => path)
|
577
|
-
end
|
578
|
-
|
579
|
-
it %[should return the path that was set] do
|
580
|
-
@rv[:path].should == path
|
581
|
-
end
|
582
|
-
|
583
|
-
it %[should have created a permanent node] do
|
584
|
-
st = zk.stat(:path => path)
|
585
|
-
st[:rc].should == Zookeeper::ZOK
|
586
|
-
|
587
|
-
st[:stat].ephemeral_owner.should == 0
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
describe :ephemeral do
|
592
|
-
it_should_behave_like "all success return values"
|
593
|
-
|
594
|
-
before do
|
595
|
-
@rv = zk.create(:path => path, :ephemeral => true)
|
596
|
-
end
|
597
|
-
|
598
|
-
it %[should return the path that was set] do
|
599
|
-
@rv[:path].should == path
|
600
|
-
end
|
601
|
-
|
602
|
-
it %[should have created a ephemeral node] do
|
603
|
-
st = zk.stat(:path => path)
|
604
|
-
st[:rc].should == Zookeeper::ZOK
|
605
|
-
|
606
|
-
st[:stat].ephemeral_owner.should_not be_zero
|
607
|
-
end
|
608
|
-
end
|
609
|
-
|
610
|
-
describe :sequence do
|
611
|
-
it_should_behave_like "all success return values"
|
612
|
-
|
613
|
-
before do
|
614
|
-
@orig_path = path
|
615
|
-
@rv = zk.create(:path => path, :sequence => true)
|
616
|
-
@s_path = @rv[:path] # make sure this gets cleaned up
|
617
|
-
end
|
618
|
-
|
619
|
-
after do
|
620
|
-
zk.delete(:path => @s_path)
|
621
|
-
end
|
622
|
-
|
623
|
-
it %[should return the path that was set] do
|
624
|
-
@rv[:path].should_not == @orig_path
|
625
|
-
end
|
626
|
-
|
627
|
-
it %[should have created a permanent node] do
|
628
|
-
st = zk.stat(:path => @s_path)
|
629
|
-
st[:rc].should == Zookeeper::ZOK
|
630
|
-
|
631
|
-
st[:stat].ephemeral_owner.should be_zero
|
632
|
-
end
|
633
|
-
end
|
634
|
-
|
635
|
-
describe :ephemeral_sequence do
|
636
|
-
it_should_behave_like "all success return values"
|
637
|
-
|
638
|
-
before do
|
639
|
-
@orig_path = path
|
640
|
-
@rv = zk.create(:path => path, :sequence => true, :ephemeral => true)
|
641
|
-
@s_path = @rv[:path] # make sure this gets cleaned up
|
642
|
-
end
|
643
|
-
|
644
|
-
after do
|
645
|
-
zk.delete(:path => @s_path)
|
646
|
-
end
|
647
|
-
|
648
|
-
it %[should return the path that was set] do
|
649
|
-
@rv[:path].should_not == @orig_path
|
650
|
-
end
|
651
|
-
|
652
|
-
it %[should have created an ephemeral node] do
|
653
|
-
st = zk.stat(:path => @s_path)
|
654
|
-
st[:rc].should == Zookeeper::ZOK
|
655
|
-
|
656
|
-
st[:stat].ephemeral_owner.should_not be_zero
|
657
|
-
end
|
658
|
-
end
|
659
|
-
|
660
|
-
describe :acl do
|
661
|
-
it %[should work] do
|
662
|
-
pending "need to write acl tests"
|
663
|
-
end
|
664
|
-
end
|
665
|
-
end
|
666
|
-
|
667
|
-
describe :async do
|
668
|
-
before do
|
669
|
-
@cb = ZookeeperCallbacks::StringCallback.new
|
670
|
-
end
|
671
|
-
|
672
|
-
describe :default_flags do
|
673
|
-
it_should_behave_like "all success return values"
|
674
|
-
|
675
|
-
before do
|
676
|
-
@rv = zk.create(:path => path, :callback => @cb, :callback_context => path)
|
677
|
-
wait_until(2) { @cb.completed? }
|
678
|
-
@cb.should be_completed
|
679
|
-
end
|
680
|
-
|
681
|
-
it %[should have a path] do
|
682
|
-
@cb.path.should_not be_nil
|
683
|
-
end
|
684
|
-
|
685
|
-
it %[should return the path that was set] do
|
686
|
-
@cb.path.should == path
|
687
|
-
end
|
688
|
-
|
689
|
-
it %[should have created a permanent node] do
|
690
|
-
st = zk.stat(:path => path)
|
691
|
-
st[:rc].should == Zookeeper::ZOK
|
692
|
-
|
693
|
-
st[:stat].ephemeral_owner.should == 0
|
694
|
-
end
|
695
|
-
end
|
696
|
-
|
697
|
-
describe 'error' do
|
698
|
-
it %[should barf if the data size is too large], :input_size => true do
|
699
|
-
large_data = '0' * (1024 ** 2)
|
700
|
-
|
701
|
-
lambda do
|
702
|
-
zk.create(:path => path, :data => large_data, :callback => @cb, :callback_context => path)
|
703
|
-
end.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
|
704
|
-
end
|
705
|
-
end
|
706
|
-
|
707
|
-
|
708
|
-
describe :ephemeral do
|
709
|
-
it_should_behave_like "all success return values"
|
710
|
-
|
711
|
-
before do
|
712
|
-
@rv = zk.create(:path => path, :ephemeral => true, :callback => @cb, :callback_context => path)
|
713
|
-
wait_until(2) { @cb.completed? }
|
714
|
-
@cb.should be_completed
|
715
|
-
end
|
716
|
-
|
717
|
-
it %[should have a path] do
|
718
|
-
@cb.path.should_not be_nil
|
719
|
-
end
|
720
|
-
|
721
|
-
it %[should return the path that was set] do
|
722
|
-
@cb.path.should == path
|
723
|
-
end
|
724
|
-
|
725
|
-
it %[should have created a ephemeral node] do
|
726
|
-
st = zk.stat(:path => path)
|
727
|
-
st[:rc].should == Zookeeper::ZOK
|
728
|
-
|
729
|
-
st[:stat].ephemeral_owner.should_not be_zero
|
730
|
-
end
|
731
|
-
end
|
732
|
-
|
733
|
-
describe :sequence do
|
734
|
-
it_should_behave_like "all success return values"
|
735
|
-
|
736
|
-
before do
|
737
|
-
@orig_path = path
|
738
|
-
@rv = zk.create(:path => path, :sequence => true, :callback => @cb, :callback_context => path)
|
739
|
-
|
740
|
-
wait_until(2) { @cb.completed? }
|
741
|
-
@cb.should be_completed
|
742
|
-
|
743
|
-
@s_path = @cb.path
|
744
|
-
end
|
745
|
-
|
746
|
-
after do
|
747
|
-
zk.delete(:path => @s_path)
|
748
|
-
end
|
749
|
-
|
750
|
-
it %[should have a path] do
|
751
|
-
@cb.path.should_not be_nil
|
752
|
-
end
|
753
|
-
|
754
|
-
it %[should return the path that was set] do
|
755
|
-
@cb.path.should_not == @orig_path
|
756
|
-
end
|
757
|
-
|
758
|
-
it %[should have created a permanent node] do
|
759
|
-
st = zk.stat(:path => @s_path)
|
760
|
-
st[:rc].should == Zookeeper::ZOK
|
761
|
-
|
762
|
-
st[:stat].ephemeral_owner.should be_zero
|
763
|
-
end
|
764
|
-
end
|
765
|
-
|
766
|
-
describe :ephemeral_sequence do
|
767
|
-
it_should_behave_like "all success return values"
|
768
|
-
|
769
|
-
before do
|
770
|
-
@orig_path = path
|
771
|
-
@rv = zk.create(:path => path, :sequence => true, :ephemeral => true, :callback => @cb, :callback_context => path)
|
772
|
-
path = @rv[:path] # make sure this gets cleaned up
|
773
|
-
|
774
|
-
wait_until(2) { @cb.completed? }
|
775
|
-
@cb.should be_completed
|
776
|
-
@s_path = @cb.path
|
777
|
-
end
|
778
|
-
|
779
|
-
after do
|
780
|
-
zk.delete(:path => @s_path)
|
781
|
-
end
|
782
|
-
|
783
|
-
it %[should have a path] do
|
784
|
-
@cb.path.should_not be_nil
|
785
|
-
end
|
786
|
-
|
787
|
-
it %[should return the path that was set] do
|
788
|
-
@s_path.should_not == @orig_path
|
789
|
-
end
|
790
|
-
|
791
|
-
it %[should have created an ephemeral node] do
|
792
|
-
st = zk.stat(:path => @s_path)
|
793
|
-
st[:rc].should == Zookeeper::ZOK
|
794
|
-
|
795
|
-
st[:stat].ephemeral_owner.should_not be_zero
|
796
|
-
end
|
797
|
-
end # ephemeral_sequence
|
798
|
-
end # async
|
799
|
-
end # create
|
800
|
-
|
801
|
-
describe :delete do
|
802
|
-
describe :sync do
|
803
|
-
describe 'without version' do
|
804
|
-
it_should_behave_like "all success return values"
|
805
|
-
|
806
|
-
before do
|
807
|
-
zk.create(:path => path)
|
808
|
-
@rv = zk.delete(:path => path)
|
809
|
-
end
|
810
|
-
|
811
|
-
it %[should have deleted the node] do
|
812
|
-
zk.stat(:path => path)[:stat].exists.should be_false
|
813
|
-
end
|
814
|
-
end
|
815
|
-
|
816
|
-
describe 'with current version' do
|
817
|
-
it_should_behave_like "all success return values"
|
818
|
-
|
819
|
-
before do
|
820
|
-
zk.create(:path => path)
|
821
|
-
|
822
|
-
@stat = zk.stat(:path => path)[:stat]
|
823
|
-
@stat.exists.should be_true
|
824
|
-
|
825
|
-
@rv = zk.delete(:path => path, :version => @stat.version)
|
826
|
-
end
|
827
|
-
|
828
|
-
it %[should have deleted the node] do
|
829
|
-
zk.stat(:path => path)[:stat].exists.should be_false
|
830
|
-
end
|
831
|
-
end
|
832
|
-
|
833
|
-
describe 'with old version' do
|
834
|
-
before do
|
835
|
-
3.times { |n| @stat = zk.set(:path => path, :data => n.to_s)[:stat] }
|
836
|
-
|
837
|
-
@rv = zk.delete(:path => path, :version => 0)
|
838
|
-
end
|
839
|
-
|
840
|
-
it %[should have a return code of ZBADVERSION] do
|
841
|
-
@rv[:rc].should == Zookeeper::ZBADVERSION
|
842
|
-
end
|
843
|
-
end
|
844
|
-
end # sync
|
845
|
-
|
846
|
-
describe :async do
|
847
|
-
before do
|
848
|
-
@cb = ZookeeperCallbacks::VoidCallback.new
|
849
|
-
end
|
850
|
-
|
851
|
-
describe 'without version' do
|
852
|
-
it_should_behave_like "all success return values"
|
853
|
-
|
854
|
-
before do
|
855
|
-
@rv = zk.delete(:path => path, :callback => @cb, :callback_context => path)
|
856
|
-
wait_until { @cb.completed? }
|
857
|
-
@cb.should be_completed
|
858
|
-
end
|
859
|
-
|
860
|
-
it %[should have a success return_code] do
|
861
|
-
@cb.return_code.should == Zookeeper::ZOK
|
862
|
-
end
|
863
|
-
|
864
|
-
it %[should have deleted the node] do
|
865
|
-
zk.stat(:path => path)[:stat].exists.should be_false
|
866
|
-
end
|
867
|
-
end
|
868
|
-
|
869
|
-
describe 'with current version' do
|
870
|
-
it_should_behave_like "all success return values"
|
871
|
-
|
872
|
-
before do
|
873
|
-
@stat = zk.stat(:path => path)[:stat]
|
874
|
-
@rv = zk.delete(:path => path, :version => @stat.version, :callback => @cb, :callback_context => path)
|
875
|
-
wait_until { @cb.completed? }
|
876
|
-
@cb.should be_completed
|
877
|
-
end
|
878
|
-
|
879
|
-
it %[should have a success return_code] do
|
880
|
-
@cb.return_code.should == Zookeeper::ZOK
|
881
|
-
end
|
882
|
-
|
883
|
-
it %[should have deleted the node] do
|
884
|
-
zk.stat(:path => path)[:stat].exists.should be_false
|
885
|
-
end
|
886
|
-
end
|
887
|
-
|
888
|
-
describe 'with old version' do
|
889
|
-
before do
|
890
|
-
3.times { |n| @stat = zk.set(:path => path, :data => n.to_s)[:stat] }
|
891
|
-
|
892
|
-
@rv = zk.delete(:path => path, :version => 0, :callback => @cb, :callback_context => path)
|
893
|
-
wait_until { @cb.completed? }
|
894
|
-
@cb.should be_completed
|
895
|
-
end
|
896
|
-
|
897
|
-
it %[should have a return code of ZBADVERSION] do
|
898
|
-
@cb.return_code.should == Zookeeper::ZBADVERSION
|
899
|
-
end
|
900
|
-
end
|
901
|
-
end # async
|
902
|
-
end # delete
|
903
|
-
|
904
|
-
describe :get_acl do
|
905
|
-
describe :sync do
|
906
|
-
it_should_behave_like "all success return values"
|
907
|
-
|
908
|
-
before do
|
909
|
-
@rv = zk.get_acl(:path => path)
|
910
|
-
end
|
911
|
-
|
912
|
-
it %[should return a stat for the path] do
|
913
|
-
@rv[:stat].should be_kind_of(ZookeeperStat::Stat)
|
914
|
-
end
|
915
|
-
|
916
|
-
it %[should return the acls] do
|
917
|
-
acls = @rv[:acl]
|
918
|
-
acls.should be_kind_of(Array)
|
919
|
-
h = acls.first
|
920
|
-
|
921
|
-
h.should be_kind_of(Hash)
|
922
|
-
|
923
|
-
h[:perms].should == Zookeeper::ZOO_PERM_ALL
|
924
|
-
h[:id][:scheme].should == 'world'
|
925
|
-
h[:id][:id].should == 'anyone'
|
926
|
-
end
|
927
|
-
end
|
928
|
-
|
929
|
-
describe :async do
|
930
|
-
it_should_behave_like "all success return values"
|
931
|
-
|
932
|
-
before do
|
933
|
-
@cb = Zookeeper::ACLCallback.new
|
934
|
-
@rv = zk.get_acl(:path => path, :callback => @cb, :callback_context => path)
|
935
|
-
|
936
|
-
wait_until(2) { @cb.completed? }
|
937
|
-
@cb.should be_completed
|
938
|
-
end
|
939
|
-
|
940
|
-
it %[should return a stat for the path] do
|
941
|
-
@cb.stat.should be_kind_of(ZookeeperStat::Stat)
|
942
|
-
end
|
943
|
-
|
944
|
-
it %[should return the acls] do
|
945
|
-
acls = @cb.acl
|
946
|
-
acls.should be_kind_of(Array)
|
947
|
-
|
948
|
-
acl = acls.first
|
949
|
-
acl.should be_kind_of(ZookeeperACLs::ACL)
|
950
|
-
|
951
|
-
acl.perms.should == Zookeeper::ZOO_PERM_ALL
|
952
|
-
|
953
|
-
acl.id.scheme.should == 'world'
|
954
|
-
acl.id.id.should == 'anyone'
|
955
|
-
end
|
956
|
-
end
|
957
|
-
end
|
958
|
-
|
959
|
-
describe :set_acl do
|
960
|
-
before do
|
961
|
-
@perms = 5
|
962
|
-
@new_acl = [ZookeeperACLs::ACL.new(:perms => @perms, :id => ZookeeperACLs::ZOO_ANYONE_ID_UNSAFE)]
|
963
|
-
pending("No idea how to set ACLs")
|
964
|
-
end
|
965
|
-
|
966
|
-
describe :sync do
|
967
|
-
it_should_behave_like "all success return values"
|
968
|
-
|
969
|
-
before do
|
970
|
-
@rv = zk.set_acl(:path => path, :acl => @new_acl)
|
971
|
-
end
|
972
|
-
end
|
973
|
-
end
|
974
|
-
|
975
|
-
describe :session_id do
|
976
|
-
it %[should return the session_id as a Fixnum] do
|
977
|
-
zk.session_id.should be_kind_of(Fixnum)
|
978
|
-
end
|
979
|
-
end
|
980
|
-
|
981
|
-
describe :session_passwd do
|
982
|
-
it %[should return the session passwd as a String] do
|
983
|
-
zk.session_passwd.should be_kind_of(String)
|
984
|
-
end
|
985
|
-
end
|
986
|
-
end
|
987
4
|
|
988
5
|
describe 'Zookeeper' do
|
989
6
|
let(:path) { "/_zktest_" }
|
990
7
|
let(:data) { "underpants" }
|
991
8
|
let(:zk_host) { 'localhost:2181' }
|
992
9
|
|
993
|
-
|
994
|
-
Zookeeper.
|
995
|
-
Zookeeper.new(zk_host)
|
996
|
-
end
|
997
|
-
|
998
|
-
it_should_behave_like "all"
|
999
|
-
end
|
1000
|
-
|
1001
|
-
|
1002
|
-
describe 'Zookeeper chrooted' do
|
1003
|
-
let(:path) { "/_zkchroottest_" }
|
1004
|
-
let(:data) { "underpants" }
|
1005
|
-
let(:chroot_path) { '/slyphon-zookeeper-chroot' }
|
1006
|
-
|
1007
|
-
# Ok, i can't explain this, but when you run these tests, the zk instance
|
1008
|
-
# gets set up *once* and re-used, which is different from above, where it's
|
1009
|
-
# set up new each time
|
1010
|
-
#
|
1011
|
-
let(:zk) do
|
1012
|
-
Zookeeper.logger.debug { "creating chrooted zk instance" }
|
1013
|
-
Zookeeper.new("localhost:2181#{chroot_path}")
|
1014
|
-
end
|
1015
|
-
|
1016
|
-
def with_open_zk(host='localhost:2181')
|
1017
|
-
z = Zookeeper.new(host)
|
1018
|
-
yield z
|
1019
|
-
ensure
|
1020
|
-
z.close
|
1021
|
-
|
1022
|
-
wait_until do
|
1023
|
-
begin
|
1024
|
-
!z.connected?
|
1025
|
-
rescue RuntimeError
|
1026
|
-
true
|
1027
|
-
end
|
1028
|
-
end
|
10
|
+
before do
|
11
|
+
@zk = Zookeeper.new(zk_host)
|
1029
12
|
end
|
1030
13
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
with_open_zk do |z|
|
1035
|
-
z.create(:path => chroot_path, :data => '')
|
1036
|
-
end
|
14
|
+
after do
|
15
|
+
@zk and @zk.close
|
1037
16
|
end
|
1038
17
|
|
1039
|
-
|
1040
|
-
|
1041
|
-
z.delete(:path => chroot_path)
|
1042
|
-
end
|
18
|
+
def zk
|
19
|
+
@zk
|
1043
20
|
end
|
1044
21
|
|
1045
|
-
it_should_behave_like "
|
22
|
+
it_should_behave_like "connection"
|
1046
23
|
end
|
1047
24
|
|
1048
|
-
|
1049
|
-
|