zookeeper 0.9.4-java → 1.0.0.beta.1-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 (45) hide show
  1. data/.dotfiles/rvmrc +1 -0
  2. data/.gitignore +3 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +22 -0
  5. data/CHANGELOG +38 -5
  6. data/Gemfile +18 -1
  7. data/README.markdown +2 -0
  8. data/Rakefile +47 -109
  9. data/ext/c_zookeeper.rb +10 -6
  10. data/ext/zookeeper_base.rb +23 -11
  11. data/ext/zookeeper_c.c +14 -10
  12. data/java/{zookeeper_base.rb → java_base.rb} +13 -12
  13. data/lib/zookeeper/acls.rb +17 -13
  14. data/lib/zookeeper/callbacks.rb +28 -11
  15. data/lib/zookeeper/client.rb +30 -0
  16. data/lib/zookeeper/client_methods.rb +241 -0
  17. data/lib/zookeeper/common/queue_with_pipe.rb +3 -7
  18. data/lib/zookeeper/common.rb +13 -12
  19. data/lib/zookeeper/compatibility.rb +135 -0
  20. data/lib/zookeeper/constants.rb +35 -1
  21. data/lib/zookeeper/em_client.rb +1 -1
  22. data/lib/zookeeper/exceptions.rb +117 -93
  23. data/lib/zookeeper/rake_tasks.rb +165 -0
  24. data/lib/zookeeper/stat.rb +16 -16
  25. data/lib/zookeeper/version.rb +2 -4
  26. data/lib/zookeeper.rb +32 -244
  27. data/scripts/upgrade-1.0-sed-alike.rb +46 -0
  28. data/spec/c_zookeeper_spec.rb +10 -9
  29. data/spec/chrooted_connection_spec.rb +2 -2
  30. data/spec/default_watcher_spec.rb +4 -4
  31. data/spec/em_spec.rb +1 -1
  32. data/spec/shared/connection_examples.rb +52 -37
  33. data/spec/spec_helper.rb +22 -84
  34. data/spec/support/00_spawn_zookeeper.rb +20 -0
  35. data/spec/support/zookeeper_spec_helpers.rb +84 -0
  36. data/spec/zookeeper_spec.rb +1 -1
  37. data/zookeeper.gemspec +9 -12
  38. metadata +50 -36
  39. data/examples/cloud_config.rb +0 -125
  40. data/test/test_basic.rb +0 -37
  41. data/test/test_callback1.rb +0 -36
  42. data/test/test_close.rb +0 -16
  43. data/test/test_esoteric.rb +0 -7
  44. data/test/test_watcher1.rb +0 -56
  45. data/test/test_watcher2.rb +0 -52
@@ -1,100 +1,124 @@
1
- module ZookeeperExceptions
2
- # exceptions/errors
3
- ZOK = 0
4
- ZSYSTEMERROR = -1
5
- ZRUNTIMEINCONSISTENCY = -2
6
- ZDATAINCONSISTENCY = -3
7
- ZCONNECTIONLOSS = -4
8
- ZMARSHALLINGERROR = -5
9
- ZUNIMPLEMENTED = -6
10
- ZOPERATIONTIMEOUT = -7
11
- ZBADARGUMENTS = -8
12
- ZINVALIDSTATE = -9
13
-
14
- # api errors
15
- ZAPIERROR = -100
16
- ZNONODE = -101
17
- ZNOAUTH = -102
18
- ZBADVERSION = -103
19
- ZNOCHILDRENFOREPHEMERALS = -108
20
- ZNODEEXISTS = -110
21
- ZNOTEMPTY = -111
22
- ZSESSIONEXPIRED = -112
23
- ZINVALIDCALLBACK = -113
24
- ZINVALIDACL = -114
25
- ZAUTHFAILED = -115
26
- ZCLOSING = -116
27
- ZNOTHING = -117
28
- ZSESSIONMOVED = -118
1
+ module Zookeeper
2
+ module Exceptions
3
+ include Constants
29
4
 
30
5
  class ZookeeperException < StandardError
