slyphon-zookeeper 0.1.0-java

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,178 @@
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: java
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
+ - !ruby/object:Gem::Dependency
58
+ name: slyphon-log4j
59
+ prerelease: false
60
+ requirement: &id003 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - "="
64
+ - !ruby/object:Gem::Version
65
+ hash: 1
66
+ segments:
67
+ - 1
68
+ - 2
69
+ - 15
70
+ version: 1.2.15
71
+ type: :runtime
72
+ version_requirements: *id003
73
+ - !ruby/object:Gem::Dependency
74
+ name: slyphon-zookeeper_jar
75
+ prerelease: false
76
+ requirement: &id004 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - "="
80
+ - !ruby/object:Gem::Version
81
+ hash: 9
82
+ segments:
83
+ - 3
84
+ - 3
85
+ - 1
86
+ version: 3.3.1
87
+ type: :runtime
88
+ version_requirements: *id004
89
+ description: twitter's zookeeper client
90
+ email:
91
+ - slyphon@gmail.com
92
+ executables: []
93
+
94
+ extensions: []
95
+
96
+ extra_rdoc_files: []
97
+
98
+ files:
99
+ - .gitignore
100
+ - CHANGELOG
101
+ - LICENSE
102
+ - Manifest
103
+ - README
104
+ - Rakefile
105
+ - examples/cloud_config.rb
106
+ - ext/.gitignore
107
+ - ext/extconf.rb
108
+ - ext/zkc-3.3.2.tar.gz
109
+ - ext/zookeeper_base.rb
110
+ - ext/zookeeper_c.c
111
+ - ext/zookeeper_lib.c
112
+ - ext/zookeeper_lib.h
113
+ - java/zookeeper_base.rb
114
+ - lib/zookeeper.rb
115
+ - lib/zookeeper/acls.rb
116
+ - lib/zookeeper/callbacks.rb
117
+ - lib/zookeeper/common.rb
118
+ - lib/zookeeper/constants.rb
119
+ - lib/zookeeper/exceptions.rb
120
+ - lib/zookeeper/stat.rb
121
+ - notes.txt
122
+ - slyphon-zookeeper.gemspec
123
+ - spec/default_watcher_spec.rb
124
+ - spec/log4j.properties
125
+ - spec/spec_helper.rb
126
+ - spec/zookeeper_spec.rb
127
+ - test/test_basic.rb
128
+ - test/test_callback1.rb
129
+ - test/test_close.rb
130
+ - test/test_esoteric.rb
131
+ - test/test_watcher1.rb
132
+ - test/test_watcher2.rb
133
+ has_rdoc: true
134
+ homepage:
135
+ licenses: []
136
+
137
+ post_install_message:
138
+ rdoc_options: []
139
+
140
+ require_paths:
141
+ - lib
142
+ - java
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project:
164
+ rubygems_version: 1.4.2
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: twitter's zookeeper client
168
+ test_files:
169
+ - spec/default_watcher_spec.rb
170
+ - spec/log4j.properties
171
+ - spec/spec_helper.rb
172
+ - spec/zookeeper_spec.rb
173
+ - test/test_basic.rb
174
+ - test/test_callback1.rb
175
+ - test/test_close.rb
176
+ - test/test_esoteric.rb
177
+ - test/test_watcher1.rb
178
+ - test/test_watcher2.rb