zk 1.9.6 → 1.10.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.
Files changed (40) hide show
  1. checksums.yaml +5 -13
  2. data/.github/workflows/build.yml +55 -0
  3. data/Gemfile +15 -6
  4. data/README.markdown +9 -9
  5. data/RELEASES.markdown +10 -1
  6. data/lib/zk/client.rb +1 -1
  7. data/lib/zk/event_handler.rb +15 -7
  8. data/lib/zk/fork_hook.rb +2 -2
  9. data/lib/zk/locker/locker_base.rb +13 -0
  10. data/lib/zk/locker/semaphore.rb +1 -3
  11. data/lib/zk/node_deletion_watcher.rb +3 -4
  12. data/lib/zk/pool.rb +11 -11
  13. data/lib/zk/version.rb +1 -1
  14. data/spec/event_catcher_spec.rb +1 -1
  15. data/spec/message_queue_spec.rb +6 -6
  16. data/spec/shared/client_examples.rb +81 -81
  17. data/spec/shared/locker_examples.rb +13 -13
  18. data/spec/spec_helper.rb +10 -11
  19. data/spec/zk/00_forked_client_integration_spec.rb +3 -3
  20. data/spec/zk/client/locking_and_session_death_spec.rb +2 -2
  21. data/spec/zk/client_spec.rb +19 -19
  22. data/spec/zk/election_spec.rb +44 -44
  23. data/spec/zk/extensions_spec.rb +2 -2
  24. data/spec/zk/locker/exclusive_locker_spec.rb +41 -41
  25. data/spec/zk/locker/locker_basic_spec.rb +55 -33
  26. data/spec/zk/locker/semaphore_spec.rb +39 -32
  27. data/spec/zk/locker/shared_exclusive_integration_spec.rb +37 -37
  28. data/spec/zk/locker/shared_locker_spec.rb +43 -43
  29. data/spec/zk/locker_spec.rb +2 -2
  30. data/spec/zk/module_spec.rb +25 -25
  31. data/spec/zk/mongoid_spec.rb +47 -47
  32. data/spec/zk/node_deletion_watcher_spec.rb +39 -31
  33. data/spec/zk/pool_spec.rb +56 -65
  34. data/spec/zk/threaded_callback_spec.rb +10 -10
  35. data/spec/zk/threadpool_spec.rb +25 -25
  36. data/spec/zk/watch_spec.rb +67 -79
  37. data/spec/zk/zookeeper_spec.rb +31 -31
  38. data/zk.gemspec +1 -1
  39. metadata +23 -24
  40. data/.travis.yml +0 -30
@@ -21,7 +21,7 @@ describe ZK::Client::Threaded do
21
21
  it %[should do the right thing and not fail] do
22
22
  # this is an extra special case where the user obviously hates us
23
23
 
24
- @zk.should be_kind_of(ZK::Client::Threaded) # yeah yeah, just be sure
24
+ expect(@zk).to be_kind_of(ZK::Client::Threaded) # yeah yeah, just be sure
25
25
 
26
26
  shutdown_thread = nil
27
27
 
@@ -31,17 +31,17 @@ describe ZK::Client::Threaded do
31
31
 
32
32
  wait_while { shutdown_thread.nil? }
33
33
 
34
- shutdown_thread.should_not be_nil
35
- shutdown_thread.should be_kind_of(Thread)
34
+ expect(shutdown_thread).not_to be_nil
35
+ expect(shutdown_thread).to be_kind_of(Thread)
36
36
 
37
- shutdown_thread.join(5).should == shutdown_thread
37
+ expect(shutdown_thread.join(5)).to eq(shutdown_thread)
38
38
 
39
- wait_until(5) { @zk.closed? }.should be_true
39
+ expect(wait_until(5) { @zk.closed? }).to be(true)
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
- describe :reopen do
44
+ describe :reopen, :jruby => :broken do
45
45
  include_context 'connection opts'
46
46
 
47
47
  before do
@@ -53,15 +53,15 @@ describe ZK::Client::Threaded do
53
53
  end