31
- class EverythingOk < ZookeeperException; end
32
- class SystemError < ZookeeperException; end
33
- class RunTimeInconsistency < ZookeeperException; end
34
- class DataInconsistency < ZookeeperException; end
35
- class ConnectionLoss < ZookeeperException; end
36
- class MarshallingError < ZookeeperException; end
37
- class Unimplemented < ZookeeperException; end
38
- class OperationTimeOut < ZookeeperException; end
39
- class BadArguments < ZookeeperException; end
40
- class InvalidState < ZookeeperException; end
41
- class ApiError < ZookeeperException; end
42
- class NoNode < ZookeeperException; end
43
- class NoAuth < ZookeeperException; end
44
- class BadVersion < ZookeeperException; end
45
- class NoChildrenForEphemerals < ZookeeperException; end
46
- class NodeExists < ZookeeperException; end
47
- class NotEmpty < ZookeeperException; end
48
- class SessionExpired < ZookeeperException; end
49
- class InvalidCallback < ZookeeperException; end
50
- class InvalidACL < ZookeeperException; end
51
- class AuthFailed < ZookeeperException; end
52
- class Closing < ZookeeperException; end
53
- class Nothing < ZookeeperException; end
54
- class SessionMoved < ZookeeperException; end
55
-
56
- # these are Ruby client exceptions
57
- class ConnectionClosed < ZookeeperException; end
58
- class NotConnected < ZookeeperException; end
59
- class ShuttingDownException < ZookeeperException; end
60
- class DataTooLargeException < ZookeeperException; end
61
-
62
- # yes, make an alias, this is the way zookeeper refers to it
63
- ExpiredSession = SessionExpired
64
-
65
- def self.by_code(code)
66
- case code
67
- when ZOK then EverythingOk
68
- when ZSYSTEMERROR then SystemError
69
- when ZRUNTIMEINCONSISTENCY then RunTimeInconsistency
70
- when ZDATAINCONSISTENCY then DataInconsistency
71
- when ZCONNECTIONLOSS then ConnectionLoss
72
- when ZMARSHALLINGERROR then MarshallingError
73
- when ZUNIMPLEMENTED then Unimplemented
74
- when ZOPERATIONTIMEOUT then OperationTimeOut
75
- when ZBADARGUMENTS then BadArguments
76
- when ZINVALIDSTATE then InvalidState
77
- when ZAPIERROR then ApiError
78
- when ZNONODE then NoNode
79
- when ZNOAUTH then NoAuth
80
- when ZBADVERSION then BadVersion
81
- when ZNOCHILDRENFOREPHEMERALS then NoChildrenForEphemerals
82
- when ZNODEEXISTS then NodeExists
83
- when ZNOTEMPTY then NotEmpty
84
- when ZSESSIONEXPIRED then SessionExpired
85
- when ZINVALIDCALLBACK then InvalidCallback
86
- when ZINVALIDACL then InvalidACL
87
- when ZAUTHFAILED then AuthFailed
88
- when ZCLOSING then Closing
89
- when ZNOTHING then Nothing
90
- when ZSESSIONMOVED then SessionMoved
91
- else Exception.new("no exception defined for code #{code}")
6
+
7
+ unless defined?(CONST_MISSING_WARNING)
8
+
9
+ CONST_MISSING_WARNING = <<-EOS
10
+
11
+ ------------------------------------------------------------------------------------------
12
+ WARNING! THE ZOOKEEPER NAMESPACE HAS CHNAGED AS OF 1.0!
13
+
14
+ Please update your code to use the new heirarchy!
15
+
16
+ The constant that got you this was ZookeeperExceptions::ZookeeperException::%s
17
+
18
+ stacktrace:
19
+ %s
20
+
21
+ ------------------------------------------------------------------------------------------
22
+
23
+ EOS
24
+ end
25
+
26
+ # NOTE(slyphon): Since 0.4 all of the ZookeeperException subclasses were
27
+ # defined inside of ZookeeperException, which always seemed well, icky.
28
+ # if someone references one of these we'll print out a warning and
29
+ # then give them the constant
30
+ #
31
+ def self.const_missing(const)
32
+ if Zookeeper::Exceptions.const_defined?(const)
33
+
34
+ stacktrace = caller[0..-2].reject {|n| n =~ %r%/rspec/% }.map { |n| "\t#{n}" }.join("\n")
35
+
36
+ Zookeeper.deprecation_warning(CONST_MISSING_WARNING % [const.to_s, stacktrace])
37
+
38
+
39
+ Zookeeper::Exceptions.const_get(const).tap do |const_val|
40
+ self.const_set(const, const_val)
41
+ end
42
+ else
43
+ super
92
44
  end
