zk 0.6.5 → 0.7.1
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.
- data/.dotfiles/rspec-logging +4 -0
- data/.gitignore +2 -0
- data/.yardopts +8 -0
- data/Gemfile +6 -1
- data/README.markdown +86 -0
- data/lib/z_k/client/base.rb +692 -0
- data/lib/z_k/client/conveniences.rb +134 -0
- data/lib/z_k/client/state_mixin.rb +94 -0
- data/lib/z_k/client/unixisms.rb +89 -0
- data/lib/z_k/client.rb +12 -891
- data/lib/z_k/election.rb +3 -0
- data/lib/z_k/event_handler.rb +7 -5
- data/lib/z_k/mongoid.rb +1 -1
- data/lib/z_k/pool.rb +70 -27
- data/lib/z_k/threadpool.rb +7 -2
- data/lib/z_k/version.rb +1 -1
- data/lib/z_k.rb +1 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/support/logging_progress_bar_formatter.rb +14 -0
- data/spec/watch_spec.rb +26 -8
- data/spec/{client_spec.rb → z_k/client_spec.rb} +1 -1
- data/spec/{election_spec.rb → z_k/election_spec.rb} +2 -3
- data/spec/{locker_spec.rb → z_k/locker_spec.rb} +1 -1
- data/spec/{mongoid_spec.rb → z_k/mongoid_spec.rb} +1 -1
- data/spec/{client_pool_spec.rb → z_k/pool_spec.rb} +98 -126
- data/spec/{threadpool_spec.rb → z_k/threadpool_spec.rb} +6 -3
- data/zk.gemspec +1 -0
- metadata +37 -26
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'tracer'
|
4
4
|
|
@@ -57,33 +57,32 @@ describe ZK::Pool do
|
|
57
57
|
@about_to_block = false
|
58
58
|
|
59
59
|
open_th = Thread.new do
|
60
|
-
@connection_pool.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
60
|
+
@cnx = @connection_pool.checkout(true)
|
61
|
+
@about_to_block = true
|
62
|
+
# wait for signal to release our connection
|
63
|
+
release_q.pop
|
65
64
|
end
|
66
65
|
|
67
|
-
wait_until(
|
66
|
+
wait_until(5) { @about_to_block }
|
68
67
|
@about_to_block.should be_true
|
69
68
|
|
70
|
-
release_q.num_waiting.should == 1
|
71
|
-
|
72
69
|
closing_th = Thread.new do
|
73
70
|
@connection_pool.close_all!
|
74
71
|
end
|
75
72
|
|
76
|
-
wait_until(
|
73
|
+
wait_until(5) { @connection_pool.closing? }
|
77
74
|
@connection_pool.should be_closing
|
75
|
+
logger.debug { "connection pool is closing" }
|
78
76
|
|
79
77
|
lambda { @connection_pool.with_connection { |c| } }.should raise_error(ZK::Exceptions::PoolIsShuttingDownException)
|
80
78
|
|
81
79
|
release_q << :ok_let_go
|
82
80
|
|
83
|
-
open_th.join(
|
81
|
+
open_th.join(5).should == open_th
|
82
|
+
|
83
|
+
wait_until(5) { @connection_pool.closed? }
|
84
|
+
# $stderr.puts "@connection_pool.pool_state: #{@connection_pool.pool_state.inspect}"
|
84
85
|
|
85
|
-
wait_until(2) { @connection_pool.closed? }
|
86
|
-
$stderr.puts "@connection_pool.pool_state: #{@connection_pool.pool_state.inspect}"
|
87
86
|
@connection_pool.should be_closed
|
88
87
|
|
89
88
|
lambda do
|
@@ -107,8 +106,8 @@ describe ZK::Pool do
|
|
107
106
|
@connection_pool.checkout(true)
|
108
107
|
end
|
109
108
|
|
110
|
-
th.join_until { @connection_pool.count_waiters > 0 }
|
111
|
-
@connection_pool.count_waiters.should > 0
|
109
|
+
# th.join_until { @connection_pool.count_waiters > 0 }
|
110
|
+
# @connection_pool.count_waiters.should > 0
|
112
111
|
|
113
112
|
@connection_pool.force_close!
|
114
113
|
|
@@ -126,21 +125,21 @@ describe ZK::Pool do
|
|
126
125
|
end
|
127
126
|
|
128
127
|
@connection_pool.with_connection do |zk|
|
129
|
-
|
128
|
+
# $stderr.puts "registering callback"
|
130
129
|
zk.watcher.register(@path) do |event|
|
131
|
-
|
130
|
+
# $stderr.puts "callback fired! event: #{event.inspect}"
|
132
131
|
|
133
132
|
@callback_called = true
|
134
133
|
event.path.should == @path
|
135
|
-
|
134
|
+
# $stderr.puts "signaling other waiters"
|
136
135
|
end
|
137
136
|
|
138
|
-
|
137
|
+
# $stderr.puts "setting up watcher"
|
139
138
|
zk.exists?(@path, :watch => true).should be_false
|
140
139
|
end
|
141
140
|
|
142
141
|
@connection_pool.with_connection do |zk|
|
143
|
-
|
142
|
+
# $stderr.puts "creating path"
|
144
143
|
zk.create(@path, "", :mode => :ephemeral).should == @path
|
145
144
|
end
|
146
145
|
|
@@ -148,7 +147,53 @@ describe ZK::Pool do
|
|
148
147
|
|
149
148
|
@callback_called.should be_true
|
150
149
|
end
|
151
|
-
|
150
|
+
|
151
|
+
# These tests are seriously yucky, but they show that when a client is !connected?
|
152
|
+
# the pool behaves properly and will not return that client to the caller.
|
153
|
+
|
154
|
+
describe 'health checking with disconnected client' do
|
155
|
+
before do
|
156
|
+
wait_until(2) { @connection_pool.available_size == 2 }
|
157
|
+
@connection_pool.available_size.should == 2
|
158
|
+
|
159
|
+
@connections = @connection_pool.connections
|
160
|
+
@connections.length.should == 2
|
161
|
+
|
162
|
+
@cnx1 = @connections.shift
|
163
|
+
|
164
|
+
mock_sub = flexmock(:subscription)
|
165
|
+
|
166
|
+
@mcnx1 = flexmock(@cnx1) do |m|
|
167
|
+
m.should_receive(:connected?).at_least.once.and_return(false)
|
168
|
+
m.should_receive(:on_connected).with(Proc).at_least.once.and_return(mock_sub)
|
169
|
+
end
|
170
|
+
|
171
|
+
@connections.unshift(@mcnx1)
|
172
|
+
end
|
173
|
+
|
174
|
+
after do
|
175
|
+
@connections.delete(@mcnx1)
|
176
|
+
@connections.unshift(@cnx1)
|
177
|
+
[@cnx1, @cnx2].each { |c| @connection_pool.checkin(c) }
|
178
|
+
end
|
179
|
+
|
180
|
+
it %[should remove the disconnected client from the pool] do
|
181
|
+
@connection_pool.available_size.should == 2
|
182
|
+
|
183
|
+
@cnx2 = @connection_pool.checkout
|
184
|
+
|
185
|
+
# this is gross and relies on knowing internal state
|
186
|
+
@connection_pool.checkout(false).should be_false
|
187
|
+
|
188
|
+
@cnx2.should_not be_nil
|
189
|
+
@cnx2.should_not == @mcnx1
|
190
|
+
|
191
|
+
@connection_pool.available_size.should == 0
|
192
|
+
@connections.should include(@mcnx1)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end # Simple
|
152
197
|
|
153
198
|
describe :Bounded do
|
154
199
|
before do
|
@@ -156,6 +201,7 @@ describe ZK::Pool do
|
|
156
201
|
@max_clients = 2
|
157
202
|
@connection_pool = ZK::Pool::Bounded.new("localhost:#{ZK_TEST_PORT}", :min_clients => @min_clients, :max_clients => @max_clients, :timeout => @timeout)
|
158
203
|
@connection_pool.should be_open
|
204
|
+
wait_until(2) { @connection_pool.available_size > 0 }
|
159
205
|
end
|
160
206
|
|
161
207
|
after do
|
@@ -180,44 +226,25 @@ describe ZK::Pool do
|
|
180
226
|
# end
|
181
227
|
|
182
228
|
it %[should grow if it can] do
|
183
|
-
|
229
|
+
wait_until(2) { @connection_pool.available_size > 0 }
|
230
|
+
@connection_pool.available_size.should > 0
|
184
231
|
|
185
232
|
@connection_pool.size.should == 1
|
186
233
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
q1.pop # block here
|
191
|
-
end
|
192
|
-
end
|
234
|
+
logger.debug { "checking out @cnx1" }
|
235
|
+
@cnx1 = @connection_pool.checkout
|
236
|
+
@cnx1.should_not be_false
|
193
237
|
|
194
|
-
|
195
|
-
th1[:cnx].should_not be_nil
|
238
|
+
@connection_pool.can_grow_pool?.should be_true
|
196
239
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
th2.join_until(2) { th2[:cnx] }
|
240
|
+
logger.debug { "checking out @cnx2" }
|
241
|
+
@cnx2 = @connection_pool.checkout
|
242
|
+
@cnx2.should_not be_false
|
243
|
+
@cnx2.should be_connected
|
205
244
|
|
206
|
-
|
207
|
-
th2[:cnx].should be_connected
|
245
|
+
@cnx1.object_id.should_not == @cnx2.object_id
|
208
246
|
|
209
|
-
@connection_pool.
|
210
|
-
@connection_pool.available_size.should be_zero
|
211
|
-
|
212
|
-
2.times { q1.enq(:release_cnx) }
|
213
|
-
|
214
|
-
lambda do
|
215
|
-
th1.join(1).should == th1
|
216
|
-
th2.join(1).should == th2
|
217
|
-
end.should_not raise_error
|
218
|
-
|
219
|
-
@connection_pool.size.should == 2
|
220
|
-
@connection_pool.available_size.should == 2
|
247
|
+
[@cnx1, @cnx2].each { |c| @connection_pool.checkin(c) }
|
221
248
|
end
|
222
249
|
|
223
250
|
it %[should not grow past max_clients and block] do
|
@@ -226,104 +253,49 @@ describe ZK::Pool do
|
|
226
253
|
|
227
254
|
threads = []
|
228
255
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
end
|
256
|
+
@cnx1 = @connection_pool.checkout
|
257
|
+
@cnx1.should_not be_false
|
258
|
+
|
259
|
+
@connection_pool.can_grow_pool?.should be_true
|
260
|
+
|
261
|
+
@cnx2 = @connection_pool.checkout
|
262
|
+
@cnx2.should_not be_false
|
237
263
|
|
238
|
-
|
239
|
-
|
264
|
+
@connection_pool.can_grow_pool?.should be_false
|
265
|
+
|
266
|
+
logger.debug { "spawning losing thread" }
|
240
267
|
|
241
268
|
loser = Thread.new do
|
242
269
|
@connection_pool.with_connection do |cnx|
|
243
270
|
Thread.current[:cnx] = cnx
|
271
|
+
logger.debug { "Losing thread got connection" }
|
244
272
|
lose_q.pop
|
245
273
|
end
|
274
|
+
logger.debug { "losing thread exiting" }
|
246
275
|
end
|
247
276
|
|
248
|
-
|
249
|
-
@connection_pool.count_waiters
|
277
|
+
# loser.join_until(5) { @connection_pool.count_waiters > 0 }
|
278
|
+
# logger.debug { "count waiters: #{@connection_pool.count_waiters}" }
|
279
|
+
# @connection_pool.count_waiters.should == 1
|
250
280
|
|
251
281
|
loser[:cnx].should be_nil
|
252
282
|
|
253
|
-
|
254
|
-
|
255
|
-
lambda { threads.each { |th| th.join(2).should == th } }.should_not raise_error
|
283
|
+
[@cnx1, @cnx2].each { |c| @connection_pool.checkin(c) }
|
256
284
|
|
257
285
|
loser.join_until(2) { loser[:cnx] }
|
258
|
-
|
259
286
|
loser[:cnx].should_not be_nil
|
260
287
|
|
261
288
|
lose_q.enq(:release)
|
262
289
|
|
263
290
|
lambda { loser.join(2).should == loser }.should_not raise_error
|
264
291
|
|
292
|
+
logger.debug { "joined losing thread" }
|
293
|
+
|
265
294
|
@connection_pool.count_waiters.should be_zero
|
266
295
|
@connection_pool.available_size.should == 2
|
267
296
|
@connection_pool.size.should == 2
|
268
297
|
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe 'health checking' do
|
272
|
-
before do
|
273
|
-
@connections = @connection_pool.connections
|
274
|
-
@connections.length.should == 1
|
275
|
-
|
276
|
-
@cnx1 = @connections.first
|
277
|
-
end
|
278
|
-
|
279
|
-
describe 'disconnected client' do
|
280
|
-
before do
|
281
|
-
flexmock(@cnx1) do |m|
|
282
|
-
m.should_receive(:connected?).and_return(false)
|
283
|
-
end
|
284
|
-
|
285
|
-
@cnx2 = nil
|
286
|
-
|
287
|
-
th = Thread.new do
|
288
|
-
@connection_pool.with_connection do |cnx|
|
289
|
-
@cnx2 = cnx
|
290
|
-
end
|
291
|
-
end
|
298
|
+
end # should grow to max_clients
|
292
299
|
|
293
|
-
th.join_while { @cnx2.nil? }
|
294
|
-
end
|
295
|
-
|
296
|
-
it %[should create a new client and return it] do
|
297
|
-
@cnx2.should_not be_nil
|
298
|
-
@cnx2.should_not == @cnx1
|
299
|
-
end
|
300
|
-
|
301
|
-
it %[should remove the disconnected client from the pool] do
|
302
|
-
@connection_pool.available_size.should == 1
|
303
|
-
end
|
304
|
-
|
305
|
-
it %[should still have the original client in its array of all connections] do
|
306
|
-
@connections.should include(@cnx1)
|
307
|
-
end
|
308
|
-
|
309
|
-
describe 'when connected event fires' do
|
310
|
-
before do
|
311
|
-
@event = flexmock(:event) do |m|
|
312
|
-
m.should_receive(:type).and_return(-1)
|
313
|
-
m.should_receive(:zk=).with(any())
|
314
|
-
m.should_receive(:node_event?).and_return(false)
|
315
|
-
m.should_receive(:state_event?).and_return(true)
|
316
|
-
m.should_receive(:state).and_return(ZookeeperConstants::ZOO_CONNECTED_STATE)
|
317
|
-
end
|
318
|
-
|
319
|
-
@cnx1.watcher.process(@event)
|
320
|
-
end
|
321
|
-
|
322
|
-
it %[should add the connection back into the pool] do
|
323
|
-
@connection_pool.available_size.should == 2
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
300
|
end
|
329
301
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ZK::Threadpool do
|
4
4
|
|
@@ -55,13 +55,16 @@ describe ZK::Threadpool do
|
|
55
55
|
describe :start! do
|
56
56
|
it %[should be able to start a threadpool that had previously been shutdown (reuse)] do
|
57
57
|
@threadpool.shutdown
|
58
|
-
@threadpool.start
|
58
|
+
@threadpool.start!.should be_true
|
59
59
|
|
60
60
|
@threadpool.should be_running
|
61
61
|
|
62
62
|
@rval = nil
|
63
63
|
|
64
|
-
@threadpool.defer
|
64
|
+
@threadpool.defer do
|
65
|
+
@rval = true
|
66
|
+
end
|
67
|
+
|
65
68
|
wait_until(2) { @rval }
|
66
69
|
@rval.should be_true
|
67
70
|
end
|
data/zk.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_development_dependency 'rspec', '~> 2.4.0'
|
17
17
|
s.add_development_dependency 'wirble'
|
18
18
|
s.add_development_dependency 'flexmock', '~> 0.8.10'
|
19
|
+
s.add_development_dependency 'ZenTest', '~> 4.5.0'
|
19
20
|
|
20
21
|
s.files = `git ls-files`.split("\n")
|
21
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 1
|
10
|
+
version: 0.7.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan D. Simms
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-06-08 00:00:00 +00:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -81,6 +81,22 @@ dependencies:
|
|
81
81
|
version: 0.8.10
|
82
82
|
type: :development
|
83
83
|
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: ZenTest
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 43
|
93
|
+
segments:
|
94
|
+
- 4
|
95
|
+
- 5
|
96
|
+
- 0
|
97
|
+
version: 4.5.0
|
98
|
+
type: :development
|
99
|
+
version_requirements: *id005
|
84
100
|
description: A high-level wrapper around the zookeeper driver
|
85
101
|
email:
|
86
102
|
- simms@hp.com
|
@@ -92,12 +108,19 @@ extensions: []
|
|
92
108
|
extra_rdoc_files: []
|
93
109
|
|
94
110
|
files:
|
111
|
+
- .dotfiles/rspec-logging
|
95
112
|
- .gitignore
|
113
|
+
- .yardopts
|
96
114
|
- Gemfile
|
97
115
|
- LICENSE
|
116
|
+
- README.markdown
|
98
117
|
- Rakefile
|
99
118
|
- lib/z_k.rb
|
100
119
|
- lib/z_k/client.rb
|
120
|
+
- lib/z_k/client/base.rb
|
121
|
+
- lib/z_k/client/conveniences.rb
|
122
|
+
- lib/z_k/client/state_mixin.rb
|
123
|
+
- lib/z_k/client/unixisms.rb
|
101
124
|
- lib/z_k/election.rb
|
102
125
|
- lib/z_k/event_handler.rb
|
103
126
|
- lib/z_k/event_handler_subscription.rb
|
@@ -112,19 +135,20 @@ files:
|
|
112
135
|
- lib/z_k/threadpool.rb
|
113
136
|
- lib/z_k/version.rb
|
114
137
|
- lib/zk.rb
|
115
|
-
- spec/client_pool_spec.rb
|
116
|
-
- spec/client_spec.rb
|
117
|
-
- spec/election_spec.rb
|
118
|
-
- spec/locker_spec.rb
|
119
138
|
- spec/log4j.properties
|
120
139
|
- spec/message_queue_spec.rb
|
121
|
-
- spec/mongoid_spec.rb
|
122
140
|
- spec/spec_helper.rb
|
123
141
|
- spec/support/bogus_mongoid.rb
|
142
|
+
- spec/support/logging_progress_bar_formatter.rb
|
124
143
|
- spec/support/queuey_thread.rb
|
125
144
|
- spec/test_file.txt
|
126
|
-
- spec/threadpool_spec.rb
|
127
145
|
- spec/watch_spec.rb
|
146
|
+
- spec/z_k/client_spec.rb
|
147
|
+
- spec/z_k/election_spec.rb
|
148
|
+
- spec/z_k/locker_spec.rb
|
149
|
+
- spec/z_k/mongoid_spec.rb
|
150
|
+
- spec/z_k/pool_spec.rb
|
151
|
+
- spec/z_k/threadpool_spec.rb
|
128
152
|
- spec/zookeeper_spec.rb
|
129
153
|
- zk.gemspec
|
130
154
|
has_rdoc: true
|
@@ -161,18 +185,5 @@ rubygems_version: 1.6.2
|
|
161
185
|
signing_key:
|
162
186
|
specification_version: 3
|
163
187
|
summary: A high-level wrapper around the zookeeper driver
|
164
|
-
test_files:
|
165
|
-
|
166
|
-
- spec/client_spec.rb
|
167
|
-
- spec/election_spec.rb
|
168
|
-
- spec/locker_spec.rb
|
169
|
-
- spec/log4j.properties
|
170
|
-
- spec/message_queue_spec.rb
|
171
|
-
- spec/mongoid_spec.rb
|
172
|
-
- spec/spec_helper.rb
|
173
|
-
- spec/support/bogus_mongoid.rb
|
174
|
-
- spec/support/queuey_thread.rb
|
175
|
-
- spec/test_file.txt
|
176
|
-
- spec/threadpool_spec.rb
|
177
|
-
- spec/watch_spec.rb
|
178
|
-
- spec/zookeeper_spec.rb
|
188
|
+
test_files: []
|
189
|
+
|