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/lib/zk.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
require 'logging'
|
4
3
|
require 'zookeeper'
|
5
4
|
|
6
5
|
# XXX: after 1.0 we'll need this
|
@@ -23,7 +22,7 @@ end
|
|
23
22
|
require 'zk/core_ext'
|
24
23
|
require 'zk/exceptions'
|
25
24
|
require 'zk/extensions'
|
26
|
-
require 'zk/
|
25
|
+
require 'zk/logger'
|
27
26
|
require 'zk/event'
|
28
27
|
require 'zk/stat'
|
29
28
|
require 'zk/subscription'
|
@@ -307,6 +306,3 @@ module ZK
|
|
307
306
|
cnx_str # the possibly-modified connection string (with chroot info)
|
308
307
|
end
|
309
308
|
end
|
310
|
-
|
311
|
-
ZK::Logging.set_default
|
312
|
-
|
data/spec/event_catcher_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rspec/core/formatters/progress_formatter'
|
|
5
5
|
# easier to match up tests with the SQL they produce
|
6
6
|
class LoggingProgressBarFormatter < RSpec::Core::Formatters::ProgressFormatter
|
7
7
|
def example_started(example)
|
8
|
-
|
8
|
+
SpecGlobalLogger.logger << yellow("\n=====<([ #{example.full_description} ])>=====\n")
|
9
9
|
super
|
10
10
|
end
|
11
11
|
end
|
data/spec/message_queue_spec.rb
CHANGED
@@ -22,35 +22,35 @@ describe ZK::MessageQueue do
|
|
22
22
|
it "should be able to receive a published message" do
|
23
23
|
message_received = false
|
24
24
|
@consume_queue.subscribe do |title, data|
|
25
|
-
data.
|
25
|
+
expect(data).to eq('mydata')
|
26
26
|
message_received = true
|
27
27
|
end
|
28
28
|
@publish_queue.publish("mydata")
|
29
29
|
wait_until {message_received }
|
30
|
-
message_received.
|
30
|
+
expect(message_received).to be(true)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should be able to receive a custom message title" do
|
34
34
|
message_title = false
|
35
35
|
@consume_queue.subscribe do |title, data|
|
36
|
-
title.
|
36
|
+
expect(title).to eq('title')
|
37
37
|
message_title = true
|
38
38
|
end
|
39
39
|
@publish_queue.publish("data", "title")
|
40
40
|
wait_until { message_title }
|
41
|
-
message_title.
|
41
|
+
expect(message_title).to be(true)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should work even after processing a message from before" do
|
45
45
|
@publish_queue.publish("data1", "title")
|
46
46
|
message_times = 0
|
47
47
|
@consume_queue.subscribe do |title, data|
|
48
|
-
title.
|
48
|
+
expect(title).to eq("title")
|
49
49
|
message_times += 1
|
50
50
|
end
|
51
51
|
|
52
52
|
@publish_queue.publish("data2", "title")
|
53
53
|
wait_until { message_times == 2 }
|
54
|
-
message_times.
|
54
|
+
expect(message_times).to eq(2)
|
55
55
|
end
|
56
56
|
end
|
@@ -6,29 +6,29 @@ shared_examples_for 'client' do
|
|
6
6
|
@path_ary = %W[#{base} test mkdir_p path creation]
|
7
7
|
@bogus_path = File.join('', *@path_ary)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it %[should create all intermediate paths for the path givem] do
|
11
|
-
@zk.
|
12
|
-
@zk.
|
11
|
+
expect(@zk.exists?(@bogus_path)).to be(false)
|
12
|
+
expect(@zk.exists?(File.dirname(@bogus_path))).to be(false)
|
13
13
|
@zk.mkdir_p(@bogus_path)
|
14
|
-
@zk.
|
14
|
+
expect(@zk.exists?(@bogus_path)).to be(true)
|
15
15
|
end
|
16
16
|
|
17
17
|
it %[should place the data only at the leaf node] do
|
18
18
|
@zk.mkdir_p(@bogus_path, :data => 'foobar')
|
19
|
-
@zk.get(@bogus_path).first.
|
19
|
+
expect(@zk.get(@bogus_path).first).to eq('foobar')
|
20
20
|
|
21
21
|
path = ''
|
22
22
|
@path_ary[0..-2].each do |el|
|
23
23
|
path = File.join(path, el)
|
24
|
-
@zk.get(path).first.
|
24
|
+
expect(@zk.get(path).first).to eq('')
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it %[should replace the data at the leaf node if it already exists] do
|
29
29
|
@zk.mkdir_p(@bogus_path, :data => 'blahfoo')
|
30
30
|
@zk.mkdir_p(@bogus_path, :data => 'foodink')
|
31
|
-
@zk.get(@bogus_path).first.
|
31
|
+
expect(@zk.get(@bogus_path).first).to eq('foodink')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -37,14 +37,14 @@ shared_examples_for 'client' do
|
|
37
37
|
describe 'only path given' do
|
38
38
|
it %[should create a node with blank data] do
|
39
39
|
@zk.create(@base_path)
|
40
|
-
@zk.get(@base_path).first.
|
40
|
+
expect(@zk.get(@base_path).first).to eq('')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'path and data given' do
|
45
45
|
it %[should create a node with the path and data] do
|
46
46
|
@zk.create(@base_path, 'blah')
|
47
|
-
@zk.get(@base_path).first.
|
47
|
+
expect(@zk.get(@base_path).first).to eq('blah')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -52,37 +52,37 @@ shared_examples_for 'client' do
|
|
52
52
|
it %[should create a sequential node with blank data] do
|
53
53
|
@zk.create(@base_path)
|
54
54
|
path = @zk.create("#{@base_path}/v", :sequential => true)
|
55
|
-
path.start_with?(@base_path).
|
55
|
+
expect(path.start_with?(@base_path)).to be(true)
|
56
56
|
|
57
|
-
File.basename(path).
|
57
|
+
expect(File.basename(path)).to match(/v\d+/)
|
58
58
|
|
59
|
-
@zk.get(path).first.
|
59
|
+
expect(@zk.get(path).first).to eq('')
|
60
60
|
end
|
61
61
|
|
62
62
|
it %[should create a sequential node with given data] do
|
63
63
|
@zk.create(@base_path)
|
64
64
|
path = @zk.create("#{@base_path}/v", 'thedata', :sequential => true)
|
65
|
-
path.start_with?(@base_path).
|
65
|
+
expect(path.start_with?(@base_path)).to be(true)
|
66
66
|
|
67
|
-
File.basename(path).
|
67
|
+
expect(File.basename(path)).to match(/v\d+/)
|
68
68
|
|
69
69
|
data, st = @zk.get(path)
|
70
|
-
data.
|
71
|
-
st.
|
70
|
+
expect(data).to eq('thedata')
|
71
|
+
expect(st).not_to be_ephemeral
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe 'path and ephemeral' do
|
76
76
|
it %[should create an ephemeral node with blank data] do
|
77
77
|
@zk.create(@base_path, :ephemeral => true)
|
78
|
-
@zk.get(@base_path).last.
|
78
|
+
expect(@zk.get(@base_path).last).to be_ephemeral
|
79
79
|
end
|
80
80
|
|
81
81
|
it %[should create an ephemeral node with given data] do
|
82
82
|
@zk.create(@base_path, 'thedata', :ephemeral => true)
|
83
83
|
data, stat = @zk.get(@base_path)
|
84
|
-
data.
|
85
|
-
stat.
|
84
|
+
expect(data).to eq('thedata')
|
85
|
+
expect(stat).to be_ephemeral
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -90,45 +90,45 @@ shared_examples_for 'client' do
|
|
90
90
|
it %[should create a sequential ephemeral node with blank data] do
|
91
91
|
@zk.create(@base_path)
|
92
92
|
path = @zk.create("#{@base_path}/v", :sequential => true, :ephemeral => true)
|
93
|
-
path.start_with?(@base_path).
|
93
|
+
expect(path.start_with?(@base_path)).to be(true)
|
94
94
|
|
95
|
-
File.basename(path).
|
95
|
+
expect(File.basename(path)).to match(/v\d+/)
|
96
96
|
|
97
97
|
data, st = @zk.get(path)
|
98
|
-
data.
|
99
|
-
st.
|
98
|
+
expect(data).to eq('')
|
99
|
+
expect(st).to be_ephemeral
|
100
100
|
end
|
101
101
|
|
102
102
|
it %[should create a sequential ephemeral node with given data] do
|
103
103
|
@zk.create(@base_path)
|
104
104
|
path = @zk.create("#{@base_path}/v", 'thedata', :sequential => true, :ephemeral => true)
|
105
|
-
path.start_with?(@base_path).
|
105
|
+
expect(path.start_with?(@base_path)).to be(true)
|
106
106
|
|
107
|
-
File.basename(path).
|
107
|
+
expect(File.basename(path)).to match(/v\d+/)
|
108
108
|
|
109
109
|
data, st = @zk.get(path)
|
110
|
-
data.
|
111
|
-
st.
|
110
|
+
expect(data).to eq('thedata')
|
111
|
+
expect(st).to be_ephemeral
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
it %[should barf if someone hands 3 params] do
|
116
|
-
|
116
|
+
expect { @zk.create(@base_path, 'data', :sequence) }.to raise_error(ArgumentError)
|
117
117
|
end
|
118
118
|
|
119
119
|
it %[should barf if both :sequence and :sequential are given] do
|
120
|
-
|
120
|
+
expect { @zk.create(@base_path, 'data', :sequence => true, :sequential => true) }.to raise_error(ArgumentError)
|
121
121
|
end
|
122
122
|
|
123
123
|
describe %[:ignore option] do
|
124
124
|
it %[should squelch node_exists] do
|
125
125
|
@zk.create(@base_path)
|
126
126
|
|
127
|
-
|
127
|
+
expect { expect(@zk.create(@base_path, :ignore => :node_exists)).to be_nil }.not_to raise_error
|
128
128
|
end
|
129
129
|
|
130
130
|
it %[should squelch no_node] do
|
131
|
-
|
131
|
+
expect { expect(@zk.create("#{@base_path}/foo/bar/baz", :ignore => :no_node)).to be_nil }.not_to raise_error
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -136,11 +136,11 @@ shared_examples_for 'client' do
|
|
136
136
|
let(:path) { "#{@base_path}/foo/bar" }
|
137
137
|
|
138
138
|
it %[should barf if anything but the the :set value is given] do
|
139
|
-
|
139
|
+
expect { @zk.create(path, :or => :GFY) }.to raise_error(ArgumentError)
|
140
140
|
end
|
141
141
|
|
142
142
|
def create_args(opts={})
|
143
|
-
proc do
|
143
|
+
proc do
|
144
144
|
begin
|
145
145
|
@zk.create(path, opts.merge(:or => :set))
|
146
146
|
ensure
|
@@ -150,24 +150,24 @@ shared_examples_for 'client' do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
it %[should barf if any node option besides 'persistent' is given] do
|
153
|
-
create_args(:persistent => true).
|
154
|
-
create_args(:sequential => true).
|
155
|
-
create_args(:mode => :ephemeral).
|
156
|
-
create_args(:mode => :ephemeral_sequential).
|
157
|
-
create_args(:mode => :sequential).
|
153
|
+
expect(create_args(:persistent => true)).not_to raise_error
|
154
|
+
expect(create_args(:sequential => true)).to raise_error(ArgumentError)
|
155
|
+
expect(create_args(:mode => :ephemeral)).to raise_error(ArgumentError)
|
156
|
+
expect(create_args(:mode => :ephemeral_sequential)).to raise_error(ArgumentError)
|
157
|
+
expect(create_args(:mode => :sequential)).to raise_error(ArgumentError)
|
158
158
|
end
|
159
159
|
|
160
160
|
it %[should replace the data at the leaf node if it already exists] do
|
161
161
|
@zk.mkdir_p(path, :data => 'foodink')
|
162
162
|
@zk.create(path, 'blahfoo', :or => :set)
|
163
|
-
@zk.get(path).first.
|
163
|
+
expect(@zk.get(path).first).to eq('blahfoo')
|
164
164
|
end
|
165
165
|
|
166
166
|
it %[should create the intermediate paths] do
|
167
|
-
|
167
|
+
expect { @zk.create(path, 'foobar', :or => :set) }.not_to raise_error
|
168
168
|
|
169
|
-
@zk.stat(@base_path).
|
170
|
-
@zk.stat("#{@base_path}/foo").
|
169
|
+
expect(@zk.stat(@base_path)).to exist
|
170
|
+
expect(@zk.stat("#{@base_path}/foo")).to exist
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
@@ -178,16 +178,16 @@ shared_examples_for 'client' do
|
|
178
178
|
@zk.create(@base_path)
|
179
179
|
@zk.create("#{@base_path}/blah")
|
180
180
|
|
181
|
-
|
181
|
+
expect { expect(@zk.delete(@base_path, :ignore => :not_empty)).to be_nil }.not_to raise_error
|
182
182
|
end
|
183
183
|
|
184
184
|
it %[should squelch no_node] do
|
185
|
-
|
185
|
+
expect { expect(@zk.delete("#{@base_path}/foo/bar/baz", :ignore => :no_node)).to be_nil }.not_to raise_error
|
186
186
|
end
|
187
187
|
|
188
188
|
it %[should squelch bad_version] do
|
189
189
|
@zk.create(@base_path)
|
190
|
-
|
190
|
+
expect { expect(@zk.delete("#{@base_path}", :version => 7, :ignore => :bad_version)).to be_nil }.not_to raise_error
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|
@@ -197,21 +197,21 @@ shared_examples_for 'client' do
|
|
197
197
|
before do
|
198
198
|
@missing_path = '/thispathdoesnotexist'
|
199
199
|
begin
|
200
|
-
@zk.delete(@missing_path)
|
200
|
+
@zk.delete(@missing_path)
|
201
201
|
rescue ZK::Exceptions::NoNode
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
it %[should not raise any error] do
|
206
|
-
|
206
|
+
expect { @zk.stat(@missing_path) }.not_to raise_error
|
207
207
|
end
|
208
208
|
|
209
209
|
it %[should return a Stat object] do
|
210
|
-
@zk.stat(@missing_path).
|
210
|
+
expect(@zk.stat(@missing_path)).to be_kind_of(Zookeeper::Stat)
|
211
211
|
end
|
212
212
|
|
213
213
|
it %[should return a stat that not exists?] do
|
214
|
-
@zk.stat(@missing_path).
|
214
|
+
expect(@zk.stat(@missing_path)).not_to be_exists
|
215
215
|
end
|
216
216
|
end
|
217
217
|
end
|
@@ -219,12 +219,12 @@ shared_examples_for 'client' do
|
|
219
219
|
describe :set do
|
220
220
|
describe %[:ignore option] do
|
221
221
|
it %[should squelch no_node] do
|
222
|
-
|
222
|
+
expect { expect(@zk.set("#{@base_path}/foo/bar/baz", '', :ignore => :no_node)).to be_nil }.not_to raise_error
|
223
223
|
end
|
224
224
|
|
225
225
|
it %[should squelch bad_version] do
|
226
226
|
@zk.create(@base_path)
|
227
|
-
|
227
|
+
expect { expect(@zk.set("#{@base_path}", '', :version => 7, :ignore => :bad_version)).to be_nil }.not_to raise_error
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
@@ -236,7 +236,7 @@ shared_examples_for 'client' do
|
|
236
236
|
|
237
237
|
describe 'no node initially' do
|
238
238
|
before do
|
239
|
-
@zk.exists?(@path).
|
239
|
+
expect(@zk.exists?(@path)).to be(false)
|
240
240
|
end
|
241
241
|
|
242
242
|
it %[should not block] do
|
@@ -248,42 +248,42 @@ shared_examples_for 'client' do
|
|
248
248
|
end
|
249
249
|
|
250
250
|
th.join(2)
|
251
|
-
@a.
|
251
|
+
expect(@a).to be(true)
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
255
|
describe 'node exists initially' do
|
256
256
|
before do
|
257
257
|
@zk.create(@path, :mode => :ephemeral)
|
258
|
-
@zk.exists?(@path).
|
258
|
+
expect(@zk.exists?(@path)).to be(true)
|
259
259
|
end
|
260
260
|
|
261
261
|
it %[should block until the node is deleted] do
|
262
262
|
@a = false
|
263
263
|
|
264
|
-
|
264
|
+
Thread.new do
|
265
265
|
@zk.block_until_node_deleted(@path)
|
266
266
|
@a = true
|
267
267
|
end
|
268
268
|
|
269
269
|
Thread.pass
|
270
|
-
@a.
|
270
|
+
expect(@a).to be(false)
|
271
271
|
|
272
272
|
@zk.delete(@path)
|
273
273
|
|
274
274
|
wait_until(2) { @a }
|
275
|
-
@a.
|
275
|
+
expect(@a).to be(true)
|
276
276
|
end
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
280
|
describe 'session_id and session_passwd' do
|
281
281
|
it %[should expose the underlying session_id] do
|
282
|
-
@zk.session_id.
|
282
|
+
expect(@zk.session_id).to be_kind_of(Integer)
|
283
283
|
end
|
284
284
|
|
285
285
|
it %[should expose the underlying session_passwd] do
|
286
|
-
@zk.session_passwd.
|
286
|
+
expect(@zk.session_passwd).to be_kind_of(String)
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
@@ -296,22 +296,22 @@ shared_examples_for 'client' do
|
|
296
296
|
end
|
297
297
|
|
298
298
|
# after do
|
299
|
-
# logger.info { "AFTER EACH" }
|
299
|
+
# logger.info { "AFTER EACH" }
|
300
300
|
# @zk.delete(@path)
|
301
301
|
# end
|
302
302
|
|
303
303
|
def ensure_event_delivery!
|
304
304
|
@sub ||= @zk.event_handler.register(@path) do |event|
|
305
|
-
logger.debug { "got event: #{event.inspect}" }
|
305
|
+
logger.debug { "got event: #{event.inspect}" }
|
306
306
|
@queue << event
|
307
307
|
end
|
308
308
|
|
309
|
-
@zk.exists?(@path, :watch => true).
|
309
|
+
expect(@zk.exists?(@path, :watch => true)).to be(false)
|
310
310
|
@zk.create(@path)
|
311
311
|
|
312
|
-
logger.debug { "waiting for event delivery" }
|
312
|
+
logger.debug { "waiting for event delivery" }
|
313
313
|
|
314
|
-
wait_until(2) do
|
314
|
+
wait_until(2) do
|
315
315
|
begin
|
316
316
|
event = @queue.pop(true)
|
317
317
|
logger.debug { "got event: #{event}" }
|
@@ -323,7 +323,7 @@ shared_examples_for 'client' do
|
|
323
323
|
end
|
324
324
|
|
325
325
|
# first watch delivered correctly
|
326
|
-
@events.length.
|
326
|
+
expect(@events.length).to be > 0
|
327
327
|
end
|
328
328
|
|
329
329
|
it %[should fire re-registered watchers after reopen (#9)] do
|
@@ -357,14 +357,14 @@ shared_examples_for 'client' do
|
|
357
357
|
# note: we can't trust the events to be delivered in any particular order
|
358
358
|
# since they're happening on two different threads. if we see we're connected
|
359
359
|
# in the beginning, that there was a disconnection, then a reopen, that's
|
360
|
-
# probably fine.
|
360
|
+
# probably fine.
|
361
361
|
#
|
362
362
|
# we also check that the session_id was changed, which is the desired effect
|
363
363
|
|
364
364
|
orig_session_id = @zk.session_id
|
365
|
-
@zk.
|
365
|
+
expect(@zk).to be_connected
|
366
366
|
|
367
|
-
props = {
|
367
|
+
props = {
|
368
368
|
:session_event? => true,
|
369
369
|
:node_event? => false,
|
370
370
|
:client_invalid? => true,
|
@@ -372,8 +372,8 @@ shared_examples_for 'client' do
|
|
372
372
|
:state => Zookeeper::ZOO_EXPIRED_SESSION_STATE,
|
373
373
|
}
|
374
374
|
|
375
|
-
bogus_event =
|
376
|
-
bogus_event.
|
375
|
+
bogus_event = instance_double(Zookeeper::Callbacks::WatcherCallback, props)
|
376
|
+
expect(bogus_event).to receive(:zk=).with(@zk).once
|
377
377
|
|
378
378
|
mutex = Monitor.new
|
379
379
|
cond = mutex.new_cond
|
@@ -388,20 +388,20 @@ shared_examples_for 'client' do
|
|
388
388
|
end
|
389
389
|
|
390
390
|
mutex.synchronize do
|
391
|
-
events.
|
391
|
+
expect(events).to be_empty
|
392
392
|
@zk.event_handler.process(bogus_event)
|
393
393
|
end
|
394
394
|
|
395
|
-
logger.debug { "events: #{events.inspect}" }
|
395
|
+
logger.debug { "events: #{events.inspect}" }
|
396
396
|
|
397
397
|
mutex.synchronize do
|
398
398
|
time_to_stop = Time.now + 2
|
399
399
|
cond.wait_while { (events.length < 2 ) && (Time.now < time_to_stop) }
|
400
400
|
end
|
401
401
|
|
402
|
-
events.
|
403
|
-
events.
|
404
|
-
@zk.session_id.
|
402
|
+
expect(events).to include(Zookeeper::ZOO_EXPIRED_SESSION_STATE)
|
403
|
+
expect(events).to include(Zookeeper::ZOO_CONNECTED_STATE)
|
404
|
+
expect(@zk.session_id).not_to eq(orig_session_id)
|
405
405
|
end
|
406
406
|
end # reconnection
|
407
407
|
|
@@ -410,17 +410,17 @@ shared_examples_for 'client' do
|
|
410
410
|
@ary = []
|
411
411
|
|
412
412
|
@zk.on_exception { |exc| @ary << exc }
|
413
|
-
|
413
|
+
|
414
414
|
@zk.defer { raise "ZOMG!" }
|
415
415
|
|
416
416
|
wait_while(2) { @ary.empty? }
|
417
417
|
|
418
|
-
@ary.length.
|
418
|
+
expect(@ary.length).to eq(1)
|
419
419
|
|
420
420
|
e = @ary.shift
|
421
421
|
|
422
|
-
e.
|
423
|
-
e.message.
|
422
|
+
expect(e).to be_kind_of(RuntimeError)
|
423
|
+
expect(e.message).to eq('ZOMG!')
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
@@ -431,8 +431,8 @@ shared_examples_for 'client' do
|
|
431
431
|
@zk.defer { @ary << @zk.on_threadpool? }
|
432
432
|
|
433
433
|
wait_while(2) { @ary.empty? }
|
434
|
-
@ary.length.
|
435
|
-
@ary.first.
|
434
|
+
expect(@ary.length).to eq(1)
|
435
|
+
expect(@ary.first).to be(true)
|
436
436
|
end
|
437
437
|
end
|
438
438
|
end
|
@@ -6,50 +6,50 @@
|
|
6
6
|
shared_examples_for 'LockerBase#assert!' do
|
7
7
|
it %[should raise LockAssertionFailedError if its connection is no longer connected?] do
|
8
8
|
zk.close!
|
9
|
-
|
9
|
+
expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
|
10
10
|
end
|
11
11
|
|
12
12
|
it %[should raise LockAssertionFailedError if locked? is false] do
|
13
|
-
locker.
|
14
|
-
|
13
|
+
expect(locker).not_to be_locked
|
14
|
+
expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
|
15
15
|
end
|
16
16
|
|
17
17
|
it %[should raise LockAssertionFailedError lock_path does not exist] do
|
18
18
|
locker.lock
|
19
|
-
|
19
|
+
expect { locker.assert! }.not_to raise_error
|
20
20
|
|
21
21
|
zk.delete(locker.lock_path)
|
22
|
-
|
22
|
+
expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
|
23
23
|
end
|
24
24
|
|
25
25
|
it %[should raise LockAssertionFailedError if our parent node's ctime is different than what we think it should be] do
|
26
|
-
locker.lock.
|
26
|
+
expect(locker.lock).to be(true)
|
27
27
|
|
28
28
|
zk.rm_rf(File.dirname(locker.lock_path)) # remove the parent node
|
29
29
|
zk.mkdir_p(locker.lock_path)
|
30
30
|
|
31
|
-
|
31
|
+
expect { locker.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
shared_examples_for 'LockerBase#unlock' do
|
36
36
|
it %[should not delete a lock path it does not own] do
|
37
|
-
locker.lock.
|
37
|
+
expect(locker.lock).to be(true)
|
38
38
|
|
39
39
|
zk.rm_rf(File.dirname(locker.lock_path)) # remove the parent node
|
40
40
|
zk.mkdir_p(File.dirname(locker.lock_path))
|
41
41
|
|
42
|
-
locker2.lock.
|
42
|
+
expect(locker2.lock).to be(true)
|
43
43
|
|
44
|
-
locker2.lock_path.
|
44
|
+
expect(locker2.lock_path).to eq(locker.lock_path)
|
45
45
|
|
46
|
-
|
46
|
+
expect { locker2.assert! }.not_to raise_error
|
47
47
|
|
48
48
|
lock_path = locker.lock_path
|
49
49
|
|
50
|
-
locker.unlock.
|
50
|
+
expect(locker.unlock).to be(false)
|
51
51
|
|
52
|
-
zk.stat(lock_path).
|
52
|
+
expect(zk.stat(lock_path)).to exist
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|