93
45
  end
46
+ end
47
+
48
+
49
+ class EverythingOk < ZookeeperException; end
50
+ class SystemError < ZookeeperException; end
51
+ class RunTimeInconsistency < ZookeeperException; end
52
+ class DataInconsistency < ZookeeperException; end
53
+ class ConnectionLoss < ZookeeperException; end
54
+ class MarshallingError < ZookeeperException; end
55
+ class Unimplemented < ZookeeperException; end
56
+ class OperationTimeOut < ZookeeperException; end
57
+ class BadArguments < ZookeeperException; end
58
+ class InvalidState < ZookeeperException; end
59
+ class ApiError < ZookeeperException; end
60
+ class NoNode < ZookeeperException; end
61
+ class NoAuth < ZookeeperException; end
62
+ class BadVersion < ZookeeperException; end
63
+ class NoChildrenForEphemerals < ZookeeperException; end
64
+ class NodeExists < ZookeeperException; end
65
+ class NotEmpty < ZookeeperException; end
66
+ class SessionExpired < ZookeeperException; end
67
+ class InvalidCallback < ZookeeperException; end
68
+ class InvalidACL < ZookeeperException; end
69
+ class AuthFailed < ZookeeperException; end
70
+ class Closing < ZookeeperException; end
71
+ class Nothing < ZookeeperException; end
72
+ class SessionMoved < ZookeeperException; end
73
+
74
+ # these are Ruby client exceptions
75
+ class ConnectionClosed < ZookeeperException; end
76
+ class NotConnected < ZookeeperException; end
77
+ class ShuttingDownException < ZookeeperException; end
78
+ class DataTooLargeException < ZookeeperException; end
79
+
80
+ # raised when the user tries to use a connection after a fork()
81
+ # without calling reopen() in the C client
82
+ #
83
+ # (h/t: @pletern http://git.io/zIsq1Q)
84
+ class InheritedConnectionError < ZookeeperException; end
85
+
86
+ # yes, make an alias, this is the way zookeeper refers to it
87
+ ExpiredSession = SessionExpired unless defined?(ExpiredSession)
94
88
 
95
- def self.raise_on_error(code)
96
- exc = self.by_code(code)
97
- raise exc unless exc == EverythingOk
89
+ def self.by_code(code)
90
+ case code
91
+ when ZOK then EverythingOk
92
+ when ZSYSTEMERROR then SystemError
93
+ when ZRUNTIMEINCONSISTENCY then RunTimeInconsistency
94
+ when ZDATAINCONSISTENCY then DataInconsistency
95
+ when ZCONNECTIONLOSS then ConnectionLoss
96
+ when ZMARSHALLINGERROR then MarshallingError
97
+ when ZUNIMPLEMENTED then Unimplemented
98
+ when ZOPERATIONTIMEOUT then OperationTimeOut
99
+ when ZBADARGUMENTS then BadArguments
100
+ when ZINVALIDSTATE then InvalidState
101
+ when ZAPIERROR then ApiError
102
+ when ZNONODE then NoNode
103
+ when ZNOAUTH then NoAuth
104
+ when ZBADVERSION then BadVersion
105
+ when ZNOCHILDRENFOREPHEMERALS then NoChildrenForEphemerals
106
+ when ZNODEEXISTS then NodeExists
107
+ when ZNOTEMPTY then NotEmpty
108
+ when ZSESSIONEXPIRED then SessionExpired
109
+ when ZINVALIDCALLBACK then InvalidCallback
110
+ when ZINVALIDACL then InvalidACL
111
+ when ZAUTHFAILED then AuthFailed
112
+ when ZCLOSING then Closing
113
+ when ZNOTHING then Nothing
114
+ when ZSESSIONMOVED then SessionMoved
115
+ else ZookeeperException.new("no exception defined for code #{code}")
98
116
  end
99
117
  end
