zk 1.9.3 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +55 -0
- data/.gitignore +1 -0
- data/Gemfile +18 -8
- data/README.markdown +9 -9
- data/RELEASES.markdown +28 -1
- data/lib/zk/client/base.rb +15 -0
- data/lib/zk/client/threaded.rb +3 -3
- data/lib/zk/client.rb +1 -1
- data/lib/zk/election.rb +1 -1
- data/lib/zk/event_handler.rb +16 -8
- data/lib/zk/event_handler_subscription/base.rb +1 -1
- data/lib/zk/fork_hook.rb +9 -4
- data/lib/zk/locker/locker_base.rb +14 -2
- data/lib/zk/locker/semaphore.rb +1 -3
- data/lib/zk/logger.rb +34 -0
- data/lib/zk/node_deletion_watcher.rb +4 -5
- data/lib/zk/pool.rb +12 -12
- data/lib/zk/subscription.rb +1 -1
- data/lib/zk/threaded_callback.rb +1 -1
- data/lib/zk/threadpool.rb +1 -1
- data/lib/zk/version.rb +1 -1
- data/lib/zk.rb +1 -5
- data/spec/event_catcher_spec.rb +1 -1
- data/spec/logging_progress_bar_formatter.rb +1 -1
- data/spec/message_queue_spec.rb +6 -6
- data/spec/shared/client_examples.rb +81 -81
- data/spec/shared/locker_examples.rb +13 -13
- data/spec/spec_helper.rb +12 -13
- data/spec/support/bogus_mongoid.rb +1 -1
- data/spec/support/client_forker.rb +1 -1
- data/spec/support/event_catcher.rb +1 -1
- data/spec/support/logging.rb +15 -47
- data/spec/zk/00_forked_client_integration_spec.rb +3 -3
- data/spec/zk/client/locking_and_session_death_spec.rb +2 -2
- data/spec/zk/client_spec.rb +19 -19
- data/spec/zk/election_spec.rb +44 -44
- data/spec/zk/extensions_spec.rb +2 -2
- data/spec/zk/locker/exclusive_locker_spec.rb +41 -41
- data/spec/zk/locker/locker_basic_spec.rb +55 -33
- data/spec/zk/locker/semaphore_spec.rb +39 -32
- data/spec/zk/locker/shared_exclusive_integration_spec.rb +37 -37
- data/spec/zk/locker/shared_locker_spec.rb +43 -43
- data/spec/zk/locker_spec.rb +2 -2
- data/spec/zk/module_spec.rb +25 -25
- data/spec/zk/mongoid_spec.rb +47 -47
- data/spec/zk/node_deletion_watcher_spec.rb +39 -31
- data/spec/zk/pool_spec.rb +56 -65
- data/spec/zk/threaded_callback_spec.rb +10 -10
- data/spec/zk/threadpool_spec.rb +25 -25
- data/spec/zk/watch_spec.rb +67 -79
- data/spec/zk/zookeeper_spec.rb +36 -30
- data/zk.gemspec +1 -2
- metadata +26 -47
- data/.travis.yml +0 -25
- data/lib/zk/logging.rb +0 -36
data/spec/zk/watch_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe ZK do
|
|
17
17
|
after do
|
18
18
|
mute_logger do
|
19
19
|
if @zk.connected?
|
20
|
-
@zk.close!
|
20
|
+
@zk.close!
|
21
21
|
wait_until { !@zk.connected? }
|
22
22
|
end
|
23
23
|
|
@@ -33,29 +33,29 @@ describe ZK do
|
|
33
33
|
locker.synchronize do
|
34
34
|
callback_called = true
|
35
35
|
end
|
36
|
-
event.path.
|
36
|
+
expect(event.path).to eq(@path)
|
37
37
|
end
|
38
38
|
|
39
39
|
@zk.exists?(@path, :watch => true)
|
40
40
|
@zk.create(@path, "", :mode => :ephemeral)
|
41
41
|
|
42
42
|
wait_until(5) { locker.synchronize { callback_called } }
|
43
|
-
callback_called.
|
43
|
+
expect(callback_called).to be(true)
|
44
44
|
end
|
45
45
|
|
46
46
|
describe :regression do
|
47
|
-
before do
|
48
|
-
|
49
|
-
end
|
47
|
+
# before do
|
48
|
+
# pending_in_travis("these tests take too long or time out")
|
49
|
+
# end
|
50
50
|
|
51
|
-
# this is stupid, and a bad test, but we have to check that events
|
52
|
-
# don't get re-delivered to a single registered callback just because
|
51
|
+
# this is stupid, and a bad test, but we have to check that events
|
52
|
+
# don't get re-delivered to a single registered callback just because
|
53
53
|
# :watch => true was called twice
|
54
54
|
#
|
55
55
|
# again, we're testing a negative here, so consider this a regression check
|
56
56
|
#
|
57
57
|
def wait_for_events_to_not_be_delivered(events)
|
58
|
-
|
58
|
+
expect { wait_until(0.2) { events.length >= 2 } }.to raise_error(WaitWatchers::TimeoutError)
|
59
59
|
end
|
60
60
|
|
61
61
|
it %[should only deliver an event once to each watcher registered for exists?] do
|
@@ -67,14 +67,14 @@ describe ZK do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
2.times do
|
70
|
-
@zk.exists?(@path, :watch => true).
|
70
|
+
expect(@zk.exists?(@path, :watch => true)).not_to be(true)
|
71
71
|
end
|
72
72
|
|
73
73
|
@zk.create(@path, '', :mode => :ephemeral)
|
74
74
|
|
75
75
|
wait_for_events_to_not_be_delivered(events)
|
76
76
|
|
77
|
-
events.length.
|
77
|
+
expect(events.length).to eq(1)
|
78
78
|
end
|
79
79
|
|
80
80
|
it %[should only deliver an event once to each watcher registered for get] do
|
@@ -89,14 +89,14 @@ describe ZK do
|
|
89
89
|
|
90
90
|
2.times do
|
91
91
|
data, stat = @zk.get(@path, :watch => true)
|
92
|
-
data.
|
92
|
+
expect(data).to eq('one')
|
93
93
|
end
|
94
94
|
|
95
95
|
@zk.set(@path, 'two')
|
96
96
|
|
97
97
|
wait_for_events_to_not_be_delivered(events)
|
98
98
|
|
99
|
-
events.length.
|
99
|
+
expect(events.length).to eq(1)
|
100
100
|
end
|
101
101
|
|
102
102
|
|
@@ -112,20 +112,20 @@ describe ZK do
|
|
112
112
|
|
113
113
|
2.times do
|
114
114
|
children = @zk.children(@path, :watch => true)
|
115
|
-
children.
|
115
|
+
expect(children).to be_empty
|
116
116
|
end
|
117
117
|
|
118
118
|
@zk.create("#{@path}/pfx", '', :mode => :ephemeral_sequential)
|
119
119
|
|
120
120
|
wait_for_events_to_not_be_delivered(events)
|
121
121
|
|
122
|
-
events.length.
|
122
|
+
expect(events.length).to eq(1)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
it %[should restrict_new_watches_for? if a successul watch has been set] do
|
127
127
|
@zk.stat(@path, :watch => true)
|
128
|
-
@zk.event_handler.
|
128
|
+
expect(@zk.event_handler).to be_restricting_new_watches_for(:data, @path)
|
129
129
|
end
|
130
130
|
|
131
131
|
it %[should not a block on new watches after an operation fails] do
|
@@ -141,19 +141,19 @@ describe ZK do
|
|
141
141
|
|
142
142
|
# get a path that doesn't exist with a watch
|
143
143
|
|
144
|
-
|
144
|
+
expect { @zk.get(@path, :watch => true) }.to raise_error(ZK::Exceptions::NoNode)
|
145
145
|
|
146
|
-
@zk.event_handler.
|
146
|
+
expect(@zk.event_handler).not_to be_restricting_new_watches_for(:data, @path)
|
147
147
|
|
148
148
|
@zk.stat(@path, :watch => true)
|
149
149
|
|
150
|
-
@zk.event_handler.
|
150
|
+
expect(@zk.event_handler).to be_restricting_new_watches_for(:data, @path)
|
151
151
|
|
152
152
|
@zk.create(@path, '')
|
153
153
|
|
154
154
|
wait_while { events.empty? }
|
155
155
|
|
156
|
-
events.
|
156
|
+
expect(events).not_to be_empty
|
157
157
|
end
|
158
158
|
|
159
159
|
it %[should call a child listener when the node is deleted] do
|
@@ -177,10 +177,10 @@ describe ZK do
|
|
177
177
|
|
178
178
|
event = events.pop
|
179
179
|
|
180
|
-
event.
|
180
|
+
expect(event).not_to be_nil
|
181
181
|
|
182
|
-
event.path.
|
183
|
-
event.type.
|
182
|
+
expect(event.path).to eq(@path)
|
183
|
+
expect(event.type).to eq(Zookeeper::ZOO_DELETED_EVENT)
|
184
184
|
|
185
185
|
# Create the node again
|
186
186
|
@zk.create(@path, '')
|
@@ -196,10 +196,10 @@ describe ZK do
|
|
196
196
|
|
197
197
|
event = events.pop
|
198
198
|
|
199
|
-
event.
|
199
|
+
expect(event).not_to be_nil
|
200
200
|
|
201
|
-
event.path.
|
202
|
-
event.type.
|
201
|
+
expect(event.path).to eq(@path)
|
202
|
+
expect(event.type).to eq(Zookeeper::ZOO_DELETED_EVENT)
|
203
203
|
end
|
204
204
|
|
205
205
|
describe ':all' do
|
@@ -230,7 +230,7 @@ describe ZK do
|
|
230
230
|
@zk.create(@path)
|
231
231
|
@zk.create(@other_path, 'blah')
|
232
232
|
|
233
|
-
wait_until { events.length == 2 }.
|
233
|
+
expect(wait_until { events.length == 2 }).to be(true)
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
@@ -250,58 +250,58 @@ describe ZK do
|
|
250
250
|
|
251
251
|
it %[should deliver only the created event to the created block] do
|
252
252
|
@events.synchronize do
|
253
|
-
@zk.stat(@path, :watch => true).
|
253
|
+
expect(@zk.stat(@path, :watch => true)).not_to exist
|
254
254
|
|
255
255
|
@zk.create(@path)
|
256
256
|
|
257
257
|
@events.wait_for_created
|
258
258
|
|
259
|
-
@events.created.
|
260
|
-
@events.created.first.
|
261
|
-
@events.all.
|
259
|
+
expect(@events.created).not_to be_empty
|
260
|
+
expect(@events.created.first).to be_node_created
|
261
|
+
expect(@events.all).not_to be_empty
|
262
262
|
|
263
|
-
@zk.stat(@path, :watch => true).
|
263
|
+
expect(@zk.stat(@path, :watch => true)).to exist
|
264
264
|
|
265
|
-
@events.all.length.
|
265
|
+
expect(@events.all.length).to eq(1)
|
266
266
|
|
267
267
|
@zk.delete(@path)
|
268
268
|
|
269
269
|
@events.wait_for_all
|
270
270
|
end
|
271
271
|
|
272
|
-
@events.all.length.
|
272
|
+
expect(@events.all.length).to eq(2)
|
273
273
|
|
274
274
|
# :deleted event was delivered, make sure it didn't get delivered to the :created block
|
275
|
-
@events.created.length.
|
275
|
+
expect(@events.created.length).to eq(1)
|
276
276
|
end
|
277
277
|
|
278
278
|
it %[should deliver only the changed event to the changed block] do
|
279
279
|
@events.synchronize do
|
280
280
|
@zk.create(@path)
|
281
281
|
|
282
|
-
@zk.stat(@path, :watch => true).
|
282
|
+
expect(@zk.stat(@path, :watch => true)).to exist
|
283
283
|
|
284
284
|
@zk.set(@path, 'data')
|
285
285
|
|
286
286
|
@events.wait_for_changed
|
287
287
|
end
|
288
288
|
|
289
|
-
@events.changed.
|
290
|
-
@events.changed.length.
|
291
|
-
@events.changed.first.
|
289
|
+
expect(@events.changed).not_to be_empty
|
290
|
+
expect(@events.changed.length).to eq(1)
|
291
|
+
expect(@events.changed.first).to be_node_changed
|
292
292
|
|
293
|
-
@events.all.length.
|
293
|
+
expect(@events.all.length).to eq(1)
|
294
294
|
|
295
295
|
@events.synchronize do
|
296
|
-
@zk.stat(@path, :watch => true).
|
296
|
+
expect(@zk.stat(@path, :watch => true)).to exist
|
297
297
|
@zk.delete(@path)
|
298
298
|
@events.wait_for_all
|
299
299
|
end
|
300
300
|
|
301
|
-
@events.all.length.
|
301
|
+
expect(@events.all.length).to eq(2)
|
302
302
|
|
303
303
|
# :deleted event was delivered, make sure it didn't get delivered to the :changed block
|
304
|
-
@events.changed.length.
|
304
|
+
expect(@events.changed.length).to eq(1)
|
305
305
|
end
|
306
306
|
|
307
307
|
it %[should deliver only the child event to the child block] do
|
@@ -309,53 +309,53 @@ describe ZK do
|
|
309
309
|
|
310
310
|
@events.synchronize do
|
311
311
|
@zk.create(@path)
|
312
|
-
@zk.children(@path, :watch => true).
|
312
|
+
expect(@zk.children(@path, :watch => true)).to be_empty
|
313
313
|
|
314
314
|
child_path = @zk.create("#{@path}/m", '', :sequence => true)
|
315
315
|
|
316
316
|
@events.wait_for_child
|
317
317
|
|
318
|
-
@events.child.length.
|
319
|
-
@events.child.first.
|
318
|
+
expect(@events.child.length).to eq(1)
|
319
|
+
expect(@events.child.first).to be_node_child
|
320
320
|
|
321
|
-
@zk.stat(@path, :watch => true).
|
321
|
+
expect(@zk.stat(@path, :watch => true)).to exist
|
322
322
|
|
323
|
-
@events.all.length.
|
323
|
+
expect(@events.all.length).to eq(1)
|
324
324
|
|
325
325
|
@zk.set(@path, '') # equivalent to a 'touch'
|
326
326
|
@events.wait_for_all
|
327
327
|
end
|
328
328
|
|
329
|
-
@events.all.length.
|
329
|
+
expect(@events.all.length).to eq(2)
|
330
330
|
|
331
331
|
# :changed event was delivered, make sure it didn't get delivered to the :child block
|
332
|
-
@events.child.length.
|
332
|
+
expect(@events.child.length).to eq(1)
|
333
333
|
end
|
334
334
|
|
335
335
|
it %[should deliver only the deleted event to the deleted block] do
|
336
336
|
@events.synchronize do
|
337
337
|
@zk.create(@path)
|
338
|
-
@zk.stat(@path, :watch => true).
|
338
|
+
expect(@zk.stat(@path, :watch => true)).to exist
|
339
339
|
@zk.delete(@path)
|
340
340
|
|
341
341
|
@events.wait_for_deleted
|
342
342
|
@events.wait_while_all { |all| all.empty? }
|
343
343
|
|
344
|
-
@events.deleted.
|
345
|
-
@events.deleted.first.
|
346
|
-
@events.all.length.
|
344
|
+
expect(@events.deleted).not_to be_empty
|
345
|
+
expect(@events.deleted.first).to be_node_deleted
|
346
|
+
expect(@events.all.length).to eq(1)
|
347
347
|
|
348
|
-
@zk.stat(@path, :watch => true).
|
348
|
+
expect(@zk.stat(@path, :watch => true)).not_to exist
|
349
349
|
|
350
350
|
@zk.create(@path)
|
351
351
|
|
352
352
|
@events.wait_for_all
|
353
353
|
end
|
354
354
|
|
355
|
-
@events.all.length.
|
355
|
+
expect(@events.all.length).to be > 1
|
356
356
|
|
357
357
|
# :deleted event was delivered, make sure it didn't get delivered to the :created block
|
358
|
-
@events.deleted.length.
|
358
|
+
expect(@events.deleted.length).to eq(1)
|
359
359
|
end
|
360
360
|
end # event catcher scope
|
361
361
|
|
@@ -372,30 +372,30 @@ describe ZK do
|
|
372
372
|
end
|
373
373
|
|
374
374
|
@events.synchronize do
|
375
|
-
@zk.stat(@path, :watch => true).
|
375
|
+
expect(@zk.stat(@path, :watch => true)).not_to exist
|
376
376
|
|
377
377
|
@zk.create(@path)
|
378
378
|
|
379
379
|
@cond.wait(5)
|
380
380
|
|
381
|
-
@events.
|
382
|
-
@events.length.
|
383
|
-
@events.first.
|
381
|
+
expect(@events).not_to be_empty
|
382
|
+
expect(@events.length).to eq(1)
|
383
|
+
expect(@events.first).to be_node_created
|
384
384
|
|
385
|
-
@zk.stat(@path, :watch => true).
|
385
|
+
expect(@zk.stat(@path, :watch => true)).to exist
|
386
386
|
@zk.set(@path, 'blah')
|
387
387
|
|
388
388
|
@cond.wait(5)
|
389
389
|
end
|
390
390
|
|
391
|
-
@events.length.
|
392
|
-
@events.last.
|
391
|
+
expect(@events.length).to eq(2)
|
392
|
+
expect(@events.last).to be_node_changed
|
393
393
|
end
|
394
394
|
|
395
395
|
it %[should barf if an invalid event name is given] do
|
396
|
-
|
396
|
+
expect do
|
397
397
|
@zk.register(@path, :only => :tripping) { }
|
398
|
-
end.
|
398
|
+
end.to raise_error(ArgumentError)
|
399
399
|
end
|
400
400
|
end # event interest
|
401
401
|
end # watchers
|
@@ -416,21 +416,9 @@ describe ZK do
|
|
416
416
|
|
417
417
|
it %[should fire the registered callback] do
|
418
418
|
wait_while { @event.nil? }
|
419
|
-
@event.
|
419
|
+
expect(@event).not_to be_nil
|
420
420
|
end
|
421
421
|
end
|
422
|
-
|
423
|
-
describe 'registered listeners' do
|
424
|
-
before do
|
425
|
-
@event = flexmock(:event) do |m|
|
426
|
-
m.should_receive(:type).and_return(-1)
|
427
|
-
m.should_receive(:zk=).with(any())
|
428
|
-
m.should_receive(:node_event?).and_return(false)
|
429
|
-
m.should_receive(:state_event?).and_return(true)
|
430
|
-
m.should_receive(:state).and_return(Zookeeper::Constants::ZOO_CONNECTED_STATE)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
end # registered listeners
|
434
422
|
end
|
435
423
|
end
|
436
424
|
|
data/spec/zk/zookeeper_spec.rb
CHANGED
@@ -2,61 +2,67 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples_for 'ZK basic' do
|
4
4
|
before do
|
5
|
-
logger.debug { "connection_args: #{connection_args.inspect}" }
|
5
|
+
logger.debug { "connection_args: #{connection_args.inspect}" }
|
6
6
|
begin
|
7
7
|
@zk.create(@base_path)
|
8
8
|
rescue ZK::Exceptions::NodeExists
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
describe ZK, "with no authentication" do
|
13
|
+
it "should add authentication" do
|
14
|
+
expect(@zk.add_auth({:scheme => 'digest', :cert => 'bob:password'})).to include({:rc => 0})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
describe ZK, "with no paths" do
|
13
19
|
it "should not exist" do
|
14
|
-
@zk.exists?("#{@base_path}/test").
|
20
|
+
expect(@zk.exists?("#{@base_path}/test")).to be(false)
|
15
21
|
end
|
16
22
|
|
17
23
|
it "should create a path" do
|
18
|
-
@zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral).
|
24
|
+
expect(@zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral)).to eq("#{@base_path}/test")
|
19
25
|
end
|
20
26
|
|
21
27
|
it "should be able to set the data" do
|
22
28
|
@zk.create("#{@base_path}/test", "something", :mode => :ephemeral)
|
23
29
|
@zk.set("#{@base_path}/test", "somethingelse")
|
24
|
-
@zk.get("#{@base_path}/test").first.
|
30
|
+
expect(@zk.get("#{@base_path}/test").first).to eq("somethingelse")
|
25
31
|
end
|
26
32
|
|
27
33
|
it "should raise an exception for a non existent path" do
|
28
|
-
|
34
|
+
expect { @zk.get("/non_existent_path") }.to raise_error(ZK::Exceptions::NoNode)
|
29
35
|
end
|
30
36
|
|
31
37
|
it "should create a path with sequence set" do
|
32
|
-
@zk.create("#{@base_path}/test", "test_data", :mode => :persistent_sequential).
|
38
|
+
expect(@zk.create("#{@base_path}/test", "test_data", :mode => :persistent_sequential)).to match(/test(\d+)/)
|
33
39
|
end
|
34
40
|
|
35
41
|
it "should create an ephemeral path" do
|
36
|
-
@zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral).
|
42
|
+
expect(@zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral)).to eq("#{@base_path}/test")
|
37
43
|
end
|
38
44
|
|
39
45
|
it "should remove ephemeral path when client session ends" do
|
40
|
-
@zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral).
|
41
|
-
@zk.exists?("#{@base_path}/test").
|
46
|
+
expect(@zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral)).to eq("#{@base_path}/test")
|
47
|
+
expect(@zk.exists?("#{@base_path}/test")).not_to be_nil
|
42
48
|
@zk.close!
|
43
49
|
wait_until(2) { !@zk.connected? }
|
44
|
-
@zk.
|
50
|
+
expect(@zk).not_to be_connected
|
45
51
|
|
46
52
|
@zk = ZK.new(*connection_args)
|
47
53
|
wait_until{ @zk.connected? }
|
48
|
-
@zk.exists?("#{@base_path}/test").
|
54
|
+
expect(@zk.exists?("#{@base_path}/test")).to be(false)
|
49
55
|
end
|
50
56
|
|
51
57
|
it "should remove sequential ephemeral path when client session ends" do
|
52
58
|
created = @zk.create("#{@base_path}/test", "test_data", :mode => :ephemeral_sequential)
|
53
|
-
created.
|
54
|
-
@zk.exists?(created).
|
59
|
+
expect(created).to match(/test(\d+)/)
|
60
|
+
expect(@zk.exists?(created)).not_to be_nil
|
55
61
|
@zk.close!
|
56
62
|
|
57
63
|
@zk = ZK.new(*connection_args)
|
58
64
|
wait_until{ @zk.connected? }
|
59
|
-
@zk.exists?(created).
|
65
|
+
expect(@zk.exists?(created)).to be(false)
|
60
66
|
end
|
61
67
|
end
|
62
68
|
|
@@ -66,57 +72,57 @@ shared_examples_for 'ZK basic' do
|
|
66
72
|
end
|
67
73
|
|
68
74
|
it "should return a stat" do
|
69
|
-
@zk.stat("#{@base_path}/test").
|
75
|
+
expect(@zk.stat("#{@base_path}/test")).to be_instance_of(Zookeeper::Stat)
|
70
76
|
end
|
71
77
|
|
72
78
|
it "should return a boolean" do
|
73
|
-
@zk.exists?("#{@base_path}/test").
|
79
|
+
expect(@zk.exists?("#{@base_path}/test")).to be(true)
|
74
80
|
end
|
75
81
|
|
76
82
|
it "should get data and stat" do
|
77
83
|
data, stat = @zk.get("#{@base_path}/test")
|
78
|
-
data.
|
79
|
-
stat.
|
80
|
-
stat.created_time.
|
84
|
+
expect(data).to eq("test_data")
|
85
|
+
expect(stat).to be_a_kind_of(Zookeeper::Stat)
|
86
|
+
expect(stat.created_time).not_to eq(0)
|
81
87
|
end
|
82
88
|
|
83
89
|
it "should set data with a file" do
|
84
90
|
file = File.read('spec/test_file.txt')
|
85
91
|
@zk.set("#{@base_path}/test", file)
|
86
|
-
@zk.get("#{@base_path}/test").first.
|
92
|
+
expect(@zk.get("#{@base_path}/test").first).to eq(file)
|
87
93
|
end
|
88
94
|
|
89
95
|
it "should delete path" do
|
90
96
|
@zk.delete("#{@base_path}/test")
|
91
|
-
@zk.exists?("#{@base_path}/test").
|
97
|
+
expect(@zk.exists?("#{@base_path}/test")).to be(false)
|
92
98
|
end
|
93
99
|
|
94
100
|
it "should create a child path" do
|
95
|
-
@zk.create("#{@base_path}/test/child", "child", :mode => :ephemeral).
|
101
|
+
expect(@zk.create("#{@base_path}/test/child", "child", :mode => :ephemeral)).to eq("#{@base_path}/test/child")
|
96
102
|
end
|
97
103
|
|
98
104
|
it "should create sequential child paths" do
|
99
|
-
(child1 = @zk.create("#{@base_path}/test/child", "child1", :mode => :persistent_sequential)).
|
100
|
-
(child2 = @zk.create("#{@base_path}/test/child", "child2", :mode => :persistent_sequential)).
|
105
|
+
expect(child1 = @zk.create("#{@base_path}/test/child", "child1", :mode => :persistent_sequential)).to match(/\/test\/child(\d+)/)
|
106
|
+
expect(child2 = @zk.create("#{@base_path}/test/child", "child2", :mode => :persistent_sequential)).to match(/\/test\/child(\d+)/)
|
101
107
|
children = @zk.children("#{@base_path}/test")
|
102
|
-
children.length.
|
103
|
-
children.
|
104
|
-
children.
|
108
|
+
expect(children.length).to eq(2)
|
109
|
+
expect(children).to be_include(child1.match(/\/test\/(child\d+)/)[1])
|
110
|
+
expect(children).to be_include(child2.match(/\/test\/(child\d+)/)[1])
|
105
111
|
end
|
106
112
|
|
107
113
|
it "should have no children" do
|
108
|
-
@zk.children("#{@base_path}/test").
|
114
|
+
expect(@zk.children("#{@base_path}/test")).to be_empty
|
109
115
|
end
|
110
116
|
end
|
111
117
|
|
112
118
|
describe ZK, "with children" do
|
113
119
|
before(:each) do
|
114
120
|
@zk.create("#{@base_path}/test", "test_data", :mode => :persistent)
|
115
|
-
@zk.create("#{@base_path}/test/child", "child", :mode => "persistent").
|
121
|
+
expect(@zk.create("#{@base_path}/test/child", "child", :mode => "persistent")).to eq("#{@base_path}/test/child")
|
116
122
|
end
|
117
123
|
|
118
124
|
it "should get children" do
|
119
|
-
@zk.children("#{@base_path}/test").
|
125
|
+
expect(@zk.children("#{@base_path}/test")).to eql(["child"])
|
120
126
|
end
|
121
127
|
end
|
122
128
|
end
|
data/zk.gemspec
CHANGED
@@ -12,8 +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 'zookeeper', '~> 1.
|
16
|
-
s.add_runtime_dependency 'logging', '~> 1.7.2'
|
15
|
+
s.add_runtime_dependency 'zookeeper', '~> 1.5.0'
|
17
16
|
|
18
17
|
s.files = `git ls-files`.split("\n")
|
19
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,67 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.10.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jonathan D. Simms
|
9
8
|
- Topper Bowers
|
10
|
-
autorequire:
|
9
|
+
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2021-09-27 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: zookeeper
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
20
|
+
version: 1.5.0
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- - ~>
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: 1.
|
31
|
-
-
|
32
|
-
name: logging
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
|
-
requirements:
|
36
|
-
- - ~>
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: 1.7.2
|
39
|
-
type: :runtime
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.7.2
|
47
|
-
description: ! 'A high-level wrapper around the zookeeper driver
|
27
|
+
version: 1.5.0
|
28
|
+
description: 'A high-level wrapper around the zookeeper driver
|
48
29
|
|
49
|
-
'
|
30
|
+
'
|
50
31
|
email:
|
51
32
|
- slyphon@gmail.com
|
52
33
|
executables: []
|
53
34
|
extensions: []
|
54
35
|
extra_rdoc_files: []
|
55
36
|
files:
|
56
|
-
- .dotfiles/ctags_paths
|
57
|
-
- .dotfiles/rspec-logging
|
58
|
-
- .dotfiles/ruby-gemset
|
59
|
-
- .dotfiles/ruby-version
|
60
|
-
- .dotfiles/rvmrc
|
61
|
-
- .
|
62
|
-
- .
|
63
|
-
- .
|
64
|
-
- .yardopts
|
37
|
+
- ".dotfiles/ctags_paths"
|
38
|
+
- ".dotfiles/rspec-logging"
|
39
|
+
- ".dotfiles/ruby-gemset"
|
40
|
+
- ".dotfiles/ruby-version"
|
41
|
+
- ".dotfiles/rvmrc"
|
42
|
+
- ".github/workflows/build.yml"
|
43
|
+
- ".gitignore"
|
44
|
+
- ".gitmodules"
|
45
|
+
- ".yardopts"
|
65
46
|
- Gemfile
|
66
47
|
- Guardfile
|
67
48
|
- LICENSE
|
@@ -96,7 +77,7 @@ files:
|
|
96
77
|
- lib/zk/locker/locker_base.rb
|
97
78
|
- lib/zk/locker/semaphore.rb
|
98
79
|
- lib/zk/locker/shared_locker.rb
|
99
|
-
- lib/zk/
|
80
|
+
- lib/zk/logger.rb
|
100
81
|
- lib/zk/message_queue.rb
|
101
82
|
- lib/zk/mongoid.rb
|
102
83
|
- lib/zk/node_deletion_watcher.rb
|
@@ -155,27 +136,25 @@ files:
|
|
155
136
|
- zk.gemspec
|
156
137
|
homepage: https://github.com/slyphon/zk
|
157
138
|
licenses: []
|
158
|
-
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
159
141
|
rdoc_options: []
|
160
142
|
require_paths:
|
161
143
|
- lib
|
162
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
145
|
requirements:
|
165
|
-
- -
|
146
|
+
- - ">="
|
166
147
|
- !ruby/object:Gem::Version
|
167
148
|
version: '0'
|
168
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
150
|
requirements:
|
171
|
-
- -
|
151
|
+
- - ">="
|
172
152
|
- !ruby/object:Gem::Version
|
173
153
|
version: '0'
|
174
154
|
requirements: []
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
specification_version: 3
|
155
|
+
rubygems_version: 3.1.6
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
179
158
|
summary: A high-level wrapper around the zookeeper driver
|
180
159
|
test_files:
|
181
160
|
- spec/event_catcher_spec.rb
|