zk 0.8.9 → 0.9.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.
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ZK::Client::Multiplexed', :client => :multiplexed do
4
+ before do
5
+ @zk = ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}").tap do |zk|
6
+ wait_until { zk.connected? }
7
+ end
8
+
9
+ @zk.rm_rf('/test')
10
+ end
11
+
12
+ after do
13
+ @zk.rm_rf('/test')
14
+ @zk.close!
15
+
16
+ wait_until(2) { @zk.closed? }
17
+ end
18
+
19
+ it_should_behave_like 'client'
20
+ end
@@ -1,235 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ZK::Client do
4
- before do
5
- @connection_string = "localhost:#{ZK_TEST_PORT}"
6
- @zk = ZK.new(@connection_string)
7
- wait_until{ @zk.connected? }
8
- @zk.rm_rf('/test')
9
- end
10
-
11
- after do
12
- @zk.rm_rf('/test')
13
- @zk.close!
14
-
15
- wait_until(2) { @zk.closed? }
16
- end
17
-
18
- describe :mkdir_p do
19
- before(:each) do
20
- @path_ary = %w[test mkdir_p path creation]
21
- @bogus_path = File.join('/', *@path_ary)
22
- end
23
-
24
- it %[should create all intermediate paths for the path givem] do
25
- @zk.should_not be_exists(@bogus_path)
26
- @zk.should_not be_exists(File.dirname(@bogus_path))
27
- @zk.mkdir_p(@bogus_path)
28
- @zk.should be_exists(@bogus_path)
29
- end
30
- end
31
-
32
- describe :stat do
33
- describe 'for a missing node' do
34
- before do
35
- @missing_path = '/thispathdoesnotexist'
36
- @zk.delete(@missing_path) rescue ZK::Exceptions::NoNode
37
- end
38
-
39
- it %[should not raise any error] do
40
- lambda { @zk.stat(@missing_path) }.should_not raise_error
41
- end
42
-
43
- it %[should return a Stat object] do
44
- @zk.stat(@missing_path).should be_kind_of(ZookeeperStat::Stat)
45
- end
46
-
47
- it %[should return a stat that not exists?] do
48
- @zk.stat(@missing_path).should_not be_exists
49
- end
50
- end
51
- end
52
-
53
- describe :block_until_node_deleted do
54
- before do
55
- @path = '/_bogualkjdhsna'
56
- end
57
-
58
- describe 'no node initially' do
59
- before do
60
- @zk.exists?(@path).should be_false
61
- end
62
-
63
- it %[should not block] do
64
- @a = false
65
-
66
- th = Thread.new do
67
- @zk.block_until_node_deleted(@path)
68
- @a = true
69
- end
70
-
71
- th.join(2)
72
- @a.should be_true
73
- end
74
- end
75
-
76
- describe 'node exists initially' do
77
- before do
78
- @zk.create(@path, '', :mode => :ephemeral)
79
- @zk.exists?(@path).should be_true
80
- end
81
-
82
- it %[should block until the node is deleted] do
83
- @a = false
84
-
85
- th = Thread.new do
86
-
87
- @zk.block_until_node_deleted(@path)
88
- @a = true
89
- end
90
-
91
- Thread.pass
92
- @a.should be_false
93
-
94
- @zk.delete(@path)
95
-
96
- wait_until(2) { @a }
97
- @a.should be_true
98
- end
99
-
100
- shared_examples_for 'session death' do
101
- def deliver_session_event_to(event_num, zk)
102
- # jeez, Zookeeper callbacks are so frustratingly stupid
103
- bogus_event = ZookeeperCallbacks::WatcherCallback.new
104
- bogus_event.initialize_context(:type => -1, :state => event_num, :path => '', :context => 'bogustestevent')
105
- # XXX: this is bad because we're in the wrong thread, but we'll fix this after the next Zookeeper release
106
- zk.event_handler.process(bogus_event)
107
- end
108
-
109
- before do
110
- @other_zk = ZK.new(@connection_string)
111
- end
112
-
113
- after do
114
- @other_zk.close! unless @other_zk.closed?
115
- end
116
-
117
- it %[should wake up in the case of an expired session and throw an exception] do
118
- @a = false
119
-
120
- @other_zk.event_handler.register_state_handler(zoo_state) do |event|
121
- @a = event
122
- end
123
-
124
- th = Thread.new do
125
- @other_zk.block_until_node_deleted(@path)
126
- end
127
-
128
- wait_until(2) { th.status == 'sleep' }
129
-
130
- # not on the other thread, this may be bad
131
- deliver_session_event_to(zoo_state, @other_zk)
132
-
133
- # ditto, this is probably happening synchrnously
134
- wait_until(2) { @a }
135
-
136
- lambda { th.join(2) }.should raise_error(zoo_error_class)
137
- end
138
- end
139
-
140
- describe 'exceptional conditions' do
141
- describe 'ZOO_EXPIRED_SESSION_STATE' do
142
- let(:zoo_state) { ZookeeperConstants::ZOO_EXPIRED_SESSION_STATE }
143
- let(:zoo_error_class) { ZookeeperExceptions::ZookeeperException::SessionExpired }
144
-
145
- it_behaves_like 'session death'
146
- end
147
-
148
- describe 'ZOO_CONNECTING_STATE' do
149
- let(:zoo_state) { ZookeeperConstants::ZOO_CONNECTING_STATE }
150
- let(:zoo_error_class) { ZookeeperExceptions::ZookeeperException::NotConnected }
151
-
152
- it_behaves_like 'session death'
153
- end
154
-
155
- describe 'ZOO_CLOSED_STATE' do
156
- let(:zoo_state) { ZookeeperConstants::ZOO_CLOSED_STATE }
157
- let(:zoo_error_class) { ZookeeperExceptions::ZookeeperException::ConnectionClosed }
158
-
159
- it_behaves_like 'session death'
160
- end
161
- end
162
- end
163
- end
164
-
165
- describe 'session_id and session_passwd' do
166
- it %[should expose the underlying session_id] do
167
- @zk.session_id.should be_kind_of(Fixnum)
168
- end
169
-
170
- it %[should expose the underlying session_passwd] do
171
- @zk.session_passwd.should be_kind_of(String)
172
- end
173
- end
174
-
175
- describe 'reopen' do
176
- describe 'watchers' do
177
- before do
178
- @path = '/testwatchers'
179
- @queue = Queue.new
180
- end
181
-
182
- after do
183
- @zk.delete(@path)
184
- end
185
-
186
- def ensure_event_delivery!
187
- @sub ||= @zk.event_handler.register(@path) do |event|
188
- logger.debug { "got event: #{event.inspect}" }
189
- @queue << event
190
- end
191
-
192
- @zk.exists?(@path, :watch => true).should be_false
193
- @zk.create(@path, '')
194
-
195
- logger.debug { "waiting for event delivery" }
196
-
197
- wait_until(2) do
198
- begin
199
- @events << @queue.pop(true)
200
- true
201
- rescue ThreadError
202
- false
203
- end
204
- end
205
-
206
- # first watch delivered correctly
207
- @events.length.should > 0
208
- end
209
-
210
- it %[should fire re-registered watchers after reopen (#9)] do
211
- @events = []
212
-
213
- logger.debug { "ensure event delivery" }
214
- ensure_event_delivery!
215
-
216
- logger.debug { "reopening connection" }
217
- @zk.reopen
218
-
219
- wait_until(2) { @zk.connected? }
220
-
221
- logger.debug { "deleting path" }
222
- @zk.delete(@path)
223
-
224
- logger.debug { "clearing events" }
225
- @events.clear
226
-
227
- logger.debug { "taunt them a second time" }
228
- ensure_event_delivery!
229
- end
230
- end
231
- end
3
+ describe ZK::Client::Threaded do
4
+ include_context 'threaded client connection'
5
+ it_should_behave_like 'client'
232
6
  end
233
7
 
234
-
235
-
@@ -162,21 +162,22 @@ describe ZK::Election do
162
162
  @obama.zk.close!
163
163
  wait_until { @palin_won }
164
164
 
165
- zk = ZK.new('localhost:2181')
166
- newbama = ZK::Election::Candidate.new(zk, @election_name, :data => @data1)
165
+ ZK.open('localhost:2181') do |zk|
166
+ newbama = ZK::Election::Candidate.new(zk, @election_name, :data => @data1)
167
167
 
168
- win_again = false
168
+ win_again = false
169
169
 
170
- newbama.on_winning_election do
171
- win_again = true
172
- end
170
+ newbama.on_winning_election do
171
+ win_again = true
172
+ end
173
173
 
174
- newbama.vote!
175
- wait_until { newbama.voted? }
174
+ newbama.vote!
175
+ wait_until { newbama.voted? }
176
176
 
177
- newbama.should be_voted
178
- win_again.should be_false
179
- newbama.should_not be_leader
177
+ newbama.should be_voted
178
+ win_again.should be_false
179
+ newbama.should_not be_leader
180
+ end
180
181
  end
181
182
  end
182
183
  end
@@ -72,8 +72,47 @@ describe 'ZK::Client#locker' do
72
72
  thread.join(10)
73
73
  array.length.should == 2
74
74
  end
75
+
75
76
  end
76
77
 
78
+ # describe 'Locker thread safety' do
79
+ # describe 'exception' do
80
+ # before do
81
+ # @path = '/zk_test'
82
+ # @zk = ZK.new("localhost:#{ZK_TEST_PORT}")
83
+ # @zk.create(@path) rescue ZK::Exceptions::NodeExists
84
+ # end
85
+
86
+ # after do
87
+ # @zk.rm_rf(@path)
88
+ # @zk.close!
89
+ # end
90
+
91
+ # it %[should raise an EventDispatchThreadException if called in the dispatch thread] do
92
+ # @exception = nil
93
+
94
+ # @zk.register(@path) do |event|
95
+ # @zk.event_dispatch_thread?.should be_true
96
+
97
+ # begin
98
+ # @zk.with_lock('boguslockname') do
99
+ # raise "Should never have gotten this far"
100
+ # end
101
+ # rescue Exception => e
102
+ # @exception = e
103
+ # end
104
+ # end
105
+
106
+ # @zk.exists?(@path, :watch => true)
107
+
108
+ # @zk.set(@path, 'blah')
109
+
110
+ # wait_until(2) { @exception }.should be_kind_of(ZK::Exceptions::EventDispatchThreadException)
111
+ # end
112
+ # end
113
+
114
+ # end
115
+
77
116
  shared_examples_for 'SharedLocker' do
78
117
  before do
79
118
  @shared_locker = ZK::Locker.shared_locker(zk, path)
@@ -207,6 +246,7 @@ shared_examples_for 'ExclusiveLocker' do
207
246
  @ex_locker.should be_locked
208
247
  end
209
248
  end
249
+
210
250
  end
211
251
  end # ExclusiveLocker
212
252
 
@@ -366,8 +406,8 @@ end # shared-exclusive interaction
366
406
 
367
407
 
368
408
  describe ZK::Locker do
369
- let(:zk) { ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => :default) }
370
- let(:zk2) { ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => :default) }
409
+ let(:zk) { ZK.new("localhost:#{ZK_TEST_PORT}") }
410
+ let(:zk2) { ZK.new("localhost:#{ZK_TEST_PORT}") }
371
411
  let(:zk3) { ZK.new("localhost:#{ZK_TEST_PORT}") }
