zk-eventmachine 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.dev_extras/README +5 -0
- data/.dev_extras/rspec +1 -0
- data/.dev_extras/rvmrc +1 -0
- data/.dev_extras/slyphon-project.vimrc +18 -0
- data/.gitignore +8 -0
- data/Gemfile +9 -0
- data/LICENSE +19 -0
- data/README.markdown +8 -0
- data/Rakefile +2 -0
- data/lib/z_k/z_k_event_machine/callback.rb +256 -0
- data/lib/z_k/z_k_event_machine/client.rb +122 -0
- data/lib/z_k/z_k_event_machine/deferred.rb +39 -0
- data/lib/z_k/z_k_event_machine/event_handler_e_m.rb +34 -0
- data/lib/z_k/z_k_event_machine/iterator.rb +229 -0
- data/lib/z_k/z_k_event_machine/unixisms.rb +124 -0
- data/lib/z_k/z_k_event_machine/version.rb +5 -0
- data/lib/z_k/z_k_event_machine.rb +24 -0
- data/lib/zk-eventmachine.rb +2 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/extensions.rb +44 -0
- data/spec/support/logging.rb +9 -0
- data/spec/support/logging_progress_bar_formatter.rb +26 -0
- data/spec/z_k/z_k_event_machine/callback_spec.rb +135 -0
- data/spec/z_k/z_k_event_machine/client_spec.rb +693 -0
- data/spec/z_k/z_k_event_machine/event_handler_e_m_spec.rb +104 -0
- data/spec/z_k/z_k_event_machine/unixisms_spec.rb +122 -0
- data/zk-eventmachine.gemspec +28 -0
- metadata +212 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ZK::ZKEventMachine
|
4
|
+
describe 'EventHandlerEM' do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 2.0
|
7
|
+
|
8
|
+
before do
|
9
|
+
@zk = ::ZK.new
|
10
|
+
@base_path = '/zk-em-testing'
|
11
|
+
@zk.rm_rf(@base_path)
|
12
|
+
@zk.mkdir_p(@base_path)
|
13
|
+
@zkem = ZK::ZKEventMachine::Client.new('localhost:2181')
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
@zk.rm_rf(@base_path)
|
18
|
+
@zk.close!
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# this is a test of event delivery in general, not just of the
|
23
|
+
# EventHandlerEM implementation
|
24
|
+
|
25
|
+
describe 'data event' do
|
26
|
+
include EventedSpec::EMSpec
|
27
|
+
|
28
|
+
before do
|
29
|
+
@path = "#{@base_path}/blah"
|
30
|
+
@data = "this is data"
|
31
|
+
@new_data = "this is other data"
|
32
|
+
|
33
|
+
@child_path = [@path, 'child'].join('/')
|
34
|
+
end
|
35
|
+
|
36
|
+
it %[should call the callback when the data of a watched node changes] do
|
37
|
+
@zkem.connect do
|
38
|
+
@zkem.event_handler.register(@path) do |event|
|
39
|
+
EM.reactor_thread?.should be_true
|
40
|
+
event.should be_node_changed
|
41
|
+
@zkem.close! { done }
|
42
|
+
end
|
43
|
+
|
44
|
+
common_eb = lambda { |exc| raise exc }
|
45
|
+
|
46
|
+
@zkem.create(@path, @data) do |exc,path|
|
47
|
+
raise exc if exc
|
48
|
+
|
49
|
+
@zkem.stat(@path, :watch => true) do |e,*a|
|
50
|
+
raise e if e
|
51
|
+
|
52
|
+
@zkem.set(@path, @new_data) { |e| raise e if e }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it %[should call the callback when the children of the watched node change] do
|
59
|
+
@zkem.connect do
|
60
|
+
@zkem.event_handler.register(@path) do |event|
|
61
|
+
EM.reactor_thread?.should be_true
|
62
|
+
event.should be_node_child
|
63
|
+
@zkem.close! { done }
|
64
|
+
end
|
65
|
+
|
66
|
+
eb_raise = lambda { |e| raise e if e }
|
67
|
+
|
68
|
+
@zkem.create(@path, @data).callback { |*|
|
69
|
+
@zkem.children(@path, :watch => true).callback { |ary,stat|
|
70
|
+
logger.debug { "called back with: #{ary.inspect}" }
|
71
|
+
ary.should be_empty
|
72
|
+
stat.should be_kind_of(ZookeeperStat::Stat)
|
73
|
+
|
74
|
+
@zkem.create(@child_path, '') { |p|
|
75
|
+
p.should == @path
|
76
|
+
|
77
|
+
}.errback(&eb_raise)
|
78
|
+
}.errback(&eb_raise)
|
79
|
+
}.errback(&eb_raise)
|
80
|
+
end
|
81
|
+
end # it
|
82
|
+
|
83
|
+
it %[should call back the registered block when the node is deleted] do
|
84
|
+
@zkem.connect do
|
85
|
+
@zkem.event_handler.register(@path) do |event|
|
86
|
+
EM.reactor_thread?.should be_true
|
87
|
+
event.should be_node_deleted
|
88
|
+
@zkem.close! { done }
|
89
|
+
end
|
90
|
+
|
91
|
+
eb_raise = lambda { |e| raise e if e }
|
92
|
+
|
93
|
+
@zkem.create(@path, @data).callback do |*|
|
94
|
+
@zkem.stat(@path, :watch => true).callback do |*|
|
95
|
+
@zkem.delete(@path).errback(&eb_raise)
|
96
|
+
|
97
|
+
end.errback(&eb_raise)
|
98
|
+
end.errback(&eb_raise)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ZK::ZKEventMachine
|
4
|
+
describe 'Unixisms' do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 2.0
|
7
|
+
|
8
|
+
before do
|
9
|
+
@zk = ::ZK.new
|
10
|
+
@base_path = '/zk-em-testing'
|
11
|
+
@zk.rm_rf(@base_path)
|
12
|
+
@zk.mkdir_p(@base_path)
|
13
|
+
@zkem = ZK::ZKEventMachine::Client.new('localhost:2181')
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
@zk.rm_rf(@base_path)
|
18
|
+
@zk.close!
|
19
|
+
end
|
20
|
+
|
21
|
+
def close_and_done!
|
22
|
+
@zkem.close! { done }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'mkdir_p' do
|
26
|
+
before do
|
27
|
+
@bogus_paths = [
|
28
|
+
[@base_path, 'bogus', 'path', 'to', 'qwer'].join('/'),
|
29
|
+
[@base_path, 'bogus', 'path', 'to', 'somethingelse'].join('/')
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it %[should create the path recursively] do
|
34
|
+
@zk.exists?(@bogus_paths.first).should be_false
|
35
|
+
|
36
|
+
em do
|
37
|
+
@zkem.connect do
|
38
|
+
@zkem.mkdir_p(@bogus_paths.first).callback do |p|
|
39
|
+
p.first.should == @bogus_paths.first
|
40
|
+
close_and_done!
|
41
|
+
end.errback do |e|
|
42
|
+
raise e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it %[should not error on a path that already exists] do
|
49
|
+
@zk.mkdir_p(@bogus_paths.first)
|
50
|
+
|
51
|
+
em do
|
52
|
+
@zkem.connect do
|
53
|
+
@zkem.mkdir_p(@bogus_paths.first) do |exc,p|
|
54
|
+
exc.should be_nil
|
55
|
+
p.first.should == @bogus_paths.first
|
56
|
+
close_and_done!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it %[should take an array of paths] do
|
63
|
+
@bogus_paths.each do |p|
|
64
|
+
@zk.exists?(p).should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
em do
|
68
|
+
@zkem.connect do
|
69
|
+
@zkem.mkdir_p(@bogus_paths) do |exc,paths|
|
70
|
+
exc.should be_nil
|
71
|
+
paths.should be_kind_of(Array)
|
72
|
+
@bogus_paths.each { |p| paths.should include(p) }
|
73
|
+
close_and_done!
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'rm_rf' do
|
81
|
+
em_before do
|
82
|
+
@relpaths = ['disco/foo', 'prune/bar', 'fig/bar/one', 'apple/bar/two', 'orange/quux/c/d/e']
|
83
|
+
|
84
|
+
@roots = @relpaths.map { |p| File.join(@base_path, p.split('/').first) }.uniq
|
85
|
+
@paths = @relpaths.map { |n| File.join(@base_path, n) }
|
86
|
+
|
87
|
+
@paths.each { |n| @zk.mkdir_p(n) }
|
88
|
+
end
|
89
|
+
|
90
|
+
it %[should remove the paths recursively] do
|
91
|
+
em do
|
92
|
+
@zkem.connect do
|
93
|
+
@zkem.rm_rf(@roots).callback do
|
94
|
+
@roots.each { |p| @zk.exists?(p).should be_false }
|
95
|
+
close_and_done!
|
96
|
+
end.errback do |exc|
|
97
|
+
raise exc
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end # it
|
102
|
+
|
103
|
+
it %[should use the nodejs style if a block is given] do
|
104
|
+
em do
|
105
|
+
@zkem.connect do
|
106
|
+
@zkem.rm_rf(@roots) do |exc|
|
107
|
+
if exc.nil?
|
108
|
+
@roots.each { |p| @zk.exists?(p).should be_false }
|
109
|
+
close_and_done!
|
110
|
+
else
|
111
|
+
raise exc
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "z_k/z_k_event_machine/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "zk-eventmachine"
|
7
|
+
s.version = ZK::ZKEventMachine::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jonathan D. Simms"]
|
10
|
+
s.email = ["slyphon@hp.com"]
|
11
|
+
s.homepage = "https://github.com/slyphon/zk-eventmachine"
|
12
|
+
s.summary = %q{ZK client for EventMachine-based (async) applications}
|
13
|
+
s.description = s.description
|
14
|
+
|
15
|
+
s.add_dependency('zk', '~> 0.8.1')
|
16
|
+
s.add_dependency('eventmachine', '= 0.12.10')
|
17
|
+
|
18
|
+
s.add_development_dependency('rspec', '~> 2.5.0')
|
19
|
+
s.add_development_dependency('yard', '~> 0.7.0')
|
20
|
+
s.add_development_dependency('autotest', '>= 4.4.0')
|
21
|
+
s.add_development_dependency('flexmock', '~> 0.8.10')
|
22
|
+
s.add_development_dependency('evented-spec', '~> 0.4.1')
|
23
|
+
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zk-eventmachine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jonathan D. Simms
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-17 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: zk
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 61
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 8
|
33
|
+
- 1
|
34
|
+
version: 0.8.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: eventmachine
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 59
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 12
|
49
|
+
- 10
|
50
|
+
version: 0.12.10
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 27
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 5
|
65
|
+
- 0
|
66
|
+
version: 2.5.0
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 7
|
81
|
+
- 0
|
82
|
+
version: 0.7.0
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: autotest
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 47
|
94
|
+
segments:
|
95
|
+
- 4
|
96
|
+
- 4
|
97
|
+
- 0
|
98
|
+
version: 4.4.0
|
99
|
+
type: :development
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: flexmock
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 43
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 8
|
113
|
+
- 10
|
114
|
+
version: 0.8.10
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: evented-spec
|
119
|
+
prerelease: false
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 13
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
- 4
|
129
|
+
- 1
|
130
|
+
version: 0.4.1
|
131
|
+
type: :development
|
132
|
+
version_requirements: *id007
|
133
|
+
description: ""
|
134
|
+
email:
|
135
|
+
- slyphon@hp.com
|
136
|
+
executables: []
|
137
|
+
|
138
|
+
extensions: []
|
139
|
+
|
140
|
+
extra_rdoc_files: []
|
141
|
+
|
142
|
+
files:
|
143
|
+
- .dev_extras/README
|
144
|
+
- .dev_extras/rspec
|
145
|
+
- .dev_extras/rvmrc
|
146
|
+
- .dev_extras/slyphon-project.vimrc
|
147
|
+
- .gitignore
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE
|
150
|
+
- README.markdown
|
151
|
+
- Rakefile
|
152
|
+
- lib/z_k/z_k_event_machine.rb
|
153
|
+
- lib/z_k/z_k_event_machine/callback.rb
|
154
|
+
- lib/z_k/z_k_event_machine/client.rb
|
155
|
+
- lib/z_k/z_k_event_machine/deferred.rb
|
156
|
+
- lib/z_k/z_k_event_machine/event_handler_e_m.rb
|
157
|
+
- lib/z_k/z_k_event_machine/iterator.rb
|
158
|
+
- lib/z_k/z_k_event_machine/unixisms.rb
|
159
|
+
- lib/z_k/z_k_event_machine/version.rb
|
160
|
+
- lib/zk-eventmachine.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
- spec/support/extensions.rb
|
163
|
+
- spec/support/logging.rb
|
164
|
+
- spec/support/logging_progress_bar_formatter.rb
|
165
|
+
- spec/z_k/z_k_event_machine/callback_spec.rb
|
166
|
+
- spec/z_k/z_k_event_machine/client_spec.rb
|
167
|
+
- spec/z_k/z_k_event_machine/event_handler_e_m_spec.rb
|
168
|
+
- spec/z_k/z_k_event_machine/unixisms_spec.rb
|
169
|
+
- zk-eventmachine.gemspec
|
170
|
+
has_rdoc: true
|
171
|
+
homepage: https://github.com/slyphon/zk-eventmachine
|
172
|
+
licenses: []
|
173
|
+
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
none: false
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
hash: 3
|
185
|
+
segments:
|
186
|
+
- 0
|
187
|
+
version: "0"
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
none: false
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
hash: 3
|
194
|
+
segments:
|
195
|
+
- 0
|
196
|
+
version: "0"
|
197
|
+
requirements: []
|
198
|
+
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 1.6.2
|
201
|
+
signing_key:
|
202
|
+
specification_version: 3
|
203
|
+
summary: ZK client for EventMachine-based (async) applications
|
204
|
+
test_files:
|
205
|
+
- spec/spec_helper.rb
|
206
|
+
- spec/support/extensions.rb
|
207
|
+
- spec/support/logging.rb
|
208
|
+
- spec/support/logging_progress_bar_formatter.rb
|
209
|
+
- spec/z_k/z_k_event_machine/callback_spec.rb
|
210
|
+
- spec/z_k/z_k_event_machine/client_spec.rb
|
211
|
+
- spec/z_k/z_k_event_machine/event_handler_e_m_spec.rb
|
212
|
+
- spec/z_k/z_k_event_machine/unixisms_spec.rb
|