zookeeper 0.9.3-java

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.
Files changed (53) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG +119 -0
  3. data/Gemfile +17 -0
  4. data/LICENSE +23 -0
  5. data/Manifest +29 -0
  6. data/README.markdown +59 -0
  7. data/Rakefile +139 -0
  8. data/examples/cloud_config.rb +125 -0
  9. data/ext/.gitignore +6 -0
  10. data/ext/Rakefile +51 -0
  11. data/ext/c_zookeeper.rb +212 -0
  12. data/ext/dbg.h +53 -0
  13. data/ext/depend +5 -0
  14. data/ext/extconf.rb +85 -0
  15. data/ext/generate_gvl_code.rb +316 -0
  16. data/ext/zkc-3.3.5.tar.gz +0 -0
  17. data/ext/zkrb_wrapper.c +731 -0
  18. data/ext/zkrb_wrapper.h +330 -0
  19. data/ext/zkrb_wrapper_compat.c +15 -0
  20. data/ext/zkrb_wrapper_compat.h +11 -0
  21. data/ext/zookeeper_base.rb +211 -0
  22. data/ext/zookeeper_c.c +725 -0
  23. data/ext/zookeeper_lib.c +677 -0
  24. data/ext/zookeeper_lib.h +172 -0
  25. data/java/zookeeper_base.rb +477 -0
  26. data/lib/zookeeper.rb +297 -0
  27. data/lib/zookeeper/acls.rb +40 -0
  28. data/lib/zookeeper/callbacks.rb +91 -0
  29. data/lib/zookeeper/common.rb +174 -0
  30. data/lib/zookeeper/common/queue_with_pipe.rb +78 -0
  31. data/lib/zookeeper/constants.rb +57 -0
  32. data/lib/zookeeper/em_client.rb +55 -0
  33. data/lib/zookeeper/exceptions.rb +100 -0
  34. data/lib/zookeeper/stat.rb +21 -0
  35. data/lib/zookeeper/version.rb +6 -0
  36. data/notes.txt +14 -0
  37. data/spec/c_zookeeper_spec.rb +50 -0
  38. data/spec/chrooted_connection_spec.rb +81 -0
  39. data/spec/default_watcher_spec.rb +41 -0
  40. data/spec/em_spec.rb +51 -0
  41. data/spec/log4j.properties +17 -0
  42. data/spec/shared/all_success_return_values.rb +10 -0
  43. data/spec/shared/connection_examples.rb +1018 -0
  44. data/spec/spec_helper.rb +119 -0
  45. data/spec/support/progress_formatter.rb +15 -0
  46. data/spec/zookeeper_spec.rb +24 -0
  47. data/test/test_basic.rb +37 -0
  48. data/test/test_callback1.rb +36 -0
  49. data/test/test_close.rb +16 -0
  50. data/test/test_esoteric.rb +7 -0
  51. data/test/test_watcher1.rb +56 -0
  52. data/test/test_watcher2.rb +52 -0
  53. metadata +181 -0