100
- end
118
+
119
+ def self.raise_on_error(code)
120
+ exc = self.by_code(code)
121
+ raise exc unless exc == EverythingOk
122
+ end
123
+ end # Exceptions
124
+ end # Zookeeper
@@ -0,0 +1,165 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Zookeeper
5
+ # @private
6
+ module RakeTasks
7
+ def self.define_test_tasks_for(*rubies)
8
+ rubies.each do |r|
9
+
10
+ TestOneRuby.new(:name => r) do |tor|
11
+ yield tor if block_given?
12
+ end
13
+ end
14
+ end
15
+
16
+ class TestOneRuby < ::Rake::TaskLib
17
+ include ::Rake::DSL if defined?(::Rake::DSL)
18
+
19
+ DEFAULT_RVM_RUBY_NAME = '1.9.3'
20
+
21
+ # defaults to 'zk', test tasks will be built under this
22
+ attr_accessor :namespace
23
+
24
+ # the name of the task
25
+ # (tasks will be 'zk:1.9.3:run_rspec')
26
+ #
27
+ # this is mainly here so that the rvm ruby name rbx-2.0.testing
28
+ # will have its tasks defined as 'zk:rbx'
29
+ attr_accessor :name
30
+
31
+ # what is the rvm name we should use for testing? (i.e. could be an alias)
32
+ # defaults to {#name}
33
+ attr_accessor :rvm_ruby_name
34
+
35
+ # any extra environment variables?
36
+ attr_accessor :env
37
+
38
+ # gemset name to use, deafults to the name of the gemspec in the top of the
39
+ # project directory (minus the .gempsec)
40
+ attr_accessor :gemset_name
41
+
42
+ # @private
43
+ attr_reader :ruby_with_gemset,
44
+ :create_gemset_name,
45
+ :clobber_task_name,
46
+ :clean_task_name,
47
+ :build_task_name,
48
+ :bundle_task_name,
49
+ :rspec_task_name,
50
+ :phony_gemfile_link_name,
51
+ :phony_gemfile_lock_name
52
+
53
+
54
+ def self.default_gemset_name
55
+ ary = Dir['*.gemspec']
56
+ raise 'No gemspec found' if ary.empty?
57
+ ary.first[/(.+)\.gemspec\Z/, 1]
58
+ end
59
+
60
+ def initialize(opts={})
61
+ @namespace = 'zk'
62
+ @name = nil
63
+ @env = {}
64
+ @rvm_ruby_name = nil
65
+ @gemset_name = nil
66
+
67
+ opts.each { |k,v| __send__(:"#{k}=", v) }
68
+
69
+ yield self if block_given?
70
+
71
+ @gemset_name ||= self.class.default_gemset_name
72
+
73
+ # XXX: add an exception just for me in here (yes, i know this is naughty)
74
+ # or else i'd have to do this in every zk variant i want to test
75
+ # (like i have to now)
76
+
77
+ unless @rvm_ruby_name
78
+ @rvm_ruby_name = 'rbx-2.0.testing' if @name == 'rbx'
79
+ end
80
+
81
+ @rvm_ruby_name ||= name
82
+
83
+ @ruby_with_gemset = "#{@rvm_ruby_name}@#{@gemset_name}"
84
+ @create_gemset_name = "#{namespace}:#{name}:create_gemset"
85
+ @clobber_task_name = "#{namespace}:#{name}:clobber"
86
+ @clean_task_name = "#{namespace}:#{name}:clean"
87
+ @build_task_name = "#{namespace}:#{name}:build"
88
+ @bundle_task_name = "#{namespace}:#{name}:bundle_install"
89
+ @rspec_task_name = "#{namespace}:#{name}:run_rspec"
90
+ @phony_gemfile_link_name = "Gemfile.#{name}"
91
+ @phony_gemfile_lock_name = "#{phony_gemfile_link_name}.lock"
92
+
93
+ define_tasks
94
+ end
95
+
96
+ private
97
+ def need_ext_build?
98
+ name != 'jruby' && File.directory?('./ext')
99
+ end
100
+
101
+ def define_tasks
102
+ file phony_gemfile_link_name do
103
+ # apparently, rake doesn't deal with symlinks intelligently :P
104
+ ln_s('Gemfile', phony_gemfile_link_name) unless File.symlink?(phony_gemfile_link_name)
105
+ end
106
+
107
+ task :clean do
108
+ rm_rf [phony_gemfile_lock_name, phony_gemfile_lock_name]
109
+ end
110
+
111
+ task create_gemset_name do
112
+ sh "rvm #{rvm_ruby_name} do rvm gemset create #{gemset_name}"
113
+ end
114
+
115
+ task clobber_task_name do
116
+ if need_ext_build?
117
+ cd 'ext' do
118
+ sh "rake clobber"
119
+ end
120
+ end
121
+ end
122
+
123
+ task clean_task_name do
124
+ if need_ext_build?
125
+ cd 'ext' do
126
+ sh "rake clean"
127
+ end
128
+ end
129
+ end
130
+
131
+ task build_task_name => [create_gemset_name, clean_task_name] do
132
+ if need_ext_build?
133
+ cd 'ext' do
134
+ sh "rvm #{ruby_with_gemset} do rake build"
135
+ end
136
+ end
137
+ end
138
+
139
+ task bundle_task_name => [phony_gemfile_link_name, build_task_name] do
140
+ sh "rvm #{ruby_with_gemset} do bundle install --gemfile #{phony_gemfile_link_name}"
141
+ end
142
+
143
+ task rspec_task_name => bundle_task_name do
144
+ sh "rvm #{ruby_with_gemset} do env BUNDLE_GEMFILE=#{phony_gemfile_link_name} bundle exec rspec spec --fail-fast"
145
+ end
146
+
147
+ task "#{namespace}:#{name}" => rspec_task_name
148
+
149
+ task "#{namespace}:test_all_rubies" => rspec_task_name
150
+
151
+ unless Rake::Task.task_defined?("#{namespace}:test_all")
152
+ task "#{namespace}:test_all" do
153
+ require 'benchmark'
154
+ t = Benchmark.realtime do
155
+ Rake::Task["#{namespace}:test_all_rubies"].invoke
156
+ end
157
+
158
+ $stderr.puts "Test run took: #{t} s"
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+
@@ -1,21 +1,21 @@
1
- module ZookeeperStat
2
- class Stat
3
- attr_reader :version, :exists, :czxid, :mzxid, :ctime, :mtime, :cversion, :aversion, :ephemeralOwner, :dataLength, :numChildren, :pzxid
1
+ module Zookeeper
2
+ class Stat
3
+ attr_reader :version, :exists, :czxid, :mzxid, :ctime, :mtime, :cversion, :aversion, :ephemeralOwner, :dataLength, :numChildren, :pzxid
4
4
 
