slyphon-zookeeper 0.2.11 → 0.3.0

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.
data/Rakefile CHANGED
@@ -42,7 +42,7 @@ gemset_name = 'zookeeper'
42
42
  end
43
43
 
44
44
  task rspec_task_name => bundle_task_name do
45
- sh "rvm #{ruby_with_gemset} do bundle exec rspec spec"
45
+ sh "rvm #{ruby_with_gemset} do bundle exec rspec spec --fail-fast"
46
46
  end
47
47
 
48
48
  task "mb:test_all_rubies" => rspec_task_name
@@ -31,6 +31,7 @@ class ZookeeperBase < CZookeeper
31
31
  # $stderr.puts "%s: calling init, self.obj_id: %x" % [self.class, object_id]
32
32
  init(@host)
33
33
 
34
+ # XXX: replace this with a callback
34
35
  if timeout > 0
35
36
  time_to_stop = Time.now + timeout
36
37
  until state == Zookeeper::ZOO_CONNECTED_STATE
@@ -48,6 +49,11 @@ class ZookeeperBase < CZookeeper
48
49
  @completion_reqs = {}
49
50
  @req_mutex = Monitor.new
50
51
  @current_req_id = 1
52
+
53
+ # approximate the java behavior of raising java.lang.IllegalArgumentException if the host
54
+ # argument ends with '/'
55
+ raise ArgumentError, "Host argument #{host.inspect} may not end with /" if host.end_with?('/')
56
+
51
57
  @host = host
52
58
 
53
59
  @start_stop_mutex = Monitor.new
@@ -108,6 +114,14 @@ class ZookeeperBase < CZookeeper
108
114
  end
109
115
  end
110
116
 
117
+ # the C lib doesn't strip the chroot path off of returned path values, which
118
+ # is pretty damn annoying. this is used to clean things up.
119
+ def create(*args)
120
+ # since we don't care about the inputs, just glob args
121
+ rc, new_path = super(*args)
122
+ [rc, strip_chroot_from(new_path)]
123
+ end
124
+
111
125
  def set_debug_level(int)
112
126
  warn "DEPRECATION WARNING: #{self.class.name}#set_debug_level, it has moved to the class level and will be removed in a future release"
113
127
  self.class.set_debug_level(int)
@@ -143,6 +157,35 @@ class ZookeeperBase < CZookeeper
143
157
  end
144
158
 
145
159
  protected
160
+ # this is a hack: to provide consistency between the C and Java drivers when
161
+ # using a chrooted connection, we wrap the callback in a block that will
162
+ # strip the chroot path from the returned path (important in an async create
163
+ # sequential call). This is the only place where we can hook *just* the C
164
+ # version. The non-async manipulation is handled in ZookeeperBase#create.
165
+ #
166
+ def setup_completion(req_id, meth_name, call_opts)
167
+
168
+ if (meth_name == :create) and cb = call_opts[:callback]
169
+ call_opts[:callback] = lambda do |hash|
170
+ # in this case the string will be the absolute zookeeper path (i.e.
171
+ # with the chroot still prepended to the path). Here's where we strip it off
172
+ hash[:string] = strip_chroot_from(hash[:string])
173
+
174
+ # call the original callback
175
+ cb.call(hash)
176
+ end
177
+ end
178
+
179
+ # pass this along to the ZookeeperCommon implementation
180
+ super(req_id, meth_name, call_opts)
181
+ end
182
+
183
+ # if we're chrooted, this method will strip the chroot prefix from +path+
184
+ def strip_chroot_from(path)
185
+ return path unless (chrooted? and path and path.start_with?(chroot_path))
186
+ path[chroot_path.length..-1]
187
+ end
188
+
146
189
  def barf_unless_running!
147
190
  @start_stop_mutex.synchronize do
148
191
  raise ShuttingDownException unless (@_running and not @_closed)
@@ -169,5 +212,22 @@ protected
169
212
  true
170
213
  }
171
214
  end
215
+
216
+ def chrooted?
217
+ !chroot_path.empty?
218
+ end
219
+
220
+ def chroot_path
221
+ if @chroot_path.nil?
222
+ @chroot_path =
223
+ if idx = @host.index('/')
224
+ @host.slice(idx, @host.length)
225
+ else
226
+ ''
227
+ end
228
+ end
229
+
230
+ @chroot_path
231
+ end
172
232
  end
173
233
 
data/lib/zookeeper.rb CHANGED
@@ -45,7 +45,7 @@ class Zookeeper < ZookeeperBase
45
45
  assert_supported_keys(options, [:path, :watcher, :watcher_context, :callback, :callback_context])
46
46
  assert_required_keys(options, [:path])
47
47
 
48
- req_id = setup_call(options)
48
+ req_id = setup_call(:get, options)
49
49
  rc, value, stat = super(req_id, options[:path], options[:callback], options[:watcher])
50
50
 
51
51
  rv = { :req_id => req_id, :rc => rc }
@@ -59,7 +59,7 @@ class Zookeeper < ZookeeperBase
59
59
  assert_valid_data_size!(options[:data])
60
60
  options[:version] ||= -1
61
61
 
62
- req_id = setup_call(options)
62
+ req_id = setup_call(:set, options)
63
63
  rc, stat = super(req_id, options[:path], options[:data], options[:callback], options[:version])
64
64
 
65
65
  rv = { :req_id => req_id, :rc => rc }
@@ -71,7 +71,7 @@ class Zookeeper < ZookeeperBase
71
71
  assert_supported_keys(options, [:path, :callback, :callback_context, :watcher, :watcher_context])
72
72
  assert_required_keys(options, [:path])
73
73
 
74
- req_id = setup_call(options)
74
+ req_id = setup_call(:get_children, options)
75
75
  rc, children, stat = super(req_id, options[:path], options[:callback], options[:watcher])
76
76
 
77
77
  rv = { :req_id => req_id, :rc => rc }
@@ -83,7 +83,7 @@ class Zookeeper < ZookeeperBase
83
83
  assert_supported_keys(options, [:path, :callback, :callback_context, :watcher, :watcher_context])
84
84
  assert_required_keys(options, [:path])
85
85
 
86
- req_id = setup_call(options)
86
+ req_id = setup_call(:stat, options)
87
87
  rc, stat = exists(req_id, options[:path], options[:callback], options[:watcher])
88
88
 
89
89
  rv = { :req_id => req_id, :rc => rc }
@@ -102,7 +102,7 @@ class Zookeeper < ZookeeperBase
102
102
 