372
412
 
373
413
  let(:connections) { [zk, zk2, zk3] }
@@ -437,9 +477,35 @@ describe "ZK::Locker chrooted" do
437
477
  end
438
478
  end.should raise_error(ZK::Exceptions::NonExistentRootError)
439
479
 
440
-
441
480
  @got_lock.should_not be_true
442
481
  end
443
482
  end
444
483
  end
445
484
 
485
+ describe 'ZK::Locker Multiplexed client', :client => :multiplexed do
486
+ let(:zk) { ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}") }
487
+ let(:zk2) { ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}") }
488
+ let(:zk3) { ZK::Client::Multiplexed.new("localhost:#{ZK_TEST_PORT}") }
489
+
490
+ let(:connections) { [zk, zk2, zk3] }
491
+
492
+ let(:path) { "shlock" }
493
+ let(:root_lock_path) { "/_zklocking/#{path}" }
494
+
495
+ before do
496
+ wait_until{ connections.all?(&:connected?) }
497
+ pending "Mutliplexed client locking is broken"
498
+ end
499
+
500
+ after do
501
+ connections.each { |c| c.close! }
502
+ wait_until { !connections.any?(&:connected?) }
503
+ end
504
+
505
+ it_should_behave_like 'SharedLocker'
506
+ it_should_behave_like 'ExclusiveLocker'
507
+ it_should_behave_like 'shared-exclusive interaction'
508
+ end # ZK::Locker
509
+
510
+
511
+
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
2
 