@@ -0,0 +1,119 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ $LOAD_PATH.unshift(File.expand_path('../../ext', __FILE__))
3
+ $LOAD_PATH.uniq!
4
+
5
+ require 'rubygems'
6
+
7
+ gem 'flexmock', '~> 0.8.11'
8
+
9
+ require 'flexmock'
10
+ require 'zookeeper'
11
+
12
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }
13
+
14
+ if ENV['ZKRB_DEBUG']
15
+ Zookeeper.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
16
+ Zookeeper.set_debug_level(4)
17
+ else
18
+ Zookeeper.logger = Logger.new(File.expand_path('../../test.log', __FILE__)).tap do |log|
19
+ log.level = Logger::DEBUG
20
+ end
21
+ end
22
+
23
+ if ENV['ZKRB_NOLOG']
24
+ Zookeeper.logger.level = Logger::FATAL
25
+ Zookeeper.set_debug_level(0)
26
+ end
27
+
28
+
29
+ module ZookeeperSpecHeleprs
30
+ class TimeoutError < StandardError; end
31
+
32
+ def logger
33
+ Zookeeper.logger
34
+ end
35
+
36
+ def ensure_node(zk, path, data)
37
+ return if zk.closed?
38
+ if zk.stat(:path => path)[:stat].exists?
39
+ zk.set(:path => path, :data => data)
40
+ else
41
+ zk.create(:path => path, :data => data)
42
+ end
43
+ end
44
+
45
+ def with_open_zk(host='localhost:2181')
46
+ z = Zookeeper.new(host)
47
+ yield z
48
+ ensure
49
+ if z
50
+ unless z.closed?
51
+ z.close
52
+
53
+ wait_until do
54
+ begin
55
+ !z.connected?
56
+ rescue RuntimeError
57
+ true
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ # this is not as safe as the one in ZK, just to be used to clean up
65
+ # when we're the only one adjusting a particular path
66
+ def rm_rf(z, path)
67
+ z.get_children(:path => path).tap do |h|
68
+ if h[:rc].zero?
69
+ h[:children].each do |child|
70
+ rm_rf(z, File.join(path, child))
71
+ end
72
+ elsif h[:rc] == ZookeeperExceptions::ZNONODE
73
+ # no-op
74
+ else
75
+ raise "Oh noes! unexpected return value! #{h.inspect}"
76
+ end
77
+ end
78
+
79
+ rv = z.delete(:path => path)
80
+
81
+ unless (rv[:rc].zero? or rv[:rc] == ZookeeperExceptions::ZNONODE)
82
+ raise "oh noes! failed to delete #{path}"
83
+ end
84
+
85
+ path
86
+ end
87
+
88
+
89
+ # method to wait until block passed returns true or timeout (default is 10 seconds) is reached
90
+ # raises TiemoutError on timeout
91
+ def wait_until(timeout=10)
92
+ time_to_stop = Time.now + timeout
93
+ while true
94
+ rval = yield
95
+ return rval if rval
96
+ raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
97
+ Thread.pass
98
+ end
99
+ end
100
+
101
+ # inverse of wait_until
102
+ def wait_while(timeout=10)
103
+ time_to_stop = Time.now + timeout
104
+ while true
105
+ rval = yield
106
+ return rval unless rval
107
+ raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
108
+ Thread.pass
109
+ end
110
+ end
111
+ end
112
+
113
+ RSpec.configure do |config|
114
+ config.mock_with :flexmock
115
+ config.include ZookeeperSpecHeleprs
116
+ config.extend ZookeeperSpecHeleprs
117
+ end
118
+
119
+
@@ -0,0 +1,15 @@
1
+ require 'rspec/core/formatters/progress_formatter'
2
+
3
+ module RSpec
4
+ module Core
5
+ module Formatters
6
+ class ProgressFormatter
7
+ def example_started(example)
8
+ Zookeeper.logger.info(yellow("=====<([ #{example.full_description} ])>====="))
9
+ super(example)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'shared/connection_examples'
3
+
4
+
5
+ describe 'Zookeeper' do
6
+ let(:path) { "/_zktest_" }
7
+ let(:data) { "underpants" }
8
+ let(:connection_string) { 'localhost:2181' }
9
+
10
+ before do
11
+ @zk = Zookeeper.new(connection_string)
12
+ end
13
+
14
+ after do
15
+ @zk and @zk.close
16
+ end
17
+
18
+ def zk
19
+ @zk
20
+ end
21
+
22
+ it_should_behave_like "connection"
23
+ end
24
+
@@ -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,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zookeeper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 61
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 3
10
+ version: 0.9.3
11
+ platform: java
12
+ authors:
13
+ - Phillip Pearson
14
+ - Eric Maland
15
+ - Evan Weaver
16
+ - Brian Wickman
17
+ - Neil Conway
18
+ - Jonathan D. Simms
19
+ autorequire:
20
+ bindir: bin
21
+ cert_chain: []
22
+
23
+ date: 2012-05-03 00:00:00 Z
24
+ dependencies:
25
+ - !ruby/object:Gem::Dependency
26
+ name: slyphon-log4j
27
+ prerelease: false
28
+ requirement: &id001 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ hash: 1
34
+ segments:
35
+ - 1
36
+ - 2
37
+ - 15
38
+ version: 1.2.15
39
+ type: :runtime
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: slyphon-zookeeper_jar
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - "="
48
+ - !ruby/object:Gem::Version
49
+ hash: 1
50
+ segments:
51
+ - 3
52
+ - 3
53
+ - 5
54
+ version: 3.3.5
55
+ type: :runtime
56
+ version_requirements: *id002
57
+ description: |+
58
+ A low-level multi-Ruby wrapper around the ZooKeeper API bindings.
59
+ For a friendlier interface, see http://github.com/slyphon/zk
60
+
61
+ Currently supported:
62
+
63
+ MRI: 1.8.7, 1.9.2, 1.9.3
64
+ JRuby: ~> 1.6.7
65
+ Rubinius: 2.0.testing
66
+
67
+ This library uses version 3.3.5 of zookeeper bindings.
68
+
69
+ email:
70
+ - slyphon@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - .gitignore
79
+ - CHANGELOG
80
+ - Gemfile
81
+ - LICENSE
82
+ - Manifest
83
+ - README.markdown
84
+ - Rakefile
85
+ - examples/cloud_config.rb
86
+ - ext/.gitignore
87
+ - ext/Rakefile
88
+ - ext/c_zookeeper.rb
89
+ - ext/dbg.h
90
+ - ext/depend
91
+ - ext/extconf.rb
92
+ - ext/generate_gvl_code.rb
93
+ - ext/zkc-3.3.5.tar.gz
94
+ - ext/zkrb_wrapper.c
95
+ - ext/zkrb_wrapper.h
96
+ - ext/zkrb_wrapper_compat.c
97
+ - ext/zkrb_wrapper_compat.h
98
+ - ext/zookeeper_base.rb
99
+ - ext/zookeeper_c.c
100
+ - ext/zookeeper_lib.c
101
+ - ext/zookeeper_lib.h
102
+ - java/zookeeper_base.rb
103
+ - lib/zookeeper.rb
104
+ - lib/zookeeper/acls.rb
105
+ - lib/zookeeper/callbacks.rb
106
+ - lib/zookeeper/common.rb
107
+ - lib/zookeeper/common/queue_with_pipe.rb
108
+ - lib/zookeeper/constants.rb
109
+ - lib/zookeeper/em_client.rb
110
+ - lib/zookeeper/exceptions.rb
111
+ - lib/zookeeper/stat.rb
112
+ - lib/zookeeper/version.rb
113
+ - notes.txt
114
+ - spec/c_zookeeper_spec.rb
115
+ - spec/chrooted_connection_spec.rb
116
+ - spec/default_watcher_spec.rb
117
+ - spec/em_spec.rb
118
+ - spec/log4j.properties
119
+ - spec/shared/all_success_return_values.rb
120
+ - spec/shared/connection_examples.rb
121
+ - spec/spec_helper.rb
122
+ - spec/support/progress_formatter.rb
123
+ - spec/zookeeper_spec.rb
124
+ - test/test_basic.rb
125
+ - test/test_callback1.rb
126
+ - test/test_close.rb
127
+ - test/test_esoteric.rb
128
+ - test/test_watcher1.rb
129
+ - test/test_watcher2.rb
130
+ - zookeeper.gemspec
131
+ homepage: https://github.com/slyphon/zookeeper
132
+ licenses: []
133
+
134
+ post_install_message:
135
+ rdoc_options: []
136
+
137
+ require_paths:
138
+ - lib
139
+ - java
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.8.15
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Low level zookeeper client
165
+ test_files:
166
+ - spec/c_zookeeper_spec.rb
167
+ - spec/chrooted_connection_spec.rb
168
+ - spec/default_watcher_spec.rb
169
+ - spec/em_spec.rb
170
+ - spec/log4j.properties
171
+ - spec/shared/all_success_return_values.rb
172
+ - spec/shared/connection_examples.rb
173
+ - spec/spec_helper.rb
174
+ - spec/support/progress_formatter.rb
175
+ - spec/zookeeper_spec.rb
176
+ - test/test_basic.rb
177
+ - test/test_callback1.rb
178
+ - test/test_close.rb
179
+ - test/test_esoteric.rb
180
+ - test/test_watcher1.rb
181
+ - test/test_watcher2.rb