103
103
  options[:acl] ||= ZOO_OPEN_ACL_UNSAFE
104
104
 
105
- req_id = setup_call(options)
105
+ req_id = setup_call(:create, options)
106
106
  rc, newpath = super(req_id, options[:path], options[:data], options[:callback], options[:acl], flags)
107
107
 
108
108
  rv = { :req_id => req_id, :rc => rc }
@@ -115,7 +115,7 @@ class Zookeeper < ZookeeperBase
115
115
  assert_required_keys(options, [:path])
116
116
  options[:version] ||= -1
117
117
 
118
- req_id = setup_call(options)
118
+ req_id = setup_call(:delete, options)
119
119
  rc = super(req_id, options[:path], options[:version], options[:callback])
120
120
 
121
121
  { :req_id => req_id, :rc => rc }
@@ -127,7 +127,7 @@ class Zookeeper < ZookeeperBase
127
127
  assert_required_keys(options, [:path, :acl])
128
128
  options[:version] ||= -1
129
129
 
130
- req_id = setup_call(options)
130
+ req_id = setup_call(:set_acl, options)
131
131
  rc = super(req_id, options[:path], options[:acl], options[:callback], options[:version])
132
132
 
133
133
  { :req_id => req_id, :rc => rc }
@@ -138,7 +138,7 @@ class Zookeeper < ZookeeperBase
138
138
  assert_supported_keys(options, [:path, :callback, :callback_context])
139
139
  assert_required_keys(options, [:path])
140
140
 
141
- req_id = setup_call(options)
141
+ req_id = setup_call(:get_acl, options)
142
142
  rc, acls, stat = super(req_id, options[:path], options[:callback])
143
143
 
144
144
  rv = { :req_id => req_id, :rc => rc }
@@ -242,22 +242,6 @@ protected
242
242
  end
243
243
 
244
244
  private
245
- def setup_call(opts)
246
- req_id = nil
247
- @req_mutex.synchronize {
248
- req_id = @current_req_id
249
- @current_req_id += 1
250
- setup_completion(req_id, opts) if opts[:callback]
251
- setup_watcher(req_id, opts) if opts[:watcher]
252
- }
253
- req_id
254
- end
255
-
256
- def setup_watcher(req_id, call_opts)
257
- @watcher_reqs[req_id] = { :watcher => call_opts[:watcher],
258
- :context => call_opts[:watcher_context] }
259
- end
260
-
261
245
  # TODO: Sanitize user mistakes by unregistering watchers from ops that
262
246
  # don't return ZOK (except wexists)? Make users clean up after themselves for now.
263
247
  def unregister_watcher(req_id)
@@ -45,10 +45,12 @@ module ZookeeperCallbacks
45
45
 
46
46
  class StringCallback < Callback
47
47
  ## acreate, async
48
- attr_reader :return_code, :path
48
+ attr_reader :return_code, :string, :context
49
+
50
+ alias path string
49
51
 
50
52
  def initialize_context(hash)
51
- @return_code, @path, @context = hash[:rc], hash[:string], hash[:context]
53
+ @return_code, @string, @context = hash[:rc], hash[:string], hash[:context]
52
54
  end
53
55
  end
54
56
 
@@ -10,30 +10,36 @@ module ZookeeperCommon
10
10
  end
11
11
 
12
12
  protected
13
- def setup_call(opts)
13
+ def setup_call(meth_name, opts)
14
14
  req_id = nil
15
15
  @req_mutex.synchronize {
16
16
  req_id = @current_req_id
17
17
  @current_req_id += 1
18
- setup_completion(req_id, opts) if opts[:callback]
18
+ setup_completion(req_id, meth_name, opts) if opts[:callback]
19
19
  setup_watcher(req_id, opts) if opts[:watcher]
20
20
  }
21
21
  req_id
22
22
  end
23
-
23
+
24
24
  def setup_watcher(req_id, call_opts)
25
25
  @watcher_reqs[req_id] = { :watcher => call_opts[:watcher],
26
26
  :context => call_opts[:watcher_context] }
27
27
  end
28
28
 
29
- def setup_completion(req_id, call_opts)
29
+ # as a hack, to provide consistency between the java implementation and the C
30
+ # implementation when dealing w/ chrooted connections, we override this in
31
+ # ext/zookeeper_base.rb to wrap the callback in a chroot-path-stripping block.
32
+ #
33
+ # we don't use meth_name here, but we need it in the C implementation
34
+ #
35
+ def setup_completion(req_id, meth_name, call_opts)
30
36
  @completion_reqs[req_id] = { :callback => call_opts[:callback],
31
37
  :context => call_opts[:callback_context] }
32
38
  end
33
39
 
34
40
  def get_watcher(req_id)
35
41
  @req_mutex.synchronize {
36
- req_id != ZKRB_GLOBAL_CB_REQ ? @watcher_reqs.delete(req_id) : @watcher_reqs[req_id]
42
+ (req_id == ZKRB_GLOBAL_CB_REQ) ? @watcher_reqs[req_id] : @watcher_reqs.delete(req_id)
37
43
  }
38
44
  end
39
45
 
@@ -90,6 +96,4 @@ protected
90
96
  "Required arguments are: #{required.inspect}, but only the arguments #{args.keys.inspect} were supplied."
91
97
  end
92
98
  end
93
-
94
99
  end
95
-
@@ -11,7 +11,11 @@ module ZookeeperStat
11
11
  @czxid, @mzxid, @ctime, @mtime, @version, @cversion, @aversion,
12
12
  @ephemeralOwner, @dataLength, @numChildren, @pzxid = val if val.is_a?(Array)
13
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)
14
+ raise ArgumentError unless (val.is_a?(Hash) or val.is_a?(Array) or val.nil?)
15
+ end
16
+
17
+ def exists?
18
+ @exists
15
19
  end
16
20
  end
17
21
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "slyphon-zookeeper"
6
- s.version = '0.2.11'
6
+ s.version = '0.3.0'
7
7
 
8
8
  s.authors = ["Phillip Pearson", "Eric Maland", "Evan Weaver", "Brian Wickman", "Neil Conway", "Jonathan D. Simms"]
9
9
  s.email = ["slyphon@gmail.com"]
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_development_dependency 'eventmachine', '1.0.0.beta.4'
17
17
  s.add_development_dependency 'evented-spec', '~> 0.9.0'
18
18
  s.add_development_dependency 'rake', '~> 0.9.0'
19
+ s.add_development_dependency 'pry'
19
20
 
20
21
  s.files = `git ls-files`.split("\n")