3
3
  describe ZK do
4
4
  before do
5
- @zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => nil)
5
+ @zk = ZK.new("localhost:#{ZK_TEST_PORT}")
6
6
 
7
7
  @base_path = "/zktests"
8
8
  @zk.rm_rf(@base_path)
@@ -48,7 +48,7 @@ describe ZK do
48
48
  wait_until(2) { !@zk.connected? }
49
49
  @zk.should_not be_connected
50
50
 
51
- @zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => nil)
51
+ @zk = ZK.new("localhost:#{ZK_TEST_PORT}")
52
52
  wait_until{ @zk.connected? }
53
53
  @zk.exists?("#{@base_path}/test").should be_false
54
54
  end
@@ -59,7 +59,7 @@ describe ZK do
59
59
  @zk.exists?(created).should_not be_nil
60
60
  @zk.close!
61
61
 
62
- @zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => nil)
62
+ @zk = ZK.new("localhost:#{ZK_TEST_PORT}")
63
63
  wait_until{ @zk.connected? }
64
64
  @zk.exists?(created).should be_false
65
65
  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 'slyphon-zookeeper', '~> 0.3.0'
16
-
15
+ s.add_runtime_dependency 'slyphon-zookeeper', '~> 0.8.1'
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,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
9
8
  - 9
