zookeeper-ng 1.5.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.ctags_paths +1 -0
  3. data/.dotfiles/ruby-gemset +1 -0
  4. data/.dotfiles/ruby-version +1 -0
  5. data/.dotfiles/rvmrc +2 -0
  6. data/.github/workflows/build.yml +57 -0
  7. data/.gitignore +19 -0
  8. data/.gitmodules +3 -0
  9. data/CHANGELOG +408 -0
  10. data/Gemfile +30 -0
  11. data/Guardfile +8 -0
  12. data/LICENSE +23 -0
  13. data/Manifest +29 -0
  14. data/README.markdown +62 -0
  15. data/Rakefile +121 -0
  16. data/cause-abort.rb +117 -0
  17. data/ext/.gitignore +6 -0
  18. data/ext/Rakefile +41 -0
  19. data/ext/c_zookeeper.rb +398 -0
  20. data/ext/common.h +17 -0
  21. data/ext/dbg.h +53 -0
  22. data/ext/depend +5 -0
  23. data/ext/event_lib.c +740 -0
  24. data/ext/event_lib.h +175 -0
  25. data/ext/extconf.rb +103 -0
  26. data/ext/generate_gvl_code.rb +321 -0
  27. data/ext/patches/zkc-3.3.5-network.patch +24 -0
  28. data/ext/patches/zkc-3.4.5-buffer-overflow.patch +11 -0
  29. data/ext/patches/zkc-3.4.5-config.patch +5454 -0
  30. data/ext/patches/zkc-3.4.5-fetch-and-add.patch +16 -0
  31. data/ext/patches/zkc-3.4.5-logging.patch +41 -0
  32. data/ext/patches/zkc-3.4.5-out-of-order-ping.patch +163 -0
  33. data/ext/patches/zkc-3.4.5-yosemite-htonl-fix.patch +102 -0
  34. data/ext/zkc-3.4.5.tar.gz +0 -0
  35. data/ext/zkrb.c +1080 -0
  36. data/ext/zkrb_wrapper.c +775 -0
  37. data/ext/zkrb_wrapper.h +350 -0
  38. data/ext/zkrb_wrapper_compat.c +15 -0
  39. data/ext/zkrb_wrapper_compat.h +11 -0
  40. data/ext/zookeeper_base.rb +256 -0
  41. data/java/java_base.rb +501 -0
  42. data/lib/zookeeper/acls.rb +44 -0
  43. data/lib/zookeeper/callbacks.rb +108 -0
  44. data/lib/zookeeper/client.rb +30 -0
  45. data/lib/zookeeper/client_methods.rb +282 -0
  46. data/lib/zookeeper/common/queue_with_pipe.rb +110 -0
  47. data/lib/zookeeper/common.rb +122 -0
  48. data/lib/zookeeper/compatibility.rb +138 -0
  49. data/lib/zookeeper/constants.rb +97 -0
  50. data/lib/zookeeper/continuation.rb +223 -0
  51. data/lib/zookeeper/core_ext.rb +58 -0
  52. data/lib/zookeeper/em_client.rb +55 -0
  53. data/lib/zookeeper/exceptions.rb +135 -0
  54. data/lib/zookeeper/forked.rb +19 -0
  55. data/lib/zookeeper/latch.rb +34 -0
  56. data/lib/zookeeper/logger/forwarding_logger.rb +84 -0
  57. data/lib/zookeeper/logger.rb +39 -0
  58. data/lib/zookeeper/monitor.rb +19 -0
  59. data/lib/zookeeper/rake_tasks.rb +165 -0
  60. data/lib/zookeeper/request_registry.rb +153 -0
  61. data/lib/zookeeper/stat.rb +21 -0
  62. data/lib/zookeeper/version.rb +4 -0
  63. data/lib/zookeeper.rb +115 -0
  64. data/notes.txt +14 -0
  65. data/scripts/upgrade-1.0-sed-alike.rb +46 -0
  66. data/spec/c_zookeeper_spec.rb +51 -0
  67. data/spec/chrooted_connection_spec.rb +83 -0
  68. data/spec/compatibilty_spec.rb +8 -0
  69. data/spec/default_watcher_spec.rb +41 -0
  70. data/spec/em_spec.rb +51 -0
  71. data/spec/ext/zookeeper_base_spec.rb +19 -0
  72. data/spec/forked_connection_spec.rb +122 -0
  73. data/spec/latch_spec.rb +24 -0
  74. data/spec/log4j.properties +17 -0
  75. data/spec/shared/all_success_return_values.rb +10 -0
  76. data/spec/shared/connection_examples.rb +1081 -0
  77. data/spec/spec_helper.rb +61 -0
  78. data/spec/support/00_logging.rb +38 -0
  79. data/spec/support/10_spawn_zookeeper.rb +20 -0
  80. data/spec/support/progress_formatter.rb +15 -0
  81. data/spec/support/zookeeper_spec_helpers.rb +96 -0
  82. data/spec/zookeeper_spec.rb +24 -0
  83. data/zookeeper.gemspec +46 -0
  84. data/zoomonkey/duplicates +3 -0
  85. data/zoomonkey/zoomonkey.rb +194 -0
  86. metadata +185 -0
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'shared/connection_examples'
3
+
4
+ describe 'Zookeeper chrooted' do
5
+ let(:path) { "/_zkchroottest_" }
6
+ let(:data) { "underpants" }
7
+ let(:chroot_path) { '/slyphon-zookeeper-chroot' }
8
+
9
+ let(:connection_string) { "#{Zookeeper.default_cnx_str}#{chroot_path}" }
10
+
11
+ before do
12
+ @zk = Zookeeper.new(connection_string)
13
+ end
14
+
15
+ after do
16
+ @zk and @zk.close
17
+ end
18
+
19
+ def zk
20
+ @zk
21
+ end
22
+
23
+ describe 'non-existent' do
24
+ describe 'with existing parent' do
25
+ let(:chroot_path) { '/one-level' }
26
+
27
+ describe 'create' do
28
+ before do
29
+ with_open_zk { |z| rm_rf(z, chroot_path) }
30
+ end
31
+
32
+ after do
33
+ with_open_zk { |z| rm_rf(z, chroot_path) }
34
+ end
35
+
36
+ it %[should successfully create the path] do
37
+ rv = zk.create(:path => '/', :data => '')
38
+ rv[:rc].should be_zero
39
+ rv[:path].should == ''
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'with missing parent' do
45
+ let(:chroot_path) { '/deeply/nested/path' }
46
+
47
+ describe 'create' do
48
+ before do
49
+ with_open_zk do |z|
50
+ rm_rf(z, chroot_path)
51
+ end
52
+ end
53
+
54
+ it %[should return ZNONODE] do
55
+ rv = zk.create(:path => '/', :data => '')
56
+ rv[:rc].should_not be_zero
57
+ rv[:rc].should == Zookeeper::Exceptions::ZNONODE
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ describe do
65
+ before :all do
66
+ logger.warn "running before :all"
67
+
68
+ with_open_zk do |z|
69
+ z.create(:path => chroot_path, :data => '')
70
+ end
71
+ end
72
+
73
+ after :all do
74
+ with_open_zk do |z|
75
+ rm_rf(z, chroot_path)
76
+ end
77
+ end
78
+
79
+ it_should_behave_like "connection"
80
+ end
81
+ end
82
+
83
+
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Compatibiliy layer' do
4
+ it %[should raise the correct error when a const is missing] do
5
+ lambda { Zookeeper::THISISANINVALIDCONST }.should raise_error(NameError)
6
+ end
7
+ end
8
+
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zookeeper do
4
+ describe :initialize, 'with watcher block' do
5
+ before do
6
+ @events = []
7
+ @watch_block = lambda do |hash|
8
+ logger.debug "watch_block: #{hash.inspect}"
9
+ @events << hash
10
+ end
11
+
12
+ @zk = Zookeeper.new(Zookeeper.default_cnx_str, 10, @watch_block)
13
+
14
+ wait_until(2) { @zk.connected? }
15
+ @zk.should be_connected
16
+ logger.debug "connected!"
17
+
18
+ wait_until(2) { !@events.empty? }
19
+ logger.debug "got events!"
20
+ end
21
+
22
+ after do
23
+ @zk.close if @zk.connected?
24
+ end
25
+
26
+ it %[should receive initial connection state events] do
27
+ @events.should_not be_empty
28
+ @events.length.should == 1
29
+ @events.first[:state].should == Zookeeper::ZOO_CONNECTED_STATE
30
+ end
31
+
32
+ it %[should receive disconnection events] do
33
+ pending "the C driver doesn't appear to deliver disconnection events (?)"
34
+ @events.clear
35
+ @zk.close
36
+ wait_until(2) { !@events.empty? }
37
+ @events.should_not be_empty
38
+ end
39
+ end
40
+ end
41
+
data/spec/em_spec.rb ADDED
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'zookeeper/em_client'
3
+
4
+ gem 'evented-spec', '~> 0.9.0'
5
+ require 'evented-spec'
6
+
7
+
8
+ describe 'ZookeeperEM' do
9
+ describe 'Client' do
10
+ include EventedSpec::SpecHelper
11
+ default_timeout 3.0
12
+
13
+ def setup_zk
14
+ @zk = ZookeeperEM::Client.new(Zookeeper.default_cnx_str)
15
+ em do
16
+ @zk.on_attached do
17
+ yield
18
+ end
19
+ end
20
+ end
21
+
22
+ def teardown_and_done
23
+ @zk.close do
24
+ logger.debug { "TEST: about to call done" }
25
+ EM.next_tick do
26
+ done
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'callbacks' do
32
+ it %[should be called on the reactor thread] do
33
+ cb = lambda do |h|
34
+ EM.reactor_thread?.should be_true
35
+ logger.debug { "called back on the reactor thread? #{EM.reactor_thread?}" }
36
+ teardown_and_done
37
+ end
38
+
39
+ setup_zk do
40
+ @zk.on_attached do |*|
41
+ logger.debug { "on_attached called" }
42
+ rv = @zk.get(:path => '/', :callback => cb)
43
+ logger.debug { "rv from @zk.get: #{rv.inspect}" }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ unless defined?(::JRUBY_VERSION)
4
+ describe Zookeeper::ZookeeperBase do
5
+ before do
6
+ @zk = described_class.new(Zookeeper.default_cnx_str)
7
+ end
8
+
9
+ after do
10
+ @zk.close unless @zk.closed?
11
+ end
12
+
13
+ it %[should have an original_pid assigned] do
14
+ @zk.original_pid.should == Process.pid
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ unless defined?(::JRUBY_VERSION)
4
+ describe %[forked connection] do
5
+ let(:path) { "/_zktest_" }
6
+ let(:pids_root) { "#{path}/pids" }
7
+ let(:data) { "underpants" }
8
+ let(:connection_string) { Zookeeper.default_cnx_str }
9
+
10
+ def process_alive?(pid)
11
+ Process.kill(0, @pid)
12
+ true
13
+ rescue Errno::ESRCH
14
+ false
15
+ end
16
+
17
+ LBORDER = ('-' * 35) << '< '
18
+ RBORDER = ' >' << ('-' * 35)
19
+
20
+ def mark(thing)
21
+ logger << "\n#{LBORDER}#{thing}#{RBORDER}\n\n"
22
+ end
23
+
24
+ before do
25
+ mark "BEFORE: START"
26
+ if defined?(::Rubinius)
27
+ pending("this test is currently broken in rbx")
28
+ else
29
+ @zk = Zookeeper.new(connection_string)
30
+ rm_rf(@zk, path)
31
+ end
32
+ mark "BEFORE: END"
33
+ end
34
+
35
+ after do
36
+ mark "AFTER: START"
37
+
38
+ if @pid and process_alive?(@pid)
39
+ begin
40
+ Process.kill('KILL', @pid)
41
+ p Process.wait2(@pid)
42
+ rescue Errno::ESRCH
43
+ end
44
+ end
45
+
46
+ @zk.close if @zk and !@zk.closed?
47
+ with_open_zk(connection_string) { |z| rm_rf(z, path) }
48
+
49
+ mark "AFTER: END"
50
+ end
51
+
52
+ def wait_for_child_safely(pid, timeout=5)
53
+ time_to_stop = Time.now + timeout
54
+
55
+ until Time.now > time_to_stop
56
+ if a = Process.wait2(@pid, Process::WNOHANG)
57
+ return a.last
58
+ else
59
+ sleep(0.01)
60
+ end
61
+ end
62
+
63
+ nil
64
+ end
65
+
66
+ it %[should do the right thing and not fail] do
67
+ mark "TEST: START"
68
+
69
+ @zk.wait_until_connected
70
+
71
+ mkdir_p(@zk, pids_root)
72
+
73
+ # the parent's pid path
74
+ @zk.create(:path => "#{pids_root}/#{$$}", :data => $$.to_s)
75
+
76
+ @latch = Zookeeper::Latch.new
77
+ @event = nil
78
+
79
+ cb = proc do |h|
80
+ logger.debug { "watcher called back: #{h.inspect}" }
81
+ @event = h
82
+ @latch.release
83
+ end
84
+
85
+ @zk.stat(:path => "#{pids_root}/child", :watcher => cb)
86
+
87
+ @zk.pause_before_fork_in_parent
88
+
89
+ mark "FORK"
90
+
91
+ @pid = fork do
92
+ logger.debug { "reopening connection in child: #{$$}" }
93
+ @zk.reopen
94
+ logger.debug { "creating path" }
95
+ rv = @zk.create(:path => "#{pids_root}/child", :data => $$.to_s)
96
+ logger.debug { "created path #{rv[:path]}" }
97
+ @zk.close
98
+
99
+ logger.debug { "close finished" }
100
+ exit!(0)
101
+ end
102
+
103
+ @zk.resume_after_fork_in_parent
104
+
105
+ event_waiter_th = Thread.new do
106
+ @latch.await(5) unless @event
107
+ @event
108
+ end
109
+
110
+ logger.debug { "waiting on child #{@pid}" }
111
+
112
+ status = wait_for_child_safely(@pid)
113
+ raise "Child process did not exit, likely hung" unless status
114
+
115
+ status.should_not be_signaled
116
+ status.should be_success
117
+
118
+ event_waiter_th.join(5).should == event_waiter_th
119
+ @event.should_not be_nil
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ # this is a simple sanity check of my timeout addition
4
+
5
+ describe Zookeeper::Latch do
6
+ subject { described_class.new }
7
+
8
+ describe %[await] do
9
+ describe %[with timeout] do
10
+ it %[should return after waiting until timeout if not released] do
11
+ other_latch = described_class.new
12
+
13
+ th = Thread.new do
14
+ subject.await(0.01)
15
+ other_latch.release
16
+ end
17
+
18
+ other_latch.await
19
+ th.join(1).should == th
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,17 @@
1
+ log4j.rootLogger = DEBUG,S
2
+
3
+ log4j.appender.S = org.apache.log4j.FileAppender
4
+ log4j.appender.S.File = /tmp/zk-test.log
5
+
6
+ log4j.appender.S.layout = org.apache.log4j.PatternLayout
7
+ log4j.appender.S.layout.ConversionPattern = %5p [%t] (%c:%F:%L) - %m%n
8
+
9
+ log4j.appender.C = org.apache.log4j.FileAppender
10
+ log4j.appender.C.File = /tmp/zk-test-client.log
11
+
12
+ log4j.appender.C.layout = org.apache.log4j.PatternLayout
13
+ log4j.appender.C.layout.ConversionPattern = %5p [%t] (%c:%F:%L) - %m%n
14
+
15
+ log4j.org.apache.zookeeper.ZooKeeper = DEBUG,C
16
+ log4j.org.apache.zookeeper.server = DEBUG,S
17
+
@@ -0,0 +1,10 @@
1
+ shared_examples_for "all success return values" do
2
+ it %[should have a return code of Zookeeper::ZOK] do
3
+ @rv[:rc].should == Zookeeper::ZOK
4
+ end
5
+
6
+ it %[should have a req_id integer] do
7
+ @rv[:req_id].should be_kind_of(Integer)
8
+ end
9
+ end
10
+