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
@@ -34,7 +34,7 @@ shared_examples_for "connection" do
34
34
 
35
35
  it %[should return a stat] do
36
36
  @rv[:stat].should_not be_nil
37
- @rv[:stat].should be_kind_of(ZookeeperStat::Stat)
37
+ @rv[:stat].should be_kind_of(Zookeeper::Stat)
38
38
  end
39
39
  end
40
40
 
@@ -43,7 +43,7 @@ shared_examples_for "connection" do
43
43
 
44
44
  before do
45
45
  @event = nil
46
- @watcher = Zookeeper::WatcherCallback.new
46
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
47
47
 
48
48
  @rv = zk.get(:path => path, :watcher => @watcher, :watcher_context => path)
49
49
  end
@@ -67,7 +67,7 @@ shared_examples_for "connection" do
67
67
 
68
68
  describe :async do
69
69
  before do
70
- @cb = Zookeeper::DataCallback.new
70
+ @cb = Zookeeper::Callbacks::DataCallback.new
71
71
 
72
72
  @rv = zk.get(:path => path, :callback => @cb, :callback_context => path)
73
73
  wait_until(1.0) { @cb.completed? }
@@ -82,7 +82,7 @@ shared_examples_for "connection" do
82
82
 
83
83
  it %[should have the stat object in the callback] do
84
84
  @cb.stat.should_not be_nil
85
- @cb.stat.should be_kind_of(ZookeeperStat::Stat)
85
+ @cb.stat.should be_kind_of(Zookeeper::Stat)
86
86
  end
87
87
 
88
88
  it %[should have the data] do
@@ -94,8 +94,8 @@ shared_examples_for "connection" do
94
94
  it_should_behave_like "all success return values"
95
95
 
96
96
  before do
97
- @cb = Zookeeper::DataCallback.new
98
- @watcher = Zookeeper::WatcherCallback.new
97
+ @cb = Zookeeper::Callbacks::DataCallback.new
98
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
99
99
 
100
100
  @rv = zk.get(:path => path, :callback => @cb, :callback_context => path, :watcher => @watcher, :watcher_context => path)
101
101
  wait_until(1.0) { @cb.completed? }
@@ -104,7 +104,7 @@ shared_examples_for "connection" do
104
104
 
105
105
  it %[should have the stat object in the callback] do
106
106
  @cb.stat.should_not be_nil
107
- @cb.stat.should be_kind_of(ZookeeperStat::Stat)
107
+ @cb.stat.should be_kind_of(Zookeeper::Stat)
108
108
  end
109
109
 
110
110
  it %[should have the data] do
@@ -129,7 +129,7 @@ shared_examples_for "connection" do
129
129
 
130
130
  describe 'bad arguments' do
131
131
  it %[should barf with a BadArguments error] do
132
- lambda { zk.get(:bad_arg => 'what!?') }.should raise_error(ZookeeperExceptions::ZookeeperException::BadArguments)
132
+ lambda { zk.get(:bad_arg => 'what!?') }.should raise_error(Zookeeper::Exceptions::BadArguments)
133
133
  end
134
134
  end
135
135
  end # get
@@ -150,7 +150,7 @@ shared_examples_for "connection" do
150
150
 
151
151
  it %[should return the new stat] do
152
152
  @rv[:stat].should_not be_nil
153
- @rv[:stat].should be_kind_of(ZookeeperStat::Stat)
153
+ @rv[:stat].should be_kind_of(Zookeeper::Stat)
154
154
  @rv[:stat].version.should > @stat.version
155
155
  end
156
156
  end
@@ -164,7 +164,7 @@ shared_examples_for "connection" do
164
164
 
165
165
  it %[should return the new stat] do
166
166
  @rv[:stat].should_not be_nil
167
- @rv[:stat].should be_kind_of(ZookeeperStat::Stat)
167
+ @rv[:stat].should be_kind_of(Zookeeper::Stat)
168
168
  @rv[:stat].version.should > @stat.version
169
169
  end
170
170
  end
@@ -190,14 +190,14 @@ shared_examples_for "connection" do
190
190
  it %[should barf if the data size is too large], :input_size => true do
191
191
  large_data = '0' * (1024 ** 2)
192
192
 