21
22
  s.require_paths = ["lib"]
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,7 @@ Zookeeper.logger = Logger.new(File.expand_path('../../test.log', __FILE__)).tap
13
13
  log.level = Logger::DEBUG
14
14
  end
15
15
 
16
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }
16
17
 
17
18
  # NOTE: this is a useful debugging setup. have our logs and the low-level C
18
19
  # logging statements both go to stderr. to use, comment the above and uncomment
@@ -25,22 +26,6 @@ def logger
25
26
  Zookeeper.logger
26
27
  end
27
28
 
28
-
29
- require 'rspec/core/formatters/progress_formatter'
30
-
31
- module RSpec
32
- module Core
33
- module Formatters
34
- class ProgressFormatter
35
- def example_started(example)
36
- Zookeeper.logger.info(yellow("=====<([ #{example.full_description} ])>====="))
37
- super(example)
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
29
  RSpec.configure do |config|
45
30
  config.mock_with :flexmock
46
31
  end
@@ -55,4 +40,3 @@ def wait_until(timeout=10, &block)
55
40
  end
56
41
  end
57
42
 
58
-
@@ -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
+
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  shared_examples_for "all success return values" do
4
4
  it %[should have a return code of Zookeeper::ZOK] do
@@ -10,26 +10,32 @@ shared_examples_for "all success return values" do
10
10
  end
11
11
  end
12
12
 
13
- describe Zookeeper do
14
- before do
15
- @path = "/_zktest_"
16
- @data = "underpants"
17
-
18
- @zk = Zookeeper.new('localhost:2181')
13
+ shared_examples_for "all" do
14
+ def ensure_node(path, data)
15
+ if zk.stat(:path => path)[:stat].exists?
16
+ zk.set(:path => path, :data => data)
17
+ else
18
+ zk.create(:path => path, :data => data)
19
+ end
20
+ end
19
21
 
20
- # uncomment for driver debugging output
21
- #@zk.set_debug_level(Zookeeper::ZOO_LOG_LEVEL_DEBUG) unless defined?(::JRUBY_VERSION)
22
+ before :each do
23
+ ensure_node(path, data)
24
+ end
22
25
 
23
- @zk.create(:path => @path, :data => @data)
26
+ after :each do
27
+ ensure_node(path, data)
24
28
  end
25
29
 
26
- after do
27
- @zk.delete(:path => @path)
28
- @zk.close
30
+ after :all do
31
+ Zookeeper.logger.warn "running shared examples after :all"
32
+ # close the chrooted connection
33
+ zk.delete(:path => path)
34
+ zk.close
29
35
 
30
36
  wait_until do
31
37
  begin
32
- !@zk.connected?
38
+ !zk.connected?
33
39
  rescue RuntimeError
34
40
  true
35
41
  end
@@ -43,11 +49,11 @@ describe Zookeeper do
43
49
  it_should_behave_like "all success return values"
44
50
 
45
51
  before do
46
- @rv = @zk.get(:path => @path)
52
+ @rv = zk.get(:path => path)
47
53
  end
48
54
 
49
55
  it %[should return the data] do
50
- @rv[:data].should == @data
56
+ @rv[:data].should == data
51
57
  end
52
58
 
53
59
  it %[should return a stat] do
@@ -63,37 +69,37 @@ describe Zookeeper do
63
69
  @event = nil
64
70
  @watcher = Zookeeper::WatcherCallback.new
65
71
 
66
- @rv = @zk.get(:path => @path, :watcher => @watcher, :watcher_context => @path)
72
+ @rv = zk.get(:path => path, :watcher => @watcher, :watcher_context => path)
67
73
  end
68
74
 
69
75
  it %[should return the data] do
70
- @rv[:data].should == @data
76
+ @rv[:data].should == data
71
77
  end
72
78
 
73
79
  it %[should set a watcher on the node] do
74
80
  # test the watcher by changing node data
75
- @zk.set(:path => @path, :data => 'blah')[:rc].should be_zero
81
+ zk.set(:path => path, :data => 'blah')[:rc].should be_zero
76
82
 
77
83
  wait_until(1.0) { @watcher.completed? }
78
84
 
79
- @watcher.path.should == @path
80
- @watcher.context.should == @path
85
+ @watcher.path.should == path
86
+ @watcher.context.should == path
81
87
  @watcher.should be_completed
82
88
  @watcher.type.should == Zookeeper::ZOO_CHANGED_EVENT
83
89
  end
84
90
  end
85
91
 
86
92
  describe :async do
87
- it_should_behave_like "all success return values"
88
-
89
93
  before do
90
94
  @cb = Zookeeper::DataCallback.new
91
95
 
92
- @rv = @zk.get(:path => @path, :callback => @cb, :callback_context => @path)
96
+ @rv = zk.get(:path => path, :callback => @cb, :callback_context => path)
93
97
  wait_until(1.0) { @cb.completed? }
94
98
  @cb.should be_completed
95
99
  end
96
100
 
101
+ it_should_behave_like "all success return values"
102
+
97
103
  it %[should have a return code of ZOK] do
98
104
  @cb.return_code.should == Zookeeper::ZOK
99
105
  end
@@ -104,7 +110,7 @@ describe Zookeeper do
104
110
  end
105
111
 
106
112
  it %[should have the data] do
107
- @cb.data.should == @data
113
+ @cb.data.should == data
108
114
  end
109
115
  end
110
116
 
@@ -115,7 +121,7 @@ describe Zookeeper do
115
121
  @cb = Zookeeper::DataCallback.new
116
122
  @watcher = Zookeeper::WatcherCallback.new
117
123
 
118
- @rv = @zk.get(:path => @path, :callback => @cb, :callback_context => @path, :watcher => @watcher, :watcher_context => @path)
124
+ @rv = zk.get(:path => path, :callback => @cb, :callback_context => path, :watcher => @watcher, :watcher_context => path)
119
125
  wait_until(1.0) { @cb.completed? }
120
126
  @cb.should be_completed
121
127
  end
@@ -126,7 +132,7 @@ describe Zookeeper do
126
132
  end
127
133
 
128
134
  it %[should have the data] do
129
- @cb.data.should == @data
135
+ @cb.data.should == data
130
136
  end
131
137
 
132
138
  it %[should have a return code of ZOK] do
@@ -134,20 +140,20 @@ describe Zookeeper do
134
140
  end
135
141
 
136
142
  it %[should set a watcher on the node] do