54
54
 
55
55
  it %[should say the client is connected after reopen] do
56
- @zk.connected?.should == true
56
+ expect(@zk.connected?).to eq(true)
57
57
 
58
58
  @zk.close!
59
59
 
60
- @zk.connected?.should == false
60
+ expect(@zk.connected?).to eq(false)
61
61
 
62
62
  @zk.reopen
63
63
 
64
- @zk.connected?.should == true
64
+ expect(@zk.connected?).to eq(true)
65
65
  end
66
66
  end
67
67
 
@@ -80,7 +80,7 @@ describe ZK::Client::Threaded do
80
80
  # TODO: this is a terrible test. there is no way to guarantee that this
81
81
  # has been retried. the join at the end should not raise an error
82
82
 
83
- @zk.should_not be_connected
83
+ expect(@zk).not_to be_connected
84
84
 
85
85
  th = Thread.new do
86
86
  @zk.stat('/path/to/blah', :retry_duration => 30)
@@ -89,11 +89,11 @@ describe ZK::Client::Threaded do
89
89
  th.run
90
90
 
91
91
  @zk.connect
92
- th.join(5).should == th
92
+ expect(th.join(5)).to eq(th)
93
93
  end
94
94
 
95
95
  it %[barfs if the connection is closed before the connected event is received] do
96
- @zk.should_not be_connected
96
+ expect(@zk).not_to be_connected
97
97
 
98
98
  exc = nil
99
99
 
@@ -110,14 +110,14 @@ describe ZK::Client::Threaded do
110
110
 
111
111
  @zk.close!
112
112
 
113
- th.join(5).should == th
113
+ expect(th.join(5)).to eq(th)
114
114
 
115
- exc.should_not be_nil
116
- exc.should be_kind_of(ZK::Exceptions::Retryable)
115
+ expect(exc).not_to be_nil
116
+ expect(exc).to be_kind_of(ZK::Exceptions::Retryable)
117
117
  end
118
118
 
119
119
  it %[should barf if the timeout expires] do
120
- @zk.should_not be_connected
120
+ expect(@zk).not_to be_connected
121
121
 
122
122
  exc = nil
123
123
 
@@ -132,10 +132,10 @@ describe ZK::Client::Threaded do
132
132
 
133
133
  th.run
134
134
 
135
- th.join(5).should == th
135
+ expect(th.join(5)).to eq(th)
136
136
 
137
- exc.should_not be_nil
138
- exc.should be_kind_of(ZK::Exceptions::Retryable)
137
+ expect(exc).not_to be_nil
138
+ expect(exc).to be_kind_of(ZK::Exceptions::Retryable)
139
139
  end
140
140
  end
141
141
  end # ZK::Client::Threaded
@@ -4,7 +4,7 @@ describe ZK::Election, :jruby => :broken do
4
4
  include_context 'connection opts'
5
5
 
6
6
  before do
7
- ZK.open(connection_host) do |cnx|
7
+ ZK.open(connection_host) do |cnx|
8
8
  logger.debug { "REMOVING /_zkelection" }
9
9
  cnx.rm_rf('/_zkelection')
10
10
  end
@@ -56,8 +56,8 @@ describe ZK::Election, :jruby => :broken do
56
56
  end
57
57
 
58
58
  @palin.on_losing_election do
59
- @obama_won.should be_true
60
- @palin.leader_acked?.should be_true
59
+ expect(@obama_won).to be(true)
60
+ expect(@palin.leader_acked?).to be(true)
61
61
  @palin_lost = true
62
62
  end
63
63
 
@@ -68,21 +68,21 @@ describe ZK::Election, :jruby => :broken do
68
68
  oth.run
69
69
 
70
70
  wait_until { @obama_waiting }
71
- @obama_waiting.should be_true
71
+ expect(@obama_waiting).to be(true)
72
72
 
73
73
  # palin's callbacks haven't fired
74
- @palin_lost.should be_nil
74
+ expect(@palin_lost).to be_nil
75
75
 