10
- version: 0.8.9
9
+ - 0
10
+ version: 0.9.0
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: 2012-04-21 00:00:00 Z
19
+ date: 2012-04-23 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: slyphon-zookeeper
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 19
29
+ hash: 61
30
30
  segments:
31
31
  - 0
32
- - 3
33
- - 0
34
- version: 0.3.0
32
+ - 8
33
+ - 1
34
+ version: 0.8.1
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  description: |
@@ -55,11 +55,15 @@ files:
55
55
  - Gemfile
56
56
  - LICENSE
57
57
  - README.markdown
58
+ - RELEASES.markdown
58
59
  - Rakefile
59
60
  - lib/z_k.rb
60
61
  - lib/z_k/client.rb
61
62
  - lib/z_k/client/base.rb
63
+ - lib/z_k/client/continuation_proxy.rb
62
64
  - lib/z_k/client/conveniences.rb
65
+ - lib/z_k/client/drop_box.rb
66
+ - lib/z_k/client/multiplexed.rb
63
67
  - lib/z_k/client/state_mixin.rb
64
68
  - lib/z_k/client/threaded.rb
65
69
  - lib/z_k/client/unixisms.rb
@@ -80,12 +84,20 @@ files:
80
84
  - spec/informal/lock_with_dead_session.rb
81
85
  - spec/log4j.properties
82
86
  - spec/message_queue_spec.rb
87
+ - spec/shared/client_contexts.rb
88
+ - spec/shared/client_examples.rb
83
89
  - spec/spec_helper.rb
84
90
  - spec/support/bogus_mongoid.rb
91
+ - spec/support/logging.rb
85
92
  - spec/support/logging_progress_bar_formatter.rb
86
93
  - spec/support/queuey_thread.rb
94
+ - spec/support/special_happy_funtime_error.rb
95
+ - spec/support/wait_watchers.rb
87
96
  - spec/test_file.txt
88
97
  - spec/watch_spec.rb
98
+ - spec/z_k/client/drop_box_spec.rb
99
+ - spec/z_k/client/locking_and_session_death_spec.rb
100
+ - spec/z_k/client/multiplexed_spec.rb
89
101
  - spec/z_k/client_spec.rb
90
102
  - spec/z_k/election_spec.rb
91
103
  - spec/z_k/extensions_spec.rb
@@ -132,12 +144,20 @@ test_files:
132
144
  - spec/informal/lock_with_dead_session.rb
133
145
  - spec/log4j.properties
134
146
  - spec/message_queue_spec.rb
147
+ - spec/shared/client_contexts.rb
148
+ - spec/shared/client_examples.rb
135
149
  - spec/spec_helper.rb
136
150
  - spec/support/bogus_mongoid.rb
151
+ - spec/support/logging.rb
137
152
  - spec/support/logging_progress_bar_formatter.rb
138
153
  - spec/support/queuey_thread.rb
154
+ - spec/support/special_happy_funtime_error.rb
155
+ - spec/support/wait_watchers.rb
139
156
  - spec/test_file.txt
140
157
  - spec/watch_spec.rb
158
+ - spec/z_k/client/drop_box_spec.rb
159
+ - spec/z_k/client/locking_and_session_death_spec.rb
160
+ - spec/z_k/client/multiplexed_spec.rb
141
161
  - spec/z_k/client_spec.rb
142
162
  - spec/z_k/election_spec.rb
143
163
  - spec/z_k/extensions_spec.rb