5
- alias :ephemeral_owner :ephemeralOwner
6
- alias :num_children :numChildren
7
- alias :data_length :dataLength
5
+ alias :ephemeral_owner :ephemeralOwner
6
+ alias :num_children :numChildren
7
+ alias :data_length :dataLength
8
8
 
9
- def initialize(val)
10
- @exists = !!val
11
- @czxid, @mzxid, @ctime, @mtime, @version, @cversion, @aversion,
12
- @ephemeralOwner, @dataLength, @numChildren, @pzxid = val if val.is_a?(Array)
13
- val.each { |k,v| instance_variable_set "@#{k}", v } if val.is_a?(Hash)
14
- raise ArgumentError unless (val.is_a?(Hash) or val.is_a?(Array) or val.nil?)
15
- end
9
+ def initialize(val)
10
+ @exists = !!val
11
+ @czxid, @mzxid, @ctime, @mtime, @version, @cversion, @aversion,
12
+ @ephemeralOwner, @dataLength, @numChildren, @pzxid = val if val.is_a?(Array)
13
+ val.each { |k,v| instance_variable_set "@#{k}", v } if val.is_a?(Hash)
14
+ raise ArgumentError unless (val.is_a?(Hash) or val.is_a?(Array) or val.nil?)
15
+ end
16
16
 
17
- def exists?
18
- @exists
19
- end
17
+ def exists?
18
+ @exists
20
19
  end
21
20
  end
21
+ end
@@ -1,6 +1,4 @@
1
- # this "namespacing" is retarded. fix this in 1.0
2
- # @private
3
- module ZookeeperVersion
4
- VERSION = '0.9.4'
1
+ module Zookeeper
2
+ VERSION = '1.0.0.beta.1'
5
3
  DRIVER_VERSION = '3.3.5'
6
4
  end