76
76
  latch.release
77
77
 
78
78
  wait_until { @obama_won }
79
- @obama_won.should be_true
79
+ expect(@obama_won).to be(true)
80
80
 
81
- lambda { oth.join(1).should == oth }.should_not raise_error
81
+ expect { expect(oth.join(1)).to eq(oth) }.not_to raise_error
82
82
 
83
83
  wait_until { @palin_lost }
84
84
 
85
- @palin_lost.should be_true
85
+ expect(@palin_lost).to be(true)
86
86
  end
87
87
  end
88
88
 
@@ -92,7 +92,7 @@ describe ZK::Election, :jruby => :broken do
92
92
  @obama_won = @obama_lost = @palin_won = @palin_lost = nil
93
93
  win_latch, lose_latch = Latch.new, Latch.new
94
94
 
95
- @obama.on_winning_election do
95
+ @obama.on_winning_election do
96
96
  logger.debug { "obama on_winning_election fired" }
97
97
  @obama_won = true
98
98
  win_latch.release
@@ -115,50 +115,50 @@ describe ZK::Election, :jruby => :broken do
115
115
  @palin_lost = true
116
116
  lose_latch.release
117
117
  end
118
-
118
+
119
119
  @obama.vote!
120
120
  @palin.vote!
121
121
 
122
122
  win_latch.await
123
- @obama_won.should be_true
123
+ expect(@obama_won).to be(true)
124
124
 
125
125
  lose_latch.await
126
- @palin_lost.should be_true
126
+ expect(@palin_lost).to be(true)
127
127
  end
128
128
 
129
129
  describe 'winner' do
130
130
  it %[should fire the on_winning_election callbacks] do
131
- @obama_won.should be_true
131
+ expect(@obama_won).to be(true)
132
132
  end
133
133
 
134
134
  it %[should not fire the on_losing_election callbacks] do
135
- @obama_lost.should be_nil
135
+ expect(@obama_lost).to be_nil
136
136
  end
137
137
 
138
138
  it %[should acknowledge completion of winning callbacks] do
139
- @zk.exists?(@obama.leader_ack_path).should be_true
139
+ expect(@zk.exists?(@obama.leader_ack_path)).to be(true)
140
140
  end
141
141
 
142
142
  it %[should write its data to the leader_ack node] do
143
- @zk.get(@obama.leader_ack_path).first.should == @data1
143
+ expect(@zk.get(@obama.leader_ack_path).first).to eq(@data1)
144
144
  end
145
145
 