193
- lambda { zk.set(:path => path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
193
+ lambda { zk.set(:path => path, :data => large_data) }.should raise_error(Zookeeper::Exceptions::DataTooLargeException)
194
194
  end
195
195
  end
196
196
  end # sync
197
197
 
198
198
  describe :async do
199
199
  before do
200
- @cb = Zookeeper::StatCallback.new
200
+ @cb = Zookeeper::Callbacks::StatCallback.new
201
201
  end
202
202
 
203
203
  describe 'without version' do
@@ -264,7 +264,7 @@ shared_examples_for "connection" do
264
264
  it %[should barf if the data size is too large], :input_size => true do
265
265
  large_data = '0' * (1024 ** 2)
266
266
 
267
- lambda { zk.set(:path => path, :data => large_data, :callback => @cb, :callback_context => path) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
267
+ lambda { zk.set(:path => path, :data => large_data, :callback => @cb, :callback_context => path) }.should raise_error(Zookeeper::Exceptions::DataTooLargeException)
268
268
  end
269
269
  end
270
270
 
@@ -303,7 +303,7 @@ shared_examples_for "connection" do
303
303
 
304
304
  it %[should have a stat object whose num_children is 3] do
305
305
  @rv[:stat].should_not be_nil
306
- @rv[:stat].should be_kind_of(ZookeeperStat::Stat)
306
+ @rv[:stat].should be_kind_of(Zookeeper::Stat)
307
307
  @rv[:stat].num_children.should == 3
308
308
  end
309
309
  end
@@ -314,7 +314,7 @@ shared_examples_for "connection" do
314
314
  before do
315
315
  @addtl_child = 'child3'
316
316
 
317
- @watcher = Zookeeper::WatcherCallback.new
317
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
318
318
 
319
319
  @rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path)
320
320
  end
@@ -331,7 +331,7 @@ shared_examples_for "connection" do
331
331
 
332
332
  it %[should have a stat object whose num_children is 3] do
333
333
  @rv[:stat].should_not be_nil
334
- @rv[:stat].should be_kind_of(ZookeeperStat::Stat)
334
+ @rv[:stat].should be_kind_of(Zookeeper::Stat)
335
335
  @rv[:stat].num_children.should == 3
336
336
  end
337
337
 
@@ -353,7 +353,7 @@ shared_examples_for "connection" do
353
353
  it_should_behave_like "all success return values"
354
354
 
355
355
  before do
356
- @cb = ZookeeperCallbacks::StringsCallback.new
356
+ @cb = Zookeeper::Callbacks::StringsCallback.new
357
357
  @rv = zk.get_children(:path => path, :callback => @cb, :callback_context => path)
358
358
 
359
359
  wait_until { @cb.completed? }
@@ -372,7 +372,7 @@ shared_examples_for "connection" do
372
372
 
373
373
  it %[should have a stat object whose num_children is 3] do
374
374
  @cb.stat.should_not be_nil
375
- @cb.stat.should be_kind_of(ZookeeperStat::Stat)
375
+ @cb.stat.should be_kind_of(Zookeeper::Stat)
376
376
  @cb.stat.num_children.should == 3
377
377
  end
378
378
  end
@@ -383,8 +383,8 @@ shared_examples_for "connection" do
383
383
  before do
384
384
  @addtl_child = 'child3'
385
385
 
386
- @watcher = Zookeeper::WatcherCallback.new
387
- @cb = ZookeeperCallbacks::StringsCallback.new
386
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
387
+ @cb = Zookeeper::Callbacks::StringsCallback.new
388
388
 
389
389
  @rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path, :callback => @cb, :callback_context => path)
390
390
  wait_until { @cb.completed? }
@@ -407,7 +407,7 @@ shared_examples_for "connection" do
407
407
 
408
408
  it %[should have a stat object whose num_children is 3] do
409
409
  @cb.stat.should_not be_nil
410
- @cb.stat.should be_kind_of(ZookeeperStat::Stat)
410
+ @cb.stat.should be_kind_of(Zookeeper::Stat)
411
411
  @cb.stat.num_children.should == 3
412
412
  end
413
413
 
@@ -445,7 +445,7 @@ shared_examples_for "connection" do
445
445
  it_should_behave_like "all success return values"
446
446
 
447
447
  before do
448
- @watcher = Zookeeper::WatcherCallback.new
448
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
449
449
 
450
450
  @rv = zk.stat(:path => path, :watcher => @watcher, :watcher_context => path)
451
451
  end
@@ -472,7 +472,7 @@ shared_examples_for "connection" do
472
472
  it_should_behave_like "all success return values"
473
473
 
474
474
  before do
475
- @cb = ZookeeperCallbacks::StatCallback.new
475
+ @cb = Zookeeper::Callbacks::StatCallback.new
476
476
  @rv = zk.stat(:path => path, :callback => @cb, :callback_context => path)
477
477
 
478
478
  wait_until { @cb.completed? }
@@ -494,9 +494,9 @@ shared_examples_for "connection" do
494
494
  before do
495
495
  @addtl_child = 'child3'
496
496
 
497
- @watcher = Zookeeper::WatcherCallback.new
497
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
498
498
 
499
- @cb = ZookeeperCallbacks::StatCallback.new
499
+ @cb = Zookeeper::Callbacks::StatCallback.new
500
500
  @rv = zk.stat(:path => path, :callback => @cb, :callback_context => path, :watcher => @watcher, :watcher_context => path)
501
501
 
502
502
  wait_until { @cb.completed? }
@@ -541,7 +541,7 @@ shared_examples_for "connection" do
541
541
  it %[should barf if the data size is too large], :input_size => true do
542
542
  large_data = '0' * (1024 ** 2)
543
543
 
544
- lambda { zk.create(:path => path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
544
+ lambda { zk.create(:path => path, :data => large_data) }.should raise_error(Zookeeper::Exceptions::DataTooLargeException)
545
545
  end
546
546
  end
547
547
 
@@ -642,7 +642,7 @@ shared_examples_for "connection" do
642
642
 
643
643
  describe :async do
644
644
  before do
645
- @cb = ZookeeperCallbacks::StringCallback.new
645
+ @cb = Zookeeper::Callbacks::StringCallback.new
646
646
  end
647
647
 
648
648
  describe :default_flags do
@@ -676,7 +676,7 @@ shared_examples_for "connection" do
676
676
 
677
677
  lambda do
678
678
  zk.create(:path => path, :data => large_data, :callback => @cb, :callback_context => path)
679
- end.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
679
+ end.should raise_error(Zookeeper::Exceptions::DataTooLargeException)
680
680
  end
681
681
  end
682
682
 
@@ -821,7 +821,7 @@ shared_examples_for "connection" do
821
821
 
822
822
  describe :async do
823
823
  before do
824
- @cb = ZookeeperCallbacks::VoidCallback.new
824
+ @cb = Zookeeper::Callbacks::VoidCallback.new
825
825
  end
826
826
 
827
827
  describe 'without version' do
@@ -886,7 +886,7 @@ shared_examples_for "connection" do
886
886
  end
887
887
 
888
888
  it %[should return a stat for the path] do
889
- @rv[:stat].should be_kind_of(ZookeeperStat::Stat)
889
+ @rv[:stat].should be_kind_of(Zookeeper::Stat)
890
890
  end
891
891
 
892
892
  it %[should return the acls] do
@@ -906,7 +906,7 @@ shared_examples_for "connection" do
906
906
  it_should_behave_like "all success return values"
907
907
 
908
908
  before do
909
- @cb = Zookeeper::ACLCallback.new
909
+ @cb = Zookeeper::Callbacks::ACLCallback.new
910
910
  @rv = zk.get_acl(:path => path, :callback => @cb, :callback_context => path)
911
911
 
912
912
  wait_until(2) { @cb.completed? }
@@ -914,7 +914,7 @@ shared_examples_for "connection" do
914
914
  end
915
915
 
916
916
  it %[should return a stat for the path] do
917
- @cb.stat.should be_kind_of(ZookeeperStat::Stat)
917
+ @cb.stat.should be_kind_of(Zookeeper::Stat)
918
918
  end
919
919
 
920
920
  it %[should return the acls] do
@@ -922,7 +922,7 @@ shared_examples_for "connection" do
922
922
  acls.should be_kind_of(Array)
923
923
 
924
924
  acl = acls.first
925
- acl.should be_kind_of(ZookeeperACLs::ACL)
925
+ acl.should be_kind_of(Zookeeper::ACLs::ACL)
926
926
 
927
927
  acl.perms.should == Zookeeper::ZOO_PERM_ALL
928
928
 
@@ -935,7 +935,7 @@ shared_examples_for "connection" do
935
935
  describe :set_acl do
936
936
  before do
937
937
  @perms = 5
938
- @new_acl = [ZookeeperACLs::ACL.new(:perms => @perms, :id => ZookeeperACLs::ZOO_ANYONE_ID_UNSAFE)]
938
+ @new_acl = [Zookeeper::ACLs::ACL.new(:perms => @perms, :id => Zookeeper::Constants::ZOO_ANYONE_ID_UNSAFE)]
939
939
  pending("No idea how to set ACLs")
940
940
  end
941
941
 
@@ -950,7 +950,7 @@ shared_examples_for "connection" do
950
950
 
951
951
  describe :session_id do
952
952
  it %[should return the session_id as a Fixnum] do
953
- zk.session_id.should be_kind_of(Fixnum)
953
+ zk.session_id.should be_kind_of(Integer)
954
954
  end
955
955
  end
956
956
 
@@ -965,7 +965,7 @@ shared_examples_for "connection" do
965
965
  it_should_behave_like "all success return values"
966
966
 
967
967
  before do
968
- @cb = Zookeeper::StringCallback.new
968
+ @cb = Zookeeper::Callbacks::StringCallback.new
969
969
  @rv = zk.sync(:path => path, :callback => @cb)
970
970
 
971
971
  wait_until(2) { @cb.completed }
@@ -975,7 +975,7 @@ shared_examples_for "connection" do
975
975
 
976
976
  describe :errors do
977
977
  it %[should barf with BadArguments if :callback is not given] do
978
- lambda { zk.sync(:path => path) }.should raise_error(ZookeeperExceptions::ZookeeperException::BadArguments)
978
+ lambda { zk.sync(:path => path) }.should raise_error(Zookeeper::Exceptions::BadArguments)
979
979
  end
980
980
  end
981
981
  end
@@ -1014,5 +1014,20 @@ shared_examples_for "connection" do
1014
1014
  end
1015
1015
  end
1016
1016
  end
1017
+
1018
+ unless defined?(::JRUBY_VERSION)
1019
+ describe 'fork protection' do
1020
+ it %[should raise an InheritedConnectionError if the current Process.pid is different from the one that created the client] do
1021
+ pid = Process.pid
1022
+ begin
1023
+ Process.stub(:pid => -1)
1024
+ lambda { zk.stat(:path => path) }.should raise_error(Zookeeper::Exceptions::InheritedConnectionError)
1025
+ ensure
1026
+ # ensure we reset this, only want it to fail during the test
1027
+ Process.stub(:pid => pid)
1028
+ end
1029
+ end
1030
+ end
1031
+ end
1017
1032
  end
1018
1033
 
data/spec/spec_helper.rb CHANGED
@@ -4,9 +4,13 @@ $LOAD_PATH.uniq!
4
4
 
5
5
  require 'rubygems'
6
6
 
7
- gem 'flexmock', '~> 0.8.11'
7
+ release_ops_path = File.expand_path('../../releaseops/lib', __FILE__)
8
+
9
+ if File.exists?(release_ops_path)
10
+ require File.join(release_ops_path, 'releaseops')
11
+ ReleaseOps::SimpleCov.maybe_start
12
+ end
8
13
 
9
- require 'flexmock'
10
14
  require 'zookeeper'
11
15
 
12
16
  Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }
@@ -26,94 +30,28 @@ if ENV['ZKRB_NOLOG']
26
30
  end
27
31
 
28
32
 
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
33
+ RSpec.configure do |config|
34
+ config.mock_with :rspec
35
+ config.include ZookeeperSpecHeleprs
36
+ config.extend ZookeeperSpecHeleprs
52
37
 
53
- wait_until do
54
- begin
55
- !z.connected?
56
- rescue RuntimeError
57
- true
58
- end
59
- end
60
- end
61
- end
62
- end
38
+ if Zookeeper.spawn_zookeeper?
39
+ require 'zk-server'
63
40
 
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}"
41
+ config.before(:suite) do
42
+ Zookeeper.logger.debug { "Starting zookeeper service" }
43
+ ZK::Server.run do |c|
44
+ c.base_dir = File.expand_path('../../.zkserver', __FILE__)
45
+ c.client_port = Zookeeper.test_port
46
+ c.force_sync = false
47
+ c.snap_count = 1_000_000
76
48
  end
77
49
  end
78
50
 
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
51
+ config.after(:suite) do
52
+ Zookeeper.logger.debug { "stopping zookeeper service" }
53
+ ZK::Server.shutdown
109
54
  end
110
55
  end
111
56
  end
112
57
 
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,20 @@
1
+ module Zookeeper
2
+ def self.spawn_zookeeper?
3
+ !!ENV['SPAWN_ZOOKEEPER']
4
+ end
5
+
6
+ def self.travis?
7
+ !!ENV['TRAVIS']
8
+ end
9
+
10
+ @test_port ||= spawn_zookeeper? ? 21811 : 2181
11
+
12
+ class << self
13
+ attr_accessor :test_port
14
+ end
15
+
16
+ def self.default_cnx_str
17
+ "localhost:#{test_port}"
18
+ end
19
+ end
20
+
@@ -0,0 +1,84 @@
1
+ module ZookeeperSpecHeleprs
2
+ class TimeoutError < StandardError; end
3
+
4
+ def logger
5
+ Zookeeper.logger
6
+ end
7
+
8
+ def ensure_node(zk, path, data)
9
+ return if zk.closed?
10
+ if zk.stat(:path => path)[:stat].exists?
11
+ zk.set(:path => path, :data => data)
12
+ else
13
+ zk.create(:path => path, :data => data)
14
+ end
15
+ end
16
+
17
+ def with_open_zk(host=nil)
18
+ z = Zookeeper.new(Zookeeper.default_cnx_str)
19
+ yield z
20
+ ensure
21
+ if z
22
+ unless z.closed?
23
+ z.close
24
+
25
+ wait_until do
26
+ begin
27
+ !z.connected?
28
+ rescue RuntimeError
29
+ true
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # this is not as safe as the one in ZK, just to be used to clean up
37
+ # when we're the only one adjusting a particular path
38
+ def rm_rf(z, path)
39
+ z.get_children(:path => path).tap do |h|
40
+ if h[:rc].zero?
41
+ h[:children].each do |child|
42
+ rm_rf(z, File.join(path, child))
43
+ end
44
+ elsif h[:rc] == Zookeeper::Exceptions::ZNONODE
45
+ # no-op
46
+ else
47
+ raise "Oh noes! unexpected return value! #{h.inspect}"
48
+ end
49
+ end
50
+
51
+ rv = z.delete(:path => path)
52
+
53
+ unless (rv[:rc].zero? or rv[:rc] == Zookeeper::Exceptions::ZNONODE)
54
+ raise "oh noes! failed to delete #{path}"
55
+ end
56
+
57
+ path
58
+ end
59
+
60
+
61
+ # method to wait until block passed returns true or timeout (default is 10 seconds) is reached
62
+ # raises TiemoutError on timeout
63
+ def wait_until(timeout=10)
64
+ time_to_stop = Time.now + timeout
65
+ while true
66
+ rval = yield
67
+ return rval if rval
68
+ raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
69
+ Thread.pass
70
+ end
71
+ end
72
+
73
+ # inverse of wait_until
74
+ def wait_while(timeout=10)
75
+ time_to_stop = Time.now + timeout
76
+ while true
77
+ rval = yield
78
+ return rval unless rval
79
+ raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
80
+ Thread.pass
81
+ end
82
+ end
83
+ end
84
+
@@ -5,7 +5,7 @@ require 'shared/connection_examples'
5
5
  describe 'Zookeeper' do
6
6
  let(:path) { "/_zktest_" }
7
7
  let(:data) { "underpants" }
8
- let(:connection_string) { 'localhost:2181' }
8
+ let(:connection_string) { Zookeeper.default_cnx_str }
9
9
 
10
10
  before do
11
11
  @zk = Zookeeper.new(connection_string)
data/zookeeper.gemspec CHANGED
@@ -3,28 +3,25 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require 'zookeeper/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = ENV.fetch('ZOOKEEPER_GEM_NAME', 'zookeeper')
7
- s.version = ZookeeperVersion::VERSION
6
+ s.name = 'zookeeper'
7
+ s.version = Zookeeper::VERSION
8
8
 
9
9
  s.authors = ["Phillip Pearson", "Eric Maland", "Evan Weaver", "Brian Wickman", "Neil Conway", "Jonathan D. Simms"]
10
10
  s.email = ["slyphon@gmail.com"]
11
- s.summary = %q{Low level zookeeper client}
11
+ s.summary = %q{Apache ZooKeeper driver for Rubies}
12
12
  s.description = <<-EOS
13
- A low-level multi-Ruby wrapper around the ZooKeeper API bindings.
14
- For a friendlier interface, see http://github.com/slyphon/zk
13
+ A low-level multi-Ruby wrapper around the ZooKeeper API bindings. For a
14
+ friendlier interface, see http://github.com/slyphon/zk. Currently supported:
15
+ MRI: {1.8.7, 1.9.2, 1.9.3}, JRuby: ~> 1.6.7, Rubinius: 2.0.testing, REE 1.8.7.
15
16
 
16
- Currently supported:
17
-
18
- MRI: 1.8.7, 1.9.2, 1.9.3
19
- JRuby: ~> 1.6.7
20
- Rubinius: 2.0.testing
21
-
22
- This library uses version #{ZookeeperVersion::DRIVER_VERSION} of zookeeper bindings.
17
+ This library uses version #{Zookeeper::DRIVER_VERSION} of zookeeper bindings.
23
18
 
24
19
  EOS
25
20
 
26
21
  s.homepage = 'https://github.com/slyphon/zookeeper'
27
22
 
23
+ s.add_runtime_dependency 'backports', '~> 2.5.1'
24
+
28
25
  s.files = `git ls-files`.split("\n")
29
26
  s.require_paths = ["lib"]
30
27