137
- @zk.set(:path => @path, :data => 'blah')[:rc].should be_zero
143
+ zk.set(:path => path, :data => 'blah')[:rc].should be_zero
138
144
 
139
145
  wait_until(2) { @watcher.completed? }
140
146
 
141
147
  @watcher.should be_completed
142
148
 
143
- @watcher.path.should == @path
144
- @watcher.context.should == @path
149
+ @watcher.path.should == path
150
+ @watcher.context.should == path
145
151
  end
146
152
  end
147
153
 
148
154
  describe 'bad arguments' do
149
155
  it %[should barf with a BadArguments error] do
150
- lambda { @zk.get(:bad_arg => 'what!?') }.should raise_error(ZookeeperExceptions::ZookeeperException::BadArguments)
156
+ lambda { zk.get(:bad_arg => 'what!?') }.should raise_error(ZookeeperExceptions::ZookeeperException::BadArguments)
151
157
  end
152
158
  end
153
159
  end # get
@@ -155,7 +161,7 @@ describe Zookeeper do
155
161
  describe :set do
156
162
  before do
157
163
  @new_data = "Four score and \007 years ago"
158
- @stat = @zk.stat(:path => @path)[:stat]
164
+ @stat = zk.stat(:path => path)[:stat]
159
165
  end
160
166
 
161
167
  describe :sync do
@@ -163,7 +169,7 @@ describe Zookeeper do
163
169
  it_should_behave_like "all success return values"
164
170
 
165
171
  before do
166
- @rv = @zk.set(:path => @path, :data => @new_data)
172
+ @rv = zk.set(:path => path, :data => @new_data)
167
173
  end
168
174
 
169
175
  it %[should return the new stat] do
@@ -177,7 +183,7 @@ describe Zookeeper do
177
183
  it_should_behave_like "all success return values"
178
184
 
179
185
  before do
180
- @rv = @zk.set(:path => @path, :data => @new_data, :version => @stat.version)
186
+ @rv = zk.set(:path => path, :data => @new_data, :version => @stat.version)
181
187
  end
182
188
 
183
189
  it %[should return the new stat] do
@@ -190,9 +196,9 @@ describe Zookeeper do
190
196
  describe 'with outdated version' do
191
197
  before do
192
198
  # need to do a couple of sets to ramp up the version
193
- 3.times { |n| @stat = @zk.set(:path => @path, :data => "#{@new_data}#{n}")[:stat] }
199
+ 3.times { |n| @stat = zk.set(:path => path, :data => "#{@new_data}#{n}")[:stat] }
194
200
 
195
- @rv = @zk.set(:path => @path, :data => @new_data, :version => 0)
201
+ @rv = zk.set(:path => path, :data => @new_data, :version => 0)
196
202
  end
197
203
 
198
204
  it %[should have a return code of ZBADVERSION] do
@@ -208,7 +214,7 @@ describe Zookeeper do
208
214
  it %[should barf if the data size is too large], :input_size => true do
209
215
  large_data = '0' * (1024 ** 2)
210
216
 
211
- lambda { @zk.set(:path => @path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
217
+ lambda { zk.set(:path => path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
212
218
  end
213
219
  end
214
220
  end # sync
@@ -222,7 +228,7 @@ describe Zookeeper do
222
228
  it_should_behave_like "all success return values"
223
229
 
224
230
  before do
225
- @rv = @zk.set(:path => @path, :data => @new_data, :callback => @cb, :callback_context => @path)
231
+ @rv = zk.set(:path => path, :data => @new_data, :callback => @cb, :callback_context => path)
226
232
 
227
233
  wait_until(2) { @cb.completed? }
228
234
  @cb.should be_completed
@@ -242,7 +248,7 @@ describe Zookeeper do
242
248
  it_should_behave_like "all success return values"
243
249
 
244
250
  before do
245
- @rv = @zk.set(:path => @path, :data => @new_data, :callback => @cb, :callback_context => @path, :version => @stat.version)
251
+ @rv = zk.set(:path => path, :data => @new_data, :callback => @cb, :callback_context => path, :version => @stat.version)
246
252
 
247
253
  wait_until(2) { @cb.completed? }
248
254
  @cb.should be_completed
@@ -261,9 +267,9 @@ describe Zookeeper do
261
267
  describe 'with outdated version' do
262
268
  before do
263
269
  # need to do a couple of sets to ramp up the version
264
- 3.times { |n| @stat = @zk.set(:path => @path, :data => "#{@new_data}#{n}")[:stat] }
270
+ 3.times { |n| @stat = zk.set(:path => path, :data => "#{@new_data}#{n}")[:stat] }
265
271
 
266
- @rv = @zk.set(:path => @path, :data => @new_data, :callback => @cb, :callback_context => @path, :version => 0)
272
+ @rv = zk.set(:path => path, :data => @new_data, :callback => @cb, :callback_context => path, :version => 0)
267
273
 
268
274
  wait_until(2) { @cb.completed? }
269
275
  @cb.should be_completed
@@ -282,7 +288,7 @@ describe Zookeeper do
282
288
  it %[should barf if the data size is too large], :input_size => true do
283
289
  large_data = '0' * (1024 ** 2)
284
290
 
285
- lambda { @zk.set(:path => @path, :data => large_data, :callback => @cb, :callback_context => @path) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
291
+ lambda { zk.set(:path => path, :data => large_data, :callback => @cb, :callback_context => path) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
286
292
  end
287
293
  end
288
294
 
@@ -294,13 +300,13 @@ describe Zookeeper do
294
300
  @children = %w[child0 child1 child2]
295
301
 
296
302
  @children.each do |name|
297
- @zk.create(:path => "#{@path}/#{name}", :data => name)
303
+ zk.create(:path => "#{path}/#{name}", :data => name)
298
304
  end
299
305
  end
300
306
 
301
307
  after do
302
308
  @children.each do |name|
303
- @zk.delete(:path => "#{@path}/#{name}")
309
+ zk.delete(:path => "#{path}/#{name}")
304
310
  end
305
311
  end
306
312
 
@@ -308,7 +314,7 @@ describe Zookeeper do
308
314
  it_should_behave_like "all success return values"
309
315
 
310
316
  before do
311
- @rv = @zk.get_children(:path => @path)
317
+ @rv = zk.get_children(:path => path)
312
318
  end
313
319
 
314
320
  it %[should have an array of names of the children] do
@@ -334,11 +340,11 @@ describe Zookeeper do
334
340
 
335
341
  @watcher = Zookeeper::WatcherCallback.new
336
342
 
337
- @rv = @zk.get_children(:path => @path, :watcher => @watcher, :watcher_context => @path)
343
+ @rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path)
338
344
  end
339
345
 
340
346
  after do
341
- @zk.delete(:path => "#{@path}/#{@addtl_child}")
347
+ zk.delete(:path => "#{path}/#{@addtl_child}")
342
348
  end
343
349
 
344
350
  it %[should have an array of names of the children] do
@@ -356,13 +362,13 @@ describe Zookeeper do
356
362
  it %[should set a watcher for children on the node] do
357
363
  @watcher.should_not be_completed
358
364
 
359
- @zk.create(:path => "#{@path}/#{@addtl_child}", :data => '')[:rc].should == Zookeeper::ZOK
365
+ zk.create(:path => "#{path}/#{@addtl_child}", :data => '')[:rc].should == Zookeeper::ZOK
360
366
 
361
367
  wait_until { @watcher.completed? }
362
368
  @watcher.should be_completed
363
369
 
364
- @watcher.path.should == @path
365
- @watcher.context.should == @path
370
+ @watcher.path.should == path
371
+ @watcher.context.should == path
366
372
  @watcher.type.should == Zookeeper::ZOO_CHILD_EVENT
367
373
  end
368
374
  end
@@ -372,7 +378,7 @@ describe Zookeeper do
372
378
 
373
379
  before do
374
380
  @cb = ZookeeperCallbacks::StringsCallback.new
375
- @rv = @zk.get_children(:path => @path, :callback => @cb, :callback_context => @path)
381
+ @rv = zk.get_children(:path => path, :callback => @cb, :callback_context => path)
376
382
 
377
383
  wait_until { @cb.completed? }
378
384
  @cb.should be_completed
@@ -404,13 +410,13 @@ describe Zookeeper do
404
410
  @watcher = Zookeeper::WatcherCallback.new
405
411
  @cb = ZookeeperCallbacks::StringsCallback.new
406
412
 
407
- @rv = @zk.get_children(:path => @path, :watcher => @watcher, :watcher_context => @path, :callback => @cb, :callback_context => @path)
413
+ @rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path, :callback => @cb, :callback_context => path)
408
414
  wait_until { @cb.completed? }
409
415
  @cb.should be_completed
410
416
  end
411
417
 
412
418
  after do
413
- @zk.delete(:path => "#{@path}/#{@addtl_child}")
419
+ zk.delete(:path => "#{path}/#{@addtl_child}")
414
420
  end
415
421
 
416
422
  it %[should succeed] do
@@ -432,13 +438,13 @@ describe Zookeeper do
432
438
  it %[should set a watcher for children on the node] do
433
439
  @watcher.should_not be_completed
434
440
 
435
- @zk.create(:path => "#{@path}/#{@addtl_child}", :data => '')[:rc].should == Zookeeper::ZOK
441
+ zk.create(:path => "#{path}/#{@addtl_child}", :data => '')[:rc].should == Zookeeper::ZOK
436
442
 
437
443
  wait_until { @watcher.completed? }
438
444
  @watcher.should be_completed
439
445
 
440
- @watcher.path.should == @path
441
- @watcher.context.should == @path
446
+ @watcher.path.should == path
447
+ @watcher.context.should == path
442
448
  @watcher.type.should == Zookeeper::ZOO_CHILD_EVENT
443
449
  end
444
450
  end
@@ -451,7 +457,7 @@ describe Zookeeper do
451
457
  it_should_behave_like "all success return values"
452
458
 
453
459
  before do
454
- @rv = @zk.stat(:path => @path)
460
+ @rv = zk.stat(:path => path)
455
461
  end
456
462
 
457
463
  it %[should have a stat object] do
@@ -465,7 +471,7 @@ describe Zookeeper do
465
471
  before do
466
472
  @watcher = Zookeeper::WatcherCallback.new
467
473
 
468
- @rv = @zk.stat(:path => @path, :watcher => @watcher, :watcher_context => @path)
474
+ @rv = zk.stat(:path => path, :watcher => @watcher, :watcher_context => path)
469
475
  end
470
476
 
471
477
  it %[should have a stat object] do
@@ -475,13 +481,13 @@ describe Zookeeper do
475
481
  it %[should set a watcher for data changes on the node] do
476
482
  @watcher.should_not be_completed
477
483
 
478
- @zk.set(:path => @path, :data => 'skunk')[:rc].should == Zookeeper::ZOK
484
+ zk.set(:path => path, :data => 'skunk')[:rc].should == Zookeeper::ZOK
479
485
 
480
486
  wait_until { @watcher.completed? }
481
487
  @watcher.should be_completed
482
488
 
483
- @watcher.path.should == @path
484
- @watcher.context.should == @path
489
+ @watcher.path.should == path
490
+ @watcher.context.should == path
485
491
  @watcher.type.should == Zookeeper::ZOO_CHANGED_EVENT
486
492
  end
487
493
  end
@@ -491,7 +497,7 @@ describe Zookeeper do
491
497
 
492
498
  before do
493
499
  @cb = ZookeeperCallbacks::StatCallback.new
494
- @rv = @zk.stat(:path => @path, :callback => @cb, :callback_context => @path)
500
+ @rv = zk.stat(:path => path, :callback => @cb, :callback_context => path)
495
501
 
496
502
  wait_until { @cb.completed? }
497
503
  @cb.should be_completed
@@ -515,14 +521,14 @@ describe Zookeeper do
515
521
  @watcher = Zookeeper::WatcherCallback.new
516
522
 
517
523
  @cb = ZookeeperCallbacks::StatCallback.new
518
- @rv = @zk.stat(:path => @path, :callback => @cb, :callback_context => @path, :watcher => @watcher, :watcher_context => @path)
524
+ @rv = zk.stat(:path => path, :callback => @cb, :callback_context => path, :watcher => @watcher, :watcher_context => path)
519
525
 
520
526
  wait_until { @cb.completed? }
521
527
  @cb.should be_completed
522
528
  end
523
529
 
524
530
  after do
525
- @zk.delete(:path => "#{@path}/#{@addtl_child}")
531
+ zk.delete(:path => "#{path}/#{@addtl_child}")
526
532
  end
527
533
 
528
534
  it %[should succeed] do
@@ -536,13 +542,13 @@ describe Zookeeper do
536
542
  it %[should set a watcher for data changes on the node] do
537
543
  @watcher.should_not be_completed
538
544
 
539
- @zk.set(:path => @path, :data => 'skunk')[:rc].should == Zookeeper::ZOK
545
+ zk.set(:path => path, :data => 'skunk')[:rc].should == Zookeeper::ZOK
540
546
 
541
547
  wait_until { @watcher.completed? }
542
548
  @watcher.should be_completed
543
549
 
544
- @watcher.path.should == @path
545
- @watcher.context.should == @path
550
+ @watcher.path.should == path
551
+ @watcher.context.should == path
546
552
  @watcher.type.should == Zookeeper::ZOO_CHANGED_EVENT
547
553
  end
548
554
  end
@@ -551,7 +557,7 @@ describe Zookeeper do
551
557
  describe :create do
552
558
  before do
553
559
  # remove the path set up by the global 'before' block
554
- @zk.delete(:path => @path)
560
+ zk.delete(:path => path)
555
561
  end
556
562
 
557
563
  describe :sync do
@@ -559,7 +565,7 @@ describe Zookeeper do
559
565
  it %[should barf if the data size is too large], :input_size => true do
560
566
  large_data = '0' * (1024 ** 2)
561
567
 
562
- lambda { @zk.create(:path => @path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
568
+ lambda { zk.create(:path => path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
563
569
  end
564
570
  end
565
571
 
@@ -567,15 +573,15 @@ describe Zookeeper do
567
573
  it_should_behave_like "all success return values"
568
574
 
569
575
  before do
570
- @rv = @zk.create(:path => @path)
576
+ @rv = zk.create(:path => path)
571
577
  end
572
578
 
573
579
  it %[should return the path that was set] do
574
- @rv[:path].should == @path
580
+ @rv[:path].should == path
575
581
  end
576
582
 
577
583
  it %[should have created a permanent node] do
578
- st = @zk.stat(:path => @path)
584
+ st = zk.stat(:path => path)
579
585
  st[:rc].should == Zookeeper::ZOK
580
586
 
581
587
  st[:stat].ephemeral_owner.should == 0
@@ -586,15 +592,15 @@ describe Zookeeper do
586
592
  it_should_behave_like "all success return values"
587
593
 
588
594
  before do
589
- @rv = @zk.create(:path => @path, :ephemeral => true)
595
+ @rv = zk.create(:path => path, :ephemeral => true)
590
596
  end
591
597
 
592
598
  it %[should return the path that was set] do
593
- @rv[:path].should == @path
599
+ @rv[:path].should == path
594
600
  end
595
601
 
596
602
  it %[should have created a ephemeral node] do
597
- st = @zk.stat(:path => @path)
603
+ st = zk.stat(:path => path)
598
604
  st[:rc].should == Zookeeper::ZOK
599
605
 
600
606
  st[:stat].ephemeral_owner.should_not be_zero
@@ -605,9 +611,13 @@ describe Zookeeper do
605
611
  it_should_behave_like "all success return values"
606
612
 
607
613
  before do
608
- @orig_path = @path
609
- @rv = @zk.create(:path => @path, :sequence => true)
610
- @path = @rv[:path] # make sure this gets cleaned up
614
+ @orig_path = path
615
+ @rv = zk.create(:path => path, :sequence => true)
616
+ @s_path = @rv[:path] # make sure this gets cleaned up
617
+ end
618
+
619
+ after do
620
+ zk.delete(:path => @s_path)
611
621
  end
612
622
 
613
623
  it %[should return the path that was set] do
@@ -615,7 +625,7 @@ describe Zookeeper do
615
625
  end
616
626
 
617
627
  it %[should have created a permanent node] do
618
- st = @zk.stat(:path => @path)
628
+ st = zk.stat(:path => @s_path)
619
629
  st[:rc].should == Zookeeper::ZOK
620
630
 
621
631
  st[:stat].ephemeral_owner.should be_zero
@@ -626,9 +636,13 @@ describe Zookeeper do
626
636
  it_should_behave_like "all success return values"
627
637
 
628
638
  before do
629
- @orig_path = @path
630
- @rv = @zk.create(:path => @path, :sequence => true, :ephemeral => true)
631
- @path = @rv[:path] # make sure this gets cleaned up
639
+ @orig_path = path
640
+ @rv = zk.create(:path => path, :sequence => true, :ephemeral => true)
641
+ @s_path = @rv[:path] # make sure this gets cleaned up
642
+ end
643
+
644
+ after do
645
+ zk.delete(:path => @s_path)
632
646
  end
633
647
 
634
648
  it %[should return the path that was set] do
@@ -636,7 +650,7 @@ describe Zookeeper do
636
650
  end
637
651
 
638
652
  it %[should have created an ephemeral node] do
639
- st = @zk.stat(:path => @path)
653
+ st = zk.stat(:path => @s_path)
640
654
  st[:rc].should == Zookeeper::ZOK
641
655
 
642
656
  st[:stat].ephemeral_owner.should_not be_zero
@@ -659,7 +673,7 @@ describe Zookeeper do
659
673
  it_should_behave_like "all success return values"
660
674
 
661
675
  before do
662
- @rv = @zk.create(:path => @path, :callback => @cb, :callback_context => @path)
676
+ @rv = zk.create(:path => path, :callback => @cb, :callback_context => path)
663
677
  wait_until(2) { @cb.completed? }
664
678
  @cb.should be_completed
665
679
  end
@@ -669,11 +683,11 @@ describe Zookeeper do
669
683
  end
670
684
 
671
685
  it %[should return the path that was set] do
672
- @cb.path.should == @path
686
+ @cb.path.should == path
673
687
  end
674
688
 
675
689
  it %[should have created a permanent node] do
676
- st = @zk.stat(:path => @path)
690
+ st = zk.stat(:path => path)
677
691
  st[:rc].should == Zookeeper::ZOK
678
692
 
679
693
  st[:stat].ephemeral_owner.should == 0
@@ -685,7 +699,7 @@ describe Zookeeper do
685
699
  large_data = '0' * (1024 ** 2)
686
700
 
687
701
  lambda do
688
- @zk.create(:path => @path, :data => large_data, :callback => @cb, :callback_context => @path)
702
+ zk.create(:path => path, :data => large_data, :callback => @cb, :callback_context => path)
689
703
  end.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
690
704
  end
691
705
  end
@@ -695,7 +709,7 @@ describe Zookeeper do
695
709
  it_should_behave_like "all success return values"
696
710
 
697
711
  before do
698
- @rv = @zk.create(:path => @path, :ephemeral => true, :callback => @cb, :callback_context => @path)
712
+ @rv = zk.create(:path => path, :ephemeral => true, :callback => @cb, :callback_context => path)
699
713
  wait_until(2) { @cb.completed? }
700
714
  @cb.should be_completed
701
715
  end
@@ -705,11 +719,11 @@ describe Zookeeper do
705
719
  end
706
720
 
707
721
  it %[should return the path that was set] do
708
- @cb.path.should == @path
722
+ @cb.path.should == path
709
723
  end
710
724
 
711
725
  it %[should have created a ephemeral node] do
712
- st = @zk.stat(:path => @path)
726
+ st = zk.stat(:path => path)
713
727
  st[:rc].should == Zookeeper::ZOK
714
728
 
715
729
  st[:stat].ephemeral_owner.should_not be_zero
@@ -720,13 +734,17 @@ describe Zookeeper do
720
734
  it_should_behave_like "all success return values"
721
735
 
722
736
  before do
723
- @orig_path = @path
724
- @rv = @zk.create(:path => @path, :sequence => true, :callback => @cb, :callback_context => @path)
737
+ @orig_path = path
738
+ @rv = zk.create(:path => path, :sequence => true, :callback => @cb, :callback_context => path)
725
739
 
726
740
  wait_until(2) { @cb.completed? }
727
741
  @cb.should be_completed
728
742
 
729
- @path = @cb.path
743
+ @s_path = @cb.path
744
+ end
745
+
746
+ after do
747
+ zk.delete(:path => @s_path)
730
748
  end
731
749
 
732
750
  it %[should have a path] do
@@ -738,7 +756,7 @@ describe Zookeeper do
738
756
  end
739
757
 
740
758
  it %[should have created a permanent node] do
741
- st = @zk.stat(:path => @path)
759
+ st = zk.stat(:path => @s_path)
742
760
  st[:rc].should == Zookeeper::ZOK
743
761
 
744
762
  st[:stat].ephemeral_owner.should be_zero
@@ -749,13 +767,17 @@ describe Zookeeper do
749
767
  it_should_behave_like "all success return values"
750
768
 
751
769
  before do
752
- @orig_path = @path
753
- @rv = @zk.create(:path => @path, :sequence => true, :ephemeral => true, :callback => @cb, :callback_context => @path)
754
- @path = @rv[:path] # make sure this gets cleaned up
770
+ @orig_path = path
771
+ @rv = zk.create(:path => path, :sequence => true, :ephemeral => true, :callback => @cb, :callback_context => path)
772
+ path = @rv[:path] # make sure this gets cleaned up
755
773
 
756
774
  wait_until(2) { @cb.completed? }
757
775
  @cb.should be_completed
758
- @path = @cb.path
776
+ @s_path = @cb.path
777
+ end
778
+
779
+ after do
780
+ zk.delete(:path => @s_path)
759
781
  end
760
782
 
761
783
  it %[should have a path] do
@@ -763,11 +785,11 @@ describe Zookeeper do
763
785
  end
764
786
 
765
787
  it %[should return the path that was set] do
766
- @path.should_not == @orig_path
788
+ @s_path.should_not == @orig_path
767
789
  end
768
790
 
769
791
  it %[should have created an ephemeral node] do
770
- st = @zk.stat(:path => @path)
792
+ st = zk.stat(:path => @s_path)
771
793
  st[:rc].should == Zookeeper::ZOK
772
794
 
773
795
  st[:stat].ephemeral_owner.should_not be_zero
@@ -782,12 +804,12 @@ describe Zookeeper do
782
804
  it_should_behave_like "all success return values"
783
805
 
784
806
  before do
785
- @zk.create(:path => @path)
786
- @rv = @zk.delete(:path => @path)
807
+ zk.create(:path => path)
808
+ @rv = zk.delete(:path => path)
787
809
  end
788
810
 
789
811
  it %[should have deleted the node] do
790
- @zk.stat(:path => @path)[:stat].exists.should be_false
812
+ zk.stat(:path => path)[:stat].exists.should be_false
791
813
  end
792
814
  end
793
815
 
@@ -795,24 +817,24 @@ describe Zookeeper do
795
817
  it_should_behave_like "all success return values"
796
818
 
797
819
  before do
798
- @zk.create(:path => @path)
820
+ zk.create(:path => path)
799
821
 
800
- @stat = @zk.stat(:path => @path)[:stat]
822
+ @stat = zk.stat(:path => path)[:stat]
801
823
  @stat.exists.should be_true
802
824
 
803
- @rv = @zk.delete(:path => @path, :version => @stat.version)
825
+ @rv = zk.delete(:path => path, :version => @stat.version)
804
826
  end
805
827
 
806
828
  it %[should have deleted the node] do
807
- @zk.stat(:path => @path)[:stat].exists.should be_false
829
+ zk.stat(:path => path)[:stat].exists.should be_false
808
830
  end
809
831
  end
810
832
 
811
833
  describe 'with old version' do
812
834
  before do
813
- 3.times { |n| @stat = @zk.set(:path => @path, :data => n.to_s)[:stat] }
835
+ 3.times { |n| @stat = zk.set(:path => path, :data => n.to_s)[:stat] }
814
836
 
815
- @rv = @zk.delete(:path => @path, :version => 0)
837
+ @rv = zk.delete(:path => path, :version => 0)
816
838
  end
817
839
 
818
840
  it %[should have a return code of ZBADVERSION] do
@@ -830,7 +852,7 @@ describe Zookeeper do
830
852
  it_should_behave_like "all success return values"
831
853
 
832
854
  before do
833
- @rv = @zk.delete(:path => @path, :callback => @cb, :callback_context => @path)
855
+ @rv = zk.delete(:path => path, :callback => @cb, :callback_context => path)
834
856
  wait_until { @cb.completed? }
835
857
  @cb.should be_completed
836
858
  end
@@ -840,7 +862,7 @@ describe Zookeeper do
840
862
  end
841
863
 
842
864
  it %[should have deleted the node] do
843
- @zk.stat(:path => @path)[:stat].exists.should be_false
865
+ zk.stat(:path => path)[:stat].exists.should be_false
844
866
  end
845
867
  end
846
868
 
@@ -848,8 +870,8 @@ describe Zookeeper do
848
870
  it_should_behave_like "all success return values"
849
871
 
850
872
  before do
851
- @stat = @zk.stat(:path => @path)[:stat]
852
- @rv = @zk.delete(:path => @path, :version => @stat.version, :callback => @cb, :callback_context => @path)
873
+ @stat = zk.stat(:path => path)[:stat]
874
+ @rv = zk.delete(:path => path, :version => @stat.version, :callback => @cb, :callback_context => path)
853
875
  wait_until { @cb.completed? }
854
876
  @cb.should be_completed
855
877
  end
@@ -859,15 +881,15 @@ describe Zookeeper do
859
881
  end
860
882
 
861
883
  it %[should have deleted the node] do
862
- @zk.stat(:path => @path)[:stat].exists.should be_false
884
+ zk.stat(:path => path)[:stat].exists.should be_false
863
885
  end
864
886
  end
865
887
 
866
888
  describe 'with old version' do
867
889
  before do
868
- 3.times { |n| @stat = @zk.set(:path => @path, :data => n.to_s)[:stat] }
890
+ 3.times { |n| @stat = zk.set(:path => path, :data => n.to_s)[:stat] }
869
891
 
870
- @rv = @zk.delete(:path => @path, :version => 0, :callback => @cb, :callback_context => @path)
892
+ @rv = zk.delete(:path => path, :version => 0, :callback => @cb, :callback_context => path)
871
893
  wait_until { @cb.completed? }
872
894
  @cb.should be_completed
873
895
  end
@@ -884,7 +906,7 @@ describe Zookeeper do
884
906
  it_should_behave_like "all success return values"
885
907
 
886
908
  before do
887
- @rv = @zk.get_acl(:path => @path)
909
+ @rv = zk.get_acl(:path => path)
888
910
  end
889
911
 
890
912
  it %[should return a stat for the path] do
@@ -909,7 +931,7 @@ describe Zookeeper do
909
931
 
910
932
  before do
911
933
  @cb = Zookeeper::ACLCallback.new
912
- @rv = @zk.get_acl(:path => @path, :callback => @cb, :callback_context => @path)
934
+ @rv = zk.get_acl(:path => path, :callback => @cb, :callback_context => path)
913
935
 
914
936
  wait_until(2) { @cb.completed? }
915
937
  @cb.should be_completed
@@ -935,7 +957,6 @@ describe Zookeeper do
935
957
  end
936
958
 
937
959
  describe :set_acl do
938
-
939
960
  before do
940
961
  @perms = 5
941
962
  @new_acl = [ZookeeperACLs::ACL.new(:perms => @perms, :id => ZookeeperACLs::ZOO_ANYONE_ID_UNSAFE)]
@@ -946,21 +967,83 @@ describe Zookeeper do
946
967
  it_should_behave_like "all success return values"
947
968
 
948
969
  before do
949
- @rv = @zk.set_acl(:path => @path, :acl => @new_acl)
970
+ @rv = zk.set_acl(:path => path, :acl => @new_acl)
950
971
  end
951
-
952
972
  end
953
973
  end
954
974
 
955
975
  describe :session_id do
956
976
  it %[should return the session_id as a Fixnum] do
957
- @zk.session_id.should be_kind_of(Fixnum)
977
+ zk.session_id.should be_kind_of(Fixnum)
958
978
  end
959
979
  end
960
980
 
961
981
  describe :session_passwd do
962
982
  it %[should return the session passwd as a String] do
963
- @zk.session_passwd.should be_kind_of(String)
983
+ zk.session_passwd.should be_kind_of(String)
964
984
  end
965
985
  end
966
986
  end
987
+
988
+ describe 'Zookeeper' do
989
+ let(:path) { "/_zktest_" }
990
+ let(:data) { "underpants" }
991
+ let(:zk_host) { 'localhost:2181' }
992
+
993
+ let(:zk) do
994
+ Zookeeper.logger.debug { "creating root instance" }
995
+ Zookeeper.new(zk_host)
996
+ end
997
+
998
+ it_should_behave_like "all"
999
+ end
1000
+
1001
+
1002
+ describe 'Zookeeper chrooted' do
1003
+ let(:path) { "/_zkchroottest_" }
1004
+ let(:data) { "underpants" }
1005
+ let(:chroot_path) { '/slyphon-zookeeper-chroot' }
1006
+
1007
+ # Ok, i can't explain this, but when you run these tests, the zk instance
1008
+ # gets set up *once* and re-used, which is different from above, where it's
1009
+ # set up new each time
1010
+ #
1011
+ let(:zk) do
1012
+ Zookeeper.logger.debug { "creating chrooted zk instance" }
1013
+ Zookeeper.new("localhost:2181#{chroot_path}")
1014
+ end
1015
+
1016
+ def with_open_zk(host='localhost:2181')
1017
+ z = Zookeeper.new(host)
1018
+ yield z
1019
+ ensure
1020
+ z.close
1021
+
1022
+ wait_until do
1023
+ begin
1024
+ !z.connected?
1025
+ rescue RuntimeError
1026
+ true
1027
+ end
1028
+ end
1029
+ end
1030
+
1031
+ before :all do
1032
+ Zookeeper.logger.warn "running before :all"
1033
+
1034
+ with_open_zk do |z|
1035
+ z.create(:path => chroot_path, :data => '')
1036
+ end
1037
+ end
1038
+
1039
+ after :all do
1040
+ with_open_zk do |z|
1041
+ z.delete(:path => chroot_path)
1042
+ end
1043
+ end
1044
+
1045
+ it_should_behave_like "all"
1046
+ end
1047
+
1048
+
1049
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slyphon-zookeeper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 11
10
- version: 0.2.11
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phillip Pearson
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2012-03-27 00:00:00 Z
23
+ date: 2012-04-11 00:00:00 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
@@ -104,6 +104,20 @@ dependencies:
104
104
  version: 0.9.0
105
105
  type: :development
106
106
  version_requirements: *id005
107
+ - !ruby/object:Gem::Dependency
108
+ name: pry
109
+ prerelease: false
110
+ requirement: &id006 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ type: :development
120
+ version_requirements: *id006
107
121
  description: twitter's zookeeper client
108
122
  email:
109
123
  - slyphon@gmail.com
@@ -147,6 +161,7 @@ files:
147
161
  - spec/em_spec.rb
148
162
  - spec/log4j.properties
149
163
  - spec/spec_helper.rb
164
+ - spec/support/progress_formatter.rb
150
165
  - spec/zookeeper_spec.rb
151
166
  - test/test_basic.rb
152
167
  - test/test_callback1.rb
@@ -193,6 +208,7 @@ test_files:
193
208
  - spec/em_spec.rb
194
209
  - spec/log4j.properties
195
210
  - spec/spec_helper.rb
211
+ - spec/support/progress_formatter.rb
196
212
  - spec/zookeeper_spec.rb
197
213
  - test/test_basic.rb
198
214
  - test/test_callback1.rb