slyphon-zookeeper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
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}"
@@ -0,0 +1,36 @@
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"
@@ -0,0 +1,16 @@
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)
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'zookeeper'
3
+ zk = Zookeeper.new('localhost:2181')
4
+
5
+ puts "get acl #{zk.get_acl(:path => '/').inspect}"
6
+ puts "zerror #{zk.zerror(Zookeeper::ZBADVERSION)}"
7
+
@@ -0,0 +1,56 @@
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)
@@ -0,0 +1,52 @@
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)
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slyphon-zookeeper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Phillip Pearson
14
+ - Eric Maland
15
+ - Evan Weaver
16
+ - Brian Wickman
17
+ - Jonathan D. Simms
18
+ autorequire:
19
+ bindir: bin
20
+ cert_chain: []
21
+
22
+ date: 2011-02-14 00:00:00 +00:00
23
+ default_executable:
24
+ dependencies:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ prerelease: false
28
+ requirement: &id001 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ hash: 15
34
+ segments:
35
+ - 2
36
+ - 0
37
+ - 0
38
+ version: 2.0.0
39
+ type: :development
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: flexmock
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ hash: 41
50
+ segments:
51
+ - 0
52
+ - 8
53
+ - 11
54
+ version: 0.8.11
55
+ type: :development
56
+ version_requirements: *id002
57
+ description: twitter's zookeeper client
58
+ email:
59
+ - slyphon@gmail.com
60
+ executables: []
61
+
62
+ extensions:
63
+ - ext/extconf.rb
64
+ extra_rdoc_files: []
65
+
66
+ files:
67
+ - .gitignore
68
+ - CHANGELOG
69
+ - LICENSE
70
+ - Manifest
71
+ - README
72
+ - Rakefile
73
+ - examples/cloud_config.rb
74
+ - ext/.gitignore
75
+ - ext/extconf.rb
76
+ - ext/zkc-3.3.2.tar.gz
77
+ - ext/zookeeper_base.rb
78
+ - ext/zookeeper_c.c
79
+ - ext/zookeeper_lib.c
80
+ - ext/zookeeper_lib.h
81
+ - java/zookeeper_base.rb
82
+ - lib/zookeeper.rb
83
+ - lib/zookeeper/acls.rb
84
+ - lib/zookeeper/callbacks.rb
85
+ - lib/zookeeper/common.rb
86
+ - lib/zookeeper/constants.rb
87
+ - lib/zookeeper/exceptions.rb
88
+ - lib/zookeeper/stat.rb
89
+ - notes.txt
90
+ - slyphon-zookeeper.gemspec
91
+ - spec/default_watcher_spec.rb
92
+ - spec/log4j.properties
93
+ - spec/spec_helper.rb
94
+ - spec/zookeeper_spec.rb
95
+ - test/test_basic.rb
96
+ - test/test_callback1.rb
97
+ - test/test_close.rb
98
+ - test/test_esoteric.rb
99
+ - test/test_watcher1.rb
100
+ - test/test_watcher2.rb
101
+ has_rdoc: true
102
+ homepage:
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ - ext
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.4.2
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: twitter's zookeeper client
136
+ test_files:
137
+ - spec/default_watcher_spec.rb
138
+ - spec/log4j.properties
139
+ - spec/spec_helper.rb
140
+ - spec/zookeeper_spec.rb
141
+ - test/test_basic.rb
142
+ - test/test_callback1.rb
143
+ - test/test_close.rb
144
+ - test/test_esoteric.rb
145
+ - test/test_watcher1.rb
146
+ - test/test_watcher2.rb