zk 1.9.3 → 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.
- 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/mongoid_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe ZK::Mongoid::Locking do
|
|
18
18
|
unless th.join(5) == th
|
19
19
|
logger.warn { "Forcing pool closed!" }
|
20
20
|
ZK::Mongoid::Locking.zk_lock_pool.force_close!
|
21
|
-
th.join(5).
|
21
|
+
expect(th.join(5)).to eq(th)
|
22
22
|
end
|
23
23
|
|
24
24
|
ZK::Mongoid::Locking.zk_lock_pool = nil
|
@@ -35,8 +35,8 @@ describe ZK::Mongoid::Locking do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
th.join_until { !@lock_state.nil? }
|
38
|
-
@lock_state.
|
39
|
-
@lock_state.
|
38
|
+
expect(@lock_state).not_to be_nil
|
39
|
+
expect(@lock_state).to be(true)
|
40
40
|
end
|
41
41
|
|
42
42
|
it %[should allow another thread to enter the shared lock] do
|
@@ -52,10 +52,10 @@ describe ZK::Mongoid::Locking do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
@th1.join_until { @counter > 0 }
|
55
|
-
@counter.
|
55
|
+
expect(@counter).to be > 0
|
56
56
|
|
57
57
|
@th1.join_until { @queue.num_waiting > 0 }
|
58
|
-
@queue.num_waiting.
|
58
|
+
expect(@queue.num_waiting).to be > 0
|
59
59
|
|
60
60
|
@th2 = Thread.new do
|
61
61
|
@other_doc.with_shared_lock do
|
@@ -64,9 +64,9 @@ describe ZK::Mongoid::Locking do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
@th2.join_until { @counter == 2 }
|
67
|
-
@counter.
|
67
|
+
expect(@counter).to eq(2)
|
68
68
|
|
69
|
-
@th2.join(2).
|
69
|
+
expect(@th2.join(2)).to eq(@th2)
|
70
70
|
ensure
|
71
71
|
@queue << :unlock
|
72
72
|
|
@@ -102,32 +102,32 @@ describe ZK::Mongoid::Locking do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
@th1.join_until { q2.num_waiting >= 1 }
|
105
|
-
q2.num_waiting.
|
105
|
+
expect(q2.num_waiting).to be >= 1
|
106
106
|
|
107
107
|
@th2.join_until { q1.size == 0 }
|
108
|
-
q1.size.
|
108
|
+
expect(q1.size).to be_zero
|
109
109
|
|
110
|
-
@got_exclusive_lock.
|
110
|
+
expect(@got_exclusive_lock).not_to be(true)
|
111
111
|
|
112
112
|
q2.enq(:release)
|
113
113
|
|
114
114
|
@th1.join_until { q2.size == 0 }
|
115
|
-
q2.size.
|
115
|
+
expect(q2.size).to be_zero
|
116
116
|
|
117
117
|
@th2.join_until(5) { @got_exclusive_lock }
|
118
|
-
@got_exclusive_lock.
|
118
|
+
expect(@got_exclusive_lock).to be(true)
|
119
119
|
|
120
120
|
rescue Exception => e
|
121
121
|
$stderr.puts e.to_std_format
|
122
122
|
raise e
|
123
|
-
ensure
|
123
|
+
ensure
|
124
124
|
q2 << :release
|
125
125
|
|
126
126
|
unless @th1.join(2)
|
127
127
|
$stderr.puts "UH OH! @th1 IS HUNG!!"
|
128
128
|
end
|
129
129
|
|
130
|
-
unless @th2.join(2)
|
130
|
+
unless @th2.join(2)
|
131
131
|
$stderr.puts "UH OH! @th2 IS HUNG!!"
|
132
132
|
end
|
133
133
|
end
|
@@ -145,8 +145,8 @@ describe ZK::Mongoid::Locking do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
th.join_until { !@lock_state.nil? }
|
148
|
-
@lock_state.
|
149
|
-
@lock_state.
|
148
|
+
expect(@lock_state).not_to be_nil
|
149
|
+
expect(@lock_state).to be(true)
|
150
150
|
end
|
151
151
|
|
152
152
|
it %[should allow the same thread to re-enter the lock] do
|
@@ -165,7 +165,7 @@ describe ZK::Mongoid::Locking do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
th.join_until { @counter >= 2 }
|
168
|
-
@counter.
|
168
|
+
expect(@counter).to eq(2)
|
169
169
|
end
|
170
170
|
|
171
171
|
it %[should block another thread from entering the lock] do
|
@@ -181,9 +181,9 @@ describe ZK::Mongoid::Locking do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
th1.join_until { @counter == 1 }
|
184
|
-
@counter.
|
184
|
+
expect(@counter).to eq(1)
|
185
185
|
|
186
|
-
th1.zk_mongoid_lock_registry[:exclusive].
|
186
|
+
expect(th1.zk_mongoid_lock_registry[:exclusive]).to include(@doc.zk_lock_name)
|
187
187
|
|
188
188
|
th2 = Thread.new do
|
189
189
|
@other_doc.lock_for_update do
|
@@ -196,17 +196,17 @@ describe ZK::Mongoid::Locking do
|
|
196
196
|
|
197
197
|
# this is not a deterministic check of whether or not th2 ran and did not
|
198
198
|
# get the lock but probably close enough
|
199
|
-
|
200
|
-
@counter.
|
201
|
-
@other_doc_got_lock.
|
202
|
-
th2.zk_mongoid_lock_registry[:exclusive].
|
199
|
+
|
200
|
+
expect(@counter).to eq(1)
|
201
|
+
expect(@other_doc_got_lock).to eq(false)
|
202
|
+
expect(th2.zk_mongoid_lock_registry[:exclusive]).not_to include(@other_doc.zk_lock_name)
|
203
203
|
|
204
204
|
queue << :release_lock
|
205
|
-
th1.join(5).
|
205
|
+
expect(th1.join(5)).to eq(th1)
|
206
206
|
|
207
207
|
th2.join_until { @counter == 2 }
|
208
|
-
@counter.
|
209
|
-
@other_doc_got_lock.
|
208
|
+
expect(@counter).to eq(2)
|
209
|
+
expect(@other_doc_got_lock).to be(true)
|
210
210
|
end
|
211
211
|
|
212
212
|
describe :with_name do
|
@@ -217,7 +217,7 @@ describe ZK::Mongoid::Locking do
|
|
217
217
|
after do
|
218
218
|
if @queue.num_waiting > 0
|
219
219
|
@queue << :bogus
|
220
|
-
@th1.join(5).
|
220
|
+
expect(@th1.join(5)).to eq(@th1)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -235,9 +235,9 @@ describe ZK::Mongoid::Locking do
|
|
235
235
|
end
|
236
236
|
|
237
237
|
@th1.join_until { @counter == 1 }
|
238
|
-
@counter.
|
238
|
+
expect(@counter).to eq(1)
|
239
239
|
|
240
|
-
@th1.zk_mongoid_lock_registry[:exclusive].
|
240
|
+
expect(@th1.zk_mongoid_lock_registry[:exclusive]).to include(@doc.zk_lock_name(@name))
|
241
241
|
|
242
242
|
@th2 = Thread.new do
|
243
243
|
@other_doc.lock_for_update(@name) do
|
@@ -250,16 +250,16 @@ describe ZK::Mongoid::Locking do
|
|
250
250
|
|
251
251
|
# this is not a deterministic check of whether or not @th2 ran and did not
|
252
252
|
# get the lock but probably close enough
|
253
|
-
|
254
|
-
@counter.
|
255
|
-
@other_doc_got_lock.
|
253
|
+
|
254
|
+
expect(@counter).to eq(1)
|
255
|
+
expect(@other_doc_got_lock).to eq(false)
|
256
256
|
|
257
257
|
@queue << :release_lock
|
258
|
-
@th1.join(5).
|
258
|
+
expect(@th1.join(5)).to eq(@th1)
|
259
259
|
|
260
260
|
@th2.join_until { @counter == 2 }
|
261
|
-
@counter.
|
262
|
-
@other_doc_got_lock.
|
261
|
+
expect(@counter).to eq(2)
|
262
|
+
expect(@other_doc_got_lock).to be(true)
|
263
263
|
end
|
264
264
|
|
265
265
|
it %[should not affect another thread using a different name] do
|
@@ -276,9 +276,9 @@ describe ZK::Mongoid::Locking do
|
|
276
276
|
end
|
277
277
|
|
278
278
|
@th1.join_until { @counter == 1 }
|
279
|
-
@counter.
|
279
|
+
expect(@counter).to eq(1)
|
280
280
|
|
281
|
-
@th1.zk_mongoid_lock_registry[:exclusive].
|
281
|
+
expect(@th1.zk_mongoid_lock_registry[:exclusive]).to include(@doc.zk_lock_name(@name))
|
282
282
|
|
283
283
|
@th2 = Thread.new do
|
284
284
|
@other_doc.lock_for_update do
|
@@ -288,41 +288,41 @@ describe ZK::Mongoid::Locking do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
@th2.join_until { @other_doc_got_lock }
|
291
|
-
@other_doc_got_lock.
|
292
|
-
|
293
|
-
@counter.
|
291
|
+
expect(@other_doc_got_lock).to be(true)
|
292
|
+
|
293
|
+
expect(@counter).to eq(2)
|
294
294
|
|
295
295
|
@queue << :release_lock
|
296
|
-
@th1.join(2).
|
296
|
+
expect(@th1.join(2)).to eq(@th1)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
301
301
|
describe :assert_locked_for_update! do
|
302
302
|
it %[should raise MustBeExclusivelyLockedException if the current thread does not hold the lock] do
|
303
|
-
|
303
|
+
expect { @doc.assert_locked_for_update! }.to raise_error(ZK::Exceptions::MustBeExclusivelyLockedException)
|
304
304
|
end
|
305
305
|
|
306
306
|
it %[should not raise an exception if the current thread holds the lock] do
|
307
|
-
|
307
|
+
expect do
|
308
308
|
@doc.lock_for_update do
|
309
309
|
@doc.assert_locked_for_update!
|
310
310
|
end
|
311
|
-
end.
|
311
|
+
end.not_to raise_error
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
315
315
|
describe :assert_locked_for_share! do
|
316
316
|
it %[should raise MustBeShareLockedException if the current thread does not hold a shared lock] do
|
317
|
-
|
317
|
+
expect { @doc.assert_locked_for_share! }.to raise_error(ZK::Exceptions::MustBeShareLockedException)
|
318
318
|
end
|
319
319
|
|
320
320
|
it %[should not raise an exception if the current thread holds a shared lock] do
|
321
|
-
|
321
|
+
expect do
|
322
322
|
@doc.with_shared_lock do
|
323
323
|
@doc.assert_locked_for_share!
|
324
324
|
end
|
325
|
-
end.
|
325
|
+
end.not_to raise_error
|
326
326
|
end
|
327
327
|
end
|
328
328
|
end
|
@@ -15,18 +15,18 @@ describe ZK::NodeDeletionWatcher do
|
|
15
15
|
@zk.mkdir_p(@path)
|
16
16
|
|
17
17
|
th = Thread.new { @n.block_until_deleted }
|
18
|
-
|
19
|
-
@n.wait_until_blocked(5).
|
18
|
+
|
19
|
+
expect(@n.wait_until_blocked(5)).to be(true)
|
20
20
|
|
21
21
|
logger.debug { "wait_until_blocked returned" }
|
22
22
|
|
23
|
-
@n.
|
23
|
+
expect(@n).to be_blocked
|
24
24
|
|
25
25
|
@zk.rm_rf(@path)
|
26
26
|
|
27
|
-
th.join(5).
|
28
|
-
@n.
|
29
|
-
@n.
|
27
|
+
expect(th.join(5)).to eq(th)
|
28
|
+
expect(@n).not_to be_blocked
|
29
|
+
expect(@n).to be_done
|
30
30
|
end
|
31
31
|
|
32
32
|
it %[should wake up if interrupt! is called] do
|
@@ -43,12 +43,12 @@ describe ZK::NodeDeletionWatcher do
|
|
43
43
|
|
44
44
|
@n.wait_until_blocked(5)
|
45
45
|
|
46
|
-
@n.
|
46
|
+
expect(@n).to be_blocked
|
47
47
|
|
48
48
|
@n.interrupt!
|
49
|
-
th.join(5).
|
49
|
+
expect(th.join(5)).to eq(th)
|
50
50
|
|
51
|
-
@exc.
|
51
|
+
expect(@exc).to be_kind_of(ZK::Exceptions::WakeUpException)
|
52
52
|
end
|
53
53
|
|
54
54
|
it %[should raise LockWaitTimeoutError if we time out waiting for a node to be deleted] do
|
@@ -62,28 +62,28 @@ describe ZK::NodeDeletionWatcher do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
@n.wait_until_blocked(5).
|
65
|
+
expect(@n.wait_until_blocked(5)).to be(true)
|
66
66
|
|
67
67
|
logger.debug { "wait_until_blocked returned" }
|
68
68
|
|
69
|
-
th.join(5).
|
70
|
-
|
71
|
-
@exc.
|
72
|
-
@n.
|
73
|
-
@n.
|
69
|
+
expect(th.join(5)).to eq(th)
|
70
|
+
|
71
|
+
expect(@exc).to be_kind_of(ZK::Exceptions::LockWaitTimeoutError)
|
72
|
+
expect(@n).to be_done
|
73
|
+
expect(@n).to be_timed_out
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe %[when the node doesn't exist] do
|
78
78
|
it %[should not block the caller and be done] do
|
79
|
-
@zk.exists?(@path).
|
79
|
+
expect(@zk.exists?(@path)).to be(false)
|
80
80
|
|
81
81
|
th = Thread.new { @n.block_until_deleted }
|
82
82
|
|
83
83
|
@n.wait_until_blocked
|
84
|
-
@n.
|
85
|
-
th.join(5).
|
86
|
-
@n.
|
84
|
+
expect(@n).not_to be_blocked
|
85
|
+
expect(th.join(5)).to eq(th)
|
86
|
+
expect(@n).to be_done
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -140,23 +140,27 @@ describe ZK::NodeDeletionWatcher do
|
|
140
140
|
runner.run
|
141
141
|
controller.run
|
142
142
|
controller.join
|
143
|
-
runner.join(5).
|
144
|
-
watcher.
|
143
|
+
expect(runner.join(5)).to eq(runner)
|
144
|
+
expect(watcher).to be_done
|
145
145
|
end
|
146
146
|
|
147
147
|
context %[threshold not supplied] do
|
148
148
|
let(:watcher_params){}
|
149
149
|
|
150
150
|
it 'should raise' do
|
151
|
-
expect{ watcher }.to_not
|
151
|
+
expect{ watcher }.to_not raise_error
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#threshold' do
|
155
|
+
subject { super().threshold }
|
156
|
+
it { should be_zero }
|
152
157
|
end
|
153
|
-
its(:threshold){ should be_zero }
|
154
158
|
end
|
155
159
|
|
156
160
|
context %[invalid threshold given] do
|
157
161
|
let(:watcher_params){ {:threshold => :foo} }
|
158
162
|
it 'should raise' do
|
159
|
-
expect{ watcher }.to
|
163
|
+
expect{ watcher }.to raise_error(ZK::Exceptions::BadArguments)
|
160
164
|
end
|
161
165
|
end
|
162
166
|
|
@@ -168,10 +172,14 @@ describe ZK::NodeDeletionWatcher do
|
|
168
172
|
runner.run
|
169
173
|
controller.run
|
170
174
|
controller.join
|
171
|
-
runner.join(5).
|
172
|
-
watcher.
|
175
|
+
expect(runner.join(5)).to eq(runner)
|
176
|
+
expect(watcher).to be_done
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#threshold' do
|
180
|
+
subject { super().threshold }
|
181
|
+
it { should == 1 }
|
173
182
|
end
|
174
|
-
its(:threshold){ should == 1 }
|
175
183
|
end
|
176
184
|
|
177
185
|
context do
|
@@ -181,10 +189,10 @@ describe ZK::NodeDeletionWatcher do
|
|
181
189
|
runner.run
|
182
190
|
controller.run
|
183
191
|
controller.join
|
184
|
-
runner.join(5).
|
185
|
-
@exc.
|
186
|
-
watcher.
|
187
|
-
watcher.
|
192
|
+
expect(runner.join(5)).to eq(runner)
|
193
|
+
expect(@exc).to be_kind_of(ZK::Exceptions::LockWaitTimeoutError)
|
194
|
+
expect(watcher).to be_done
|
195
|
+
expect(watcher).to be_timed_out
|
188
196
|
end
|
189
197
|
end
|
190
198
|
end
|