zookeeper 0.9.4 → 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.dotfiles/rvmrc +1 -0
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/.travis.yml +22 -0
- data/CHANGELOG +38 -5
- data/Gemfile +18 -1
- data/README.markdown +2 -0
- data/Rakefile +47 -109
- data/ext/c_zookeeper.rb +10 -6
- data/ext/zookeeper_base.rb +23 -11
- data/ext/zookeeper_c.c +14 -10
- data/java/{zookeeper_base.rb → java_base.rb} +13 -12
- data/lib/zookeeper.rb +32 -244
- data/lib/zookeeper/acls.rb +17 -13
- data/lib/zookeeper/callbacks.rb +28 -11
- data/lib/zookeeper/client.rb +30 -0
- data/lib/zookeeper/client_methods.rb +241 -0
- data/lib/zookeeper/common.rb +13 -12
- data/lib/zookeeper/common/queue_with_pipe.rb +3 -7
- data/lib/zookeeper/compatibility.rb +135 -0
- data/lib/zookeeper/constants.rb +35 -1
- data/lib/zookeeper/em_client.rb +1 -1
- data/lib/zookeeper/exceptions.rb +117 -93
- data/lib/zookeeper/rake_tasks.rb +165 -0
- data/lib/zookeeper/stat.rb +16 -16
- data/lib/zookeeper/version.rb +2 -4
- data/scripts/upgrade-1.0-sed-alike.rb +46 -0
- data/spec/c_zookeeper_spec.rb +10 -9
- data/spec/chrooted_connection_spec.rb +2 -2
- data/spec/default_watcher_spec.rb +4 -4
- data/spec/em_spec.rb +1 -1
- data/spec/shared/connection_examples.rb +52 -37
- data/spec/spec_helper.rb +22 -84
- data/spec/support/00_spawn_zookeeper.rb +20 -0
- data/spec/support/zookeeper_spec_helpers.rb +84 -0
- data/spec/zookeeper_spec.rb +1 -1
- metadata +47 -34
- data/examples/cloud_config.rb +0 -125
- data/test/test_basic.rb +0 -37
- data/test/test_callback1.rb +0 -36
- data/test/test_close.rb +0 -16
- data/test/test_esoteric.rb +0 -7
- data/test/test_watcher1.rb +0 -56
- data/test/test_watcher2.rb +0 -52
data/test/test_basic.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'zookeeper'
|
3
|
-
|
4
|
-
z = Zookeeper.new("localhost:2181")
|
5
|
-
|
6
|
-
puts "root: #{z.get_children(:path => "/").inspect}"
|
7
|
-
|
8
|
-
path = "/testing_node"
|
9
|
-
|
10
|
-
puts "working with path #{path}"
|
11
|
-
|
12
|
-
h = z.stat(:path => path)
|
13
|
-
stat = h[:stat]
|
14
|
-
puts "exists? #{stat.inspect}"
|
15
|
-
|
16
|
-
if stat.exists
|
17
|
-
z.get_children(:path => path)[:children].each do |o|
|
18
|
-
puts " child object: #{o}"
|
19
|
-
end
|
20
|
-
puts "delete: #{z.delete(:path => path, :version => stat.version).inspect}"
|
21
|
-
end
|
22
|
-
|
23
|
-
puts "create: #{z.create(:path => path, :data => 'initial value').inspect}"
|
24
|
-
|
25
|
-
v = z.get(:path => path)
|
26
|
-
value, stat = v[:data], v[:stat]
|
27
|
-
puts "current value #{value}, stat #{stat.inspect}"
|
28
|
-
|
29
|
-
puts "set: #{z.set(:path => path, :data => 'this is a test', :version => stat.version).inspect}"
|
30
|
-
|
31
|
-
v = z.get(:path => path)
|
32
|
-
value, stat = v[:data], v[:stat]
|
33
|
-
puts "new value: #{value.inspect} #{stat.inspect}"
|
34
|
-
|
35
|
-
puts "delete: #{z.delete(:path => path, :version => stat.version).inspect}"
|
36
|
-
|
37
|
-
puts "exists? #{z.stat(:path => path)[:stat].exists}"
|
data/test/test_callback1.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'zookeeper'
|
3
|
-
|
4
|
-
def wait_until(timeout=10, &block)
|
5
|
-
time_to_stop = Time.now + timeout
|
6
|
-
until yield do
|
7
|
-
break if Time.now > time_to_stop
|
8
|
-
sleep 0.1
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
puts 'Initializing Zookeeper'
|
13
|
-
|
14
|
-
zk = Zookeeper.new('localhost:2181')
|
15
|
-
|
16
|
-
if zk.state != Zookeeper::ZOO_CONNECTED_STATE
|
17
|
-
puts 'Unable to connect to Zookeeper!'
|
18
|
-
Kernel.exit
|
19
|
-
end
|
20
|
-
|
21
|
-
def callback(args)
|
22
|
-
puts "CALLBACK EXECUTED, args = #{args.inspect}"
|
23
|
-
puts args.return_code == Zookeeper::ZOK ? "TEST PASSED IN CALLBACK" : "TEST FAILED IN CALLBACK"
|
24
|
-
end
|
25
|
-
|
26
|
-
ccb = Zookeeper::VoidCallback.new do
|
27
|
-
callback(ccb)
|
28
|
-
end
|
29
|
-
|
30
|
-
resp = zk.create(:path => '/test', :data => "new data", :sequence => true, :callback => ccb)
|
31
|
-
puts "#{resp.inspect}"
|
32
|
-
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK
|
33
|
-
|
34
|
-
wait_until { ccb.completed? }
|
35
|
-
|
36
|
-
puts ccb.completed? ? "TEST PASSED" : "TEST FAILED"
|
data/test/test_close.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'zookeeper'
|
3
|
-
z = Zookeeper.new("localhost:2181")
|
4
|
-
path = "/testing_node"
|
5
|
-
z.get(:path => path)
|
6
|
-
z.create(:path => path, :data => "initial value", :ephemeral => true)
|
7
|
-
z.get(:path => path)
|
8
|
-
z.close()
|
9
|
-
sleep 5
|
10
|
-
begin
|
11
|
-
z.get(:path => path)
|
12
|
-
rescue Exception => e
|
13
|
-
puts "Rescued exception #{e.inspect}"
|
14
|
-
end
|
15
|
-
z.reopen
|
16
|
-
z.get(:path => path)
|
data/test/test_esoteric.rb
DELETED
data/test/test_watcher1.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'zookeeper'
|
3
|
-
|
4
|
-
def wait_until(timeout=10, &block)
|
5
|
-
time_to_stop = Time.now + timeout
|
6
|
-
until yield do
|
7
|
-
break if Time.now > time_to_stop
|
8
|
-
sleep 0.1
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
puts 'Initializing Zookeeper'
|
13
|
-
|
14
|
-
zk = Zookeeper.new('localhost:2181')
|
15
|
-
|
16
|
-
if zk.state != Zookeeper::ZOO_CONNECTED_STATE
|
17
|
-
puts 'Unable to connect to Zookeeper!'
|
18
|
-
Kernel.exit
|
19
|
-
end
|
20
|
-
|
21
|
-
def watcher(args)
|
22
|
-
puts "#{args.inspect}"
|
23
|
-
puts "In watcher: path=#{args.path}, context=#{args.context}"
|
24
|
-
if args.path == args.context
|
25
|
-
puts "TEST PASSED IN WATCHER"
|
26
|
-
else
|
27
|
-
puts "TEST FAILED IN WATCHER"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
wcb = Zookeeper::WatcherCallback.new do
|
32
|
-
watcher(wcb)
|
33
|
-
end
|
34
|
-
|
35
|
-
resp = zk.create(:path => '/test', :sequence => true)
|
36
|
-
puts "#{resp.inspect}"
|
37
|
-
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK
|
38
|
-
|
39
|
-
base_path = resp[:path]
|
40
|
-
watched_file = "#{base_path}/file.does.not.exist"
|
41
|
-
|
42
|
-
resp = zk.stat(:path => watched_file, :watcher => wcb, :watcher_context => watched_file)
|
43
|
-
puts "#{resp.inspect}"
|
44
|
-
puts "TEST FAILED [stat]" unless resp[:rc] == Zookeeper::ZNONODE
|
45
|
-
|
46
|
-
resp = zk.create(:path => watched_file, :data => 'test data', :ephemeral => true)
|
47
|
-
puts "#{resp.inspect}"
|
48
|
-
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK
|
49
|
-
|
50
|
-
wait_until { wcb.completed? }
|
51
|
-
|
52
|
-
puts "TEST FAILED" unless wcb.completed?
|
53
|
-
puts "TEST PASSED"
|
54
|
-
|
55
|
-
zk.delete(:path => watched_file)
|
56
|
-
zk.delete(:path => base_path)
|
data/test/test_watcher2.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'zookeeper'
|
3
|
-
|
4
|
-
def wait_until(timeout=10, &block)
|
5
|
-
time_to_stop = Time.now + timeout
|
6
|
-
until yield do
|
7
|
-
break if Time.now > time_to_stop
|
8
|
-
sleep 0.1
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
puts 'Initializing Zookeeper'
|
13
|
-
|
14
|
-
zk = Zookeeper.new('localhost:2181')
|
15
|
-
|
16
|
-
if zk.state != Zookeeper::ZOO_CONNECTED_STATE
|
17
|
-
puts 'Unable to connect to Zookeeper!'
|
18
|
-
Kernel.exit
|
19
|
-
end
|
20
|
-
|
21
|
-
def watcher(args)
|
22
|
-
if args.path == args.context
|
23
|
-
puts "TEST PASSED IN WATCHER"
|
24
|
-
else
|
25
|
-
puts "TEST FAILED IN WATCHER"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
wcb = Zookeeper::WatcherCallback.new do
|
30
|
-
watcher(wcb)
|
31
|
-
end
|
32
|
-
|
33
|
-
resp = zk.create(:path => '/test', :sequence => true)
|
34
|
-
puts "#{resp.inspect}"
|
35
|
-
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK
|
36
|
-
|
37
|
-
base_path = resp[:path]
|
38
|
-
triggering_file = "#{base_path}/file.does.not.exist"
|
39
|
-
|
40
|
-
resp = zk.get_children(:path => base_path, :watcher => wcb, :watcher_context => base_path)
|
41
|
-
puts "TEST FAILED [get_children]" unless resp[:rc] == Zookeeper::ZOK
|
42
|
-
|
43
|
-
resp = zk.create(:path => triggering_file, :data => 'test data', :ephemeral => true)
|
44
|
-
puts "TEST FAILED [create]" unless resp[:rc] == Zookeeper::ZOK
|
45
|
-
|
46
|
-
wait_until { wcb.completed? }
|
47
|
-
|
48
|
-
puts "TEST FAILED" unless wcb.completed?
|
49
|
-
puts "TEST PASSED"
|
50
|
-
|
51
|
-
zk.delete(:path => triggering_file)
|
52
|
-
zk.delete(:path => base_path)
|