146
146
  it %[should know it's the leader] do
147
- @obama.should be_leader
147
+ expect(@obama).to be_leader
148
148
  end
149
149
  end
150
150
 
151
151
  describe 'loser' do # gets a talk show on Fox News? I KEED! I KEED!
152
152
  it %[should know it isn't the leader] do
153
- @palin.should_not be_leader
153
+ expect(@palin).not_to be_leader
154
154
  end
155
155
 
156
156
  it %[should not fire the winning callbacks] do
157
- @palin_won.should_not be_true
157
+ expect(@palin_won).not_to be(true)
158
158
  end
159
159
 
160
160
  it %[should fire the losing callbacks] do
161
- @palin_lost.should be_true
161
+ expect(@palin_lost).to be(true)
162
162
  end
163
163
 
164
164
  it %[should take over as leader when the current leader goes away] do
@@ -167,13 +167,13 @@ describe ZK::Election, :jruby => :broken do
167
167
  @obama.zk.close!
168
168
  wait_until { @palin_won }
169
169
 
170
- @palin_won.should be_true # god forbid
170
+ expect(@palin_won).to be(true) # god forbid
171
171
 
172
172
  wait_until { @zk2.exists?(@palin.leader_ack_path) }
173
173
 
174
- @zk2.exists?(@palin.leader_ack_path).should be_true
174
+ expect(@zk2.exists?(@palin.leader_ack_path)).to be(true)
175
175
 
176
- @zk2.get(@palin.leader_ack_path).first.should == @data2
176
+ expect(@zk2.get(@palin.leader_ack_path).first).to eq(@data2)
177
177
  end
178
178
 
179
179
  it %[should remain leader if the original leader comes back] do
@@ -193,9 +193,9 @@ describe ZK::Election, :jruby => :broken do
193
193
  newbama.vote!
194
194
  wait_until { newbama.voted? }
195
195
 
196
- newbama.should be_voted
197
- win_again.should be_false
198
- newbama.should_not be_leader
196
+ expect(newbama).to be_voted
197
+ expect(win_again).to be(false)
198
+ expect(newbama).not_to be_leader
199
199
  end
200
200
  end
201
201
  end
@@ -207,12 +207,12 @@ describe ZK::Election, :jruby => :broken do
207
207
  before do
208
208
  @zk3 = ZK.new(*connection_args)
209
209
 
210
- @zk3.exists?('/_zkelection/2012/leader_ack').should be_false
210
+ expect(@zk3.exists?('/_zkelection/2012/leader_ack')).to be(false)
211
211
 
212
212
  @obama = ZK::Election::Candidate.new(@zk, @election_name, :data => @data1)
213
213
  @palin = ZK::Election::Candidate.new(@zk2, @election_name, :data => @data2)
214
214
 
215
- @zk3.exists?('/_zkelection/2012/leader_ack').should be_false
215
+ expect(@zk3.exists?('/_zkelection/2012/leader_ack')).to be(false)
216
216
 
217
217
  @observer = ZK::Election::Observer.new(@zk3, @election_name)
218
218
  end
@@ -231,17 +231,17 @@ describe ZK::Election, :jruby => :broken do
231
231
 
232
232
  @observer.observe!
233
233
  wait_until { !@observer.leader_alive.nil? }
234
- @observer.leader_alive.should_not be_nil
235
- @zk3.exists?(@observer.root_election_node).should be_false
234
+ expect(@observer.leader_alive).not_to be_nil
235
+ expect(@zk3.exists?(@observer.root_election_node)).to be(false)
236
236
  end
237
237
 
238
238
  it %[should set leader_alive to false] do
239
- @observer.leader_alive.should be_false
239
+ expect(@observer.leader_alive).to be(false)
240
240
  end
241
241
 
242
242
  it %[should fire death callbacks] do
243
- @events.length.should == 1
244
- @events.first.should == :death
243
+ expect(@events.length).to eq(1)
244
+ expect(@events.first).to eq(:death)
245
245
  end
246
246
  end
247
247
 
@@ -263,19 +263,19 @@ describe ZK::Election, :jruby => :broken do
263
263
  end
264
264
 
265
265
  it %[should be obama that won] do
266
- @obama.should be_leader
266
+ expect(@obama).to be_leader
267
267
  end
268
268
 
269
269
  it %[should be palin that lost] do
270
- @palin.should_not be_leader
270
+ expect(@palin).not_to be_leader
271
271
  end
272
272
 
273
273
  it %[should set leader_alive to true] do
274
- @observer.leader_alive.should be_true
274
+ expect(@observer.leader_alive).to be(true)
275
275
  end
276
276
 
277
277
  it %[should fire the new leader callbacks] do
278
- @got_life_event.should be_true
278
+ expect(@got_life_event).to be(true)
279
279
  end
280
280
  end
281
281
 
@@ -286,7 +286,7 @@ describe ZK::Election, :jruby => :broken do
286
286
  wait_until { @obama.leader? }
287
287
 
288
288
  @palin.vote!
289
- @palin.should_not be_leader
289
+ expect(@palin).not_to be_leader
290
290
 
291
291
  @got_life_event = @got_death_event = false
292
292
 
@@ -297,23 +297,23 @@ describe ZK::Election, :jruby => :broken do
297
297
 
298
298
  wait_until { !@observer.leader_alive.nil? }
299
299
 
300
- @observer.leader_alive.should be_true
300
+ expect(@observer.leader_alive).to be(true)
301
301
  @zk.close!
302
302
  wait_until { !@zk.connected? && @palin.leader? && @palin.leader_acked? }
303
303
  end
304
304
 
305
305
  it %[should be palin who is leader] do
306
- @palin.should be_leader
306
+ expect(@palin).to be_leader
307
307
  end
308
308
 
309
309
  it %[should have seen both the death and life events] do
310
- pending 'this test is flapping'
311
- @got_life_event.should be_true
312
- @got_death_event.should be_true
310
+ # pending 'this test is flapping'
311
+ expect(@got_life_event).to be(true)
312
+ expect(@got_death_event).to be(true)
313
313
  end
314
314
 
315
315
  it %[should see the data of the new leader] do
316
- @observer.leader_data.should == 'palin'
316
+ expect(@observer.leader_data).to eq('palin')
317
317
  end
318
318
  end
319
319
  end
@@ -6,8 +6,8 @@ module ZK
6
6
 
7
7
  it %[should not barf if backtrace is nil] do
8
8
  exc = StandardError.new
9
- exc.backtrace.should be_nil
10
- lambda { exc.to_std_format }.should_not raise_error
9
+ expect(exc.backtrace).to be_nil
10
+ expect { exc.to_std_format }.not_to raise_error
11
11
  end
12
12
  end
13
13
  end
@@ -9,13 +9,13 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
9
9
 
10
10
  it %[should raise LockAssertionFailedError if there is an exclusive lock with a number lower than ours] do
11
11
  # this should *really* never happen
12
-
12
+
13
13
  rlp = locker.root_lock_path
14
14
 
15
15
  zk.mkdir_p(rlp)
16
16
 
17
17
  bogus_path = zk.create("#{rlp}/#{ZK::Locker::EXCLUSIVE_LOCK_PREFIX}", :sequential => true, :ephemeral => true)
18
- logger.debug { "bogus_path: #{bogus_path.inspect}" }
18
+ logger.debug { "bogus_path: #{bogus_path.inspect}" }
19
19
 
20
20
  th = Thread.new do
21
21
  locker.lock(true)
@@ -24,40 +24,40 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
24
24
  th.run
25
25
 
26
26
  logger.debug { "calling wait_until_blocked" }
27
- proc { locker.wait_until_blocked(5) }.should_not raise_error
27
+ expect { locker.wait_until_blocked(5) }.not_to raise_error
28
28
  logger.debug { "wait_until_blocked returned" }
29
- locker.should be_waiting
29
+ expect(locker).to be_waiting
30
30
 
31
31
  wait_until { zk.exists?(locker.lock_path) }
32
32
 
33
- zk.exists?(locker.lock_path).should be_true
33
+ expect(zk.exists?(locker.lock_path)).to be(true)
34
34
 
35
35
  zk.delete(bogus_path)
36
36
 
37
- th.join(5).should == th
37
+ expect(th.join(5)).to eq(th)
38
38
 
39
- locker.lock_path.should_not == bogus_path
39
+ expect(locker.lock_path).not_to eq(bogus_path)
40
40
 
41
41
  zk.create(bogus_path, :ephemeral => true)
42
42
 
43
- lambda { locker.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
43
+ expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
44
44
  end
45
45
  end
46
46
 
47
47
  describe :acquirable? do
48
48
  it %[should work if the lock root doesn't exist] do
49
49
  zk.rm_rf(ZK::Locker.default_root_lock_node)
50
- locker.should be_acquirable
50
+ expect(locker).to be_acquirable
51
51
  end
52
52
 
53
53
  it %[should check local state of lockedness] do
54
- locker.lock.should be_true
55
- locker.should be_acquirable
54
+ expect(locker.lock).to be(true)
55
+ expect(locker).to be_acquirable
56
56
  end
57
57
 
58
58
  it %[should check if any participants would prevent us from acquiring the lock] do
59
- locker.lock.should be_true
60
- locker2.should_not be_acquirable
59
+ expect(locker.lock).to be(true)
60
+ expect(locker2).not_to be_acquirable
61
61
  end
62
62
  end
63
63
 
@@ -69,16 +69,16 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
69
69
  end
70
70
 
71
71
  it %[should acquire the first lock] do
72
- @rval.should be_true
72
+ expect(@rval).to be(true)
73
73
  end
74
74
 
75
75
  it %[should not acquire the second lock] do
76
- @rval2.should be_false
76
+ expect(@rval2).to be(false)
77
77
  end
78
78
 
79
79
  it %[should acquire the second lock after the first lock is released] do
80
- locker.unlock.should be_true
81
- locker2.lock.should be_true
80
+ expect(locker.unlock).to be(true)
81
+ expect(locker2.lock).to be(true)
82
82
  end
83
83
  end
84
84
 
@@ -95,7 +95,7 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
95
95
  it %[should block waiting for the lock with old style lock semantics] do
96
96
  ary = []
97
97
 
98
- locker.lock.should be_false
98
+ expect(locker.lock).to be(false)
99
99
 
100
100
  th = Thread.new do
101
101
  locker.lock(true)
@@ -103,22 +103,22 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
103
103
  end
104
104
 
105
105
  locker.wait_until_blocked(5)
106
-
107
- ary.should be_empty
108
- locker.should_not be_locked
106
+
107
+ expect(ary).to be_empty
108
+ expect(locker).not_to be_locked
109
109
 
110
110
  zk.delete(@read_lock_path)
111
111
 
112
- th.join(2).should == th
112
+ expect(th.join(2)).to eq(th)
113
113
 
114
- ary.length.should == 1
115
- locker.should be_locked
114
+ expect(ary.length).to eq(1)
115
+ expect(locker).to be_locked
116
116
  end
117
117
 
118
118
  it %[should block waiting for the lock with new style lock semantics] do
119
119
  ary = []
120
120
 
121
- locker.lock.should be_false
121
+ expect(locker.lock).to be(false)
122
122
 
123
123
  th = Thread.new do
124
124
  locker.lock(:wait => true)
@@ -126,24 +126,24 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
126
126
  end
127
127
 
128
128
  locker.wait_until_blocked(5)
129
-
130
- ary.should be_empty
131
- locker.should_not be_locked
129
+
130
+ expect(ary).to be_empty
131
+ expect(locker).not_to be_locked
132
132
 
133
133
  zk.delete(@read_lock_path)
134
134
 
135
- th.join(2).should == th
135
+ expect(th.join(2)).to eq(th)
136
136
 
137
- ary.length.should == 1
138
- locker.should be_locked
137
+ expect(ary.length).to eq(1)
138
+ expect(locker).to be_locked
139
139
  end
140
140
 
141
141
  it %[should time out waiting for the lock] do
142
142
  ary = []
143
143
 
144
- zk.children(lock_path_base).length.should == 1
144
+ expect(zk.children(lock_path_base).length).to eq(1)
145
145
 
146
- locker.lock.should be_false
146
+ expect(locker.lock).to be(false)
147
147
 
148
148
  th = Thread.new do
149
149
  begin
@@ -155,17 +155,17 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
155
155
  end
156
156
 
157
157
  locker.wait_until_blocked(5)
158
-
159
- ary.should be_empty
160
- locker.should_not be_locked
161
158
 
162
- th.join(2).should == th
159
+ expect(ary).to be_empty
160
+ expect(locker).not_to be_locked
161
+
162
+ expect(th.join(2)).to eq(th)
163
163
 
164
- zk.children(lock_path_base).length.should == 1
164
+ expect(zk.children(lock_path_base).length).to eq(1)
165
165
 
166
- ary.should be_empty
167
- @exc.should_not be_nil
168
- @exc.should be_kind_of(ZK::Exceptions::LockWaitTimeoutError)
166
+ expect(ary).to be_empty
167
+ expect(@exc).not_to be_nil
168
+ expect(@exc).to be_kind_of(ZK::Exceptions::LockWaitTimeoutError)
169
169
  end
170
170
  end # blocking
171
171
  end # lock