zk 0.6.4
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/.gitignore +7 -0
- data/Gemfile +10 -0
- data/Rakefile +13 -0
- data/lib/z_k/client.rb +906 -0
- data/lib/z_k/election.rb +411 -0
- data/lib/z_k/event_handler.rb +202 -0
- data/lib/z_k/event_handler_subscription.rb +29 -0
- data/lib/z_k/exceptions.rb +101 -0
- data/lib/z_k/extensions.rb +144 -0
- data/lib/z_k/locker.rb +254 -0
- data/lib/z_k/logging.rb +15 -0
- data/lib/z_k/message_queue.rb +143 -0
- data/lib/z_k/mongoid.rb +172 -0
- data/lib/z_k/pool.rb +254 -0
- data/lib/z_k/threadpool.rb +109 -0
- data/lib/z_k/version.rb +3 -0
- data/lib/z_k.rb +73 -0
- data/lib/zk.rb +2 -0
- data/spec/client_pool_spec.rb +329 -0
- data/spec/client_spec.rb +102 -0
- data/spec/election_spec.rb +301 -0
- data/spec/locker_spec.rb +386 -0
- data/spec/log4j.properties +17 -0
- data/spec/message_queue_spec.rb +55 -0
- data/spec/mongoid_spec.rb +330 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/support/bogus_mongoid.rb +11 -0
- data/spec/support/queuey_thread.rb +11 -0
- data/spec/test_file.txt +4 -0
- data/spec/threadpool_spec.rb +71 -0
- data/spec/watch_spec.rb +118 -0
- data/spec/zookeeper_spec.rb +176 -0
- data/zk.gemspec +24 -0
- metadata +176 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
|
+
|
3
|
+
describe ZK do
|
4
|
+
before do
|
5
|
+
@zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => nil)
|
6
|
+
|
7
|
+
# @zk.set_debug_level(:debug) unless defined?(::JRUBY_VERSION)
|
8
|
+
|
9
|
+
wait_until{ @zk.connected? }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ZK, "with no paths" do
|
13
|
+
before(:each) do
|
14
|
+
delete_test!
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
delete_test!
|
19
|
+
@zk.close!
|
20
|
+
wait_until{ @zk.closed? }
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_test!
|
24
|
+
if (@zk.exists?('/test'))
|
25
|
+
@zk.children("/test").each do |child|
|
26
|
+
@zk.delete("/test/#{child}")
|
27
|
+
end
|
28
|
+
@zk.delete('/test')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not exist" do
|
33
|
+
@zk.exists?("/test").should be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should create a path" do
|
37
|
+
@zk.create("/test", "test_data", :mode => :ephemeral).should == "/test"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to set the data" do
|
41
|
+
@zk.create("/test", "something", :mode => :ephemeral)
|
42
|
+
@zk.set("/test", "somethingelse")
|
43
|
+
@zk.get("/test").first.should == "somethingelse"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should raise an exception for a non existent path" do
|
47
|
+
lambda { @zk.get("/non_existent_path") }.should raise_error(ZK::Exceptions::NoNode)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should create a path with sequence set" do
|
51
|
+
@zk.create("/test", "test_data", :mode => :persistent_sequential).should =~ /test(\d+)/
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create an ephemeral path" do
|
55
|
+
@zk.create("/test", "test_data", :mode => :ephemeral).should == "/test"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should remove ephemeral path when client session ends" do
|
59
|
+
@zk.create("/test", "test_data", :mode => :ephemeral).should == "/test"
|
60
|
+
@zk.exists?("/test").should_not be_nil
|
61
|
+
@zk.close!
|
62
|
+
wait_until(2) { !@zk.connected? }
|
63
|
+
@zk.should_not be_connected
|
64
|
+
|
65
|
+
@zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => nil)
|
66
|
+
wait_until{ @zk.connected? }
|
67
|
+
@zk.exists?("/test").should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should remove sequential ephemeral path when client session ends" do
|
71
|
+
created = @zk.create("/test", "test_data", :mode => :ephemeral_sequential)
|
72
|
+
created.should =~ /test(\d+)/
|
73
|
+
@zk.exists?(created).should_not be_nil
|
74
|
+
@zk.close!
|
75
|
+
|
76
|
+
@zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => nil)
|
77
|
+
wait_until{ @zk.connected? }
|
78
|
+
@zk.exists?(created).should be_false
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ZK, "with a path" do
|
84
|
+
before(:each) do
|
85
|
+
delete_test!
|
86
|
+
@zk.create("/test", "test_data", :mode => :persistent)
|
87
|
+
end
|
88
|
+
|
89
|
+
after(:each) do
|
90
|
+
delete_test!
|
91
|
+
@zk.close!
|
92
|
+
wait_until{ @zk.closed? }
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_test!
|
96
|
+
if (@zk.exists?('/test'))
|
97
|
+
@zk.children("/test").each do |child|
|
98
|
+
@zk.delete("/test/#{child}")
|
99
|
+
end
|
100
|
+
@zk.delete('/test')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return a stat" do
|
105
|
+
@zk.stat("/test").should be_instance_of(ZookeeperStat::Stat)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return a boolean" do
|
109
|
+
@zk.exists?("/test").should be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should get data and stat" do
|
113
|
+
data, stat = @zk.get("/test")
|
114
|
+
data.should == "test_data"
|
115
|
+
stat.should be_a_kind_of(ZookeeperStat::Stat)
|
116
|
+
stat.created_time.should_not == 0
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should set data with a file" do
|
120
|
+
file = File.read('spec/test_file.txt')
|
121
|
+
@zk.set("/test", file)
|
122
|
+
@zk.get("/test").first.should == file
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should delete path" do
|
126
|
+
@zk.delete("/test")
|
127
|
+
@zk.exists?("/test").should be_false
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should create a child path" do
|
131
|
+
@zk.create("/test/child", "child", :mode => :ephemeral).should == "/test/child"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should create sequential child paths" do
|
135
|
+
(child1 = @zk.create("/test/child", "child1", :mode => :persistent_sequential)).should =~ /\/test\/child(\d+)/
|
136
|
+
(child2 = @zk.create("/test/child", "child2", :mode => :persistent_sequential)).should =~ /\/test\/child(\d+)/
|
137
|
+
children = @zk.children("/test")
|
138
|
+
children.length.should == 2
|
139
|
+
children.should be_include(child1.match(/\/test\/(child\d+)/)[1])
|
140
|
+
children.should be_include(child2.match(/\/test\/(child\d+)/)[1])
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should have no children" do
|
144
|
+
@zk.children("/test").should be_empty
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe ZK, "with children" do
|
150
|
+
|
151
|
+
before(:each) do
|
152
|
+
delete_test!
|
153
|
+
@zk.create("/test", "test_data", :mode => :persistent)
|
154
|
+
@zk.create("/test/child", "child", :mode => "persistent").should == "/test/child"
|
155
|
+
end
|
156
|
+
|
157
|
+
after(:each) do
|
158
|
+
delete_test!
|
159
|
+
@zk.close!
|
160
|
+
wait_until{ @zk.closed? }
|
161
|
+
end
|
162
|
+
|
163
|
+
def delete_test!
|
164
|
+
if (@zk.exists?('/test'))
|
165
|
+
@zk.children("/test").each do |child|
|
166
|
+
@zk.delete("/test/#{child}")
|
167
|
+
end
|
168
|
+
@zk.delete('/test')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should get children" do
|
173
|
+
@zk.children("/test").should eql(["child"])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
data/zk.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "z_k/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "zk"
|
7
|
+
s.version = ZK::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jonathan D. Simms", "Topper Bowers"]
|
10
|
+
s.email = ["simms@hp.com", "tobowers@hp.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A high-level wrapper around the zookeeper driver}
|
13
|
+
s.description = s.summary
|
14
|
+
|
15
|
+
s.add_runtime_dependency 'slyphon-zookeeper', '~> 0.1.4'
|
16
|
+
s.add_development_dependency 'rspec', '~> 2.4.0'
|
17
|
+
s.add_development_dependency 'wirble'
|
18
|
+
s.add_development_dependency 'flexmock', '~> 0.8.10'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 4
|
10
|
+
version: 0.6.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jonathan D. Simms
|
14
|
+
- Topper Bowers
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-05-19 00:00:00 +00:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: slyphon-zookeeper
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 19
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 1
|
34
|
+
- 4
|
35
|
+
version: 0.1.4
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 31
|
47
|
+
segments:
|
48
|
+
- 2
|
49
|
+
- 4
|
50
|
+
- 0
|
51
|
+
version: 2.4.0
|
52
|
+
type: :development
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: wirble
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: flexmock
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 43
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 8
|
80
|
+
- 10
|
81
|
+
version: 0.8.10
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
84
|
+
description: A high-level wrapper around the zookeeper driver
|
85
|
+
email:
|
86
|
+
- simms@hp.com
|
87
|
+
- tobowers@hp.com
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files: []
|
93
|
+
|
94
|
+
files:
|
95
|
+
- .gitignore
|
96
|
+
- Gemfile
|
97
|
+
- Rakefile
|
98
|
+
- lib/z_k.rb
|
99
|
+
- lib/z_k/client.rb
|
100
|
+
- lib/z_k/election.rb
|
101
|
+
- lib/z_k/event_handler.rb
|
102
|
+
- lib/z_k/event_handler_subscription.rb
|
103
|
+
- lib/z_k/exceptions.rb
|
104
|
+
- lib/z_k/extensions.rb
|
105
|
+
- lib/z_k/locker.rb
|
106
|
+
- lib/z_k/logging.rb
|
107
|
+
- lib/z_k/message_queue.rb
|
108
|
+
- lib/z_k/mongoid.rb
|
109
|
+
- lib/z_k/pool.rb
|
110
|
+
- lib/z_k/threadpool.rb
|
111
|
+
- lib/z_k/version.rb
|
112
|
+
- lib/zk.rb
|
113
|
+
- spec/client_pool_spec.rb
|
114
|
+
- spec/client_spec.rb
|
115
|
+
- spec/election_spec.rb
|
116
|
+
- spec/locker_spec.rb
|
117
|
+
- spec/log4j.properties
|
118
|
+
- spec/message_queue_spec.rb
|
119
|
+
- spec/mongoid_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/support/bogus_mongoid.rb
|
122
|
+
- spec/support/queuey_thread.rb
|
123
|
+
- spec/test_file.txt
|
124
|
+
- spec/threadpool_spec.rb
|
125
|
+
- spec/watch_spec.rb
|
126
|
+
- spec/zookeeper_spec.rb
|
127
|
+
- zk.gemspec
|
128
|
+
has_rdoc: true
|
129
|
+
homepage: ""
|
130
|
+
licenses: []
|
131
|
+
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
hash: 3
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
version: "0"
|
155
|
+
requirements: []
|
156
|
+
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 1.6.2
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: A high-level wrapper around the zookeeper driver
|
162
|
+
test_files:
|
163
|
+
- spec/client_pool_spec.rb
|
164
|
+
- spec/client_spec.rb
|
165
|
+
- spec/election_spec.rb
|
166
|
+
- spec/locker_spec.rb
|
167
|
+
- spec/log4j.properties
|
168
|
+
- spec/message_queue_spec.rb
|
169
|
+
- spec/mongoid_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/support/bogus_mongoid.rb
|
172
|
+
- spec/support/queuey_thread.rb
|
173
|
+
- spec/test_file.txt
|
174
|
+
- spec/threadpool_spec.rb
|
175
|
+
- spec/watch_spec.rb
|
176
|
+
- spec/zookeeper_spec.rb
|