zookeeper 1.4.4 → 1.4.6

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.
@@ -26,11 +26,11 @@ module ACLs
26
26
  end
27
27
 
28
28
  module Constants
29
- ZOO_PERM_READ = 0
30
- ZOO_PERM_WRITE = 1
31
- ZOO_PERM_CREATE = 2
32
- ZOO_PERM_DELETE = 4
33
- ZOO_PERM_ADMIN = 8
29
+ ZOO_PERM_READ = 1 << 0
30
+ ZOO_PERM_WRITE = 1 << 1
31
+ ZOO_PERM_CREATE = 1 << 2
32
+ ZOO_PERM_DELETE = 1 << 3
33
+ ZOO_PERM_ADMIN = 1 << 4
34
34
  ZOO_PERM_ALL = ZOO_PERM_READ | ZOO_PERM_WRITE | ZOO_PERM_CREATE | ZOO_PERM_DELETE | ZOO_PERM_ADMIN
35
35
 
36
36
  ZOO_ANYONE_ID_UNSAFE = Id.new(:scheme => "world", :id => "anyone")
@@ -9,12 +9,12 @@ module ClientMethods
9
9
  def_delegators :@req_registry, :setup_call
10
10
  private :setup_call
11
11
 
12
- def reopen(timeout=10, watcher=nil)
12
+ def reopen(timeout=10, watcher=nil, opts = {})
13
13
  warn "WARN: ZookeeperBase#reopen watcher argument is now ignored" if watcher
14
14
  super
15
15
  end
16
16
 
17
- def initialize(host, timeout=10, watcher=nil)
17
+ def initialize(host, timeout=10, watcher=nil, opts = {})
18
18
  super
19
19
  end
20
20
 
@@ -1,4 +1,4 @@
1
1
  module Zookeeper
2
- VERSION = '1.4.4'
3
- DRIVER_VERSION = '3.3.5'
2
+ VERSION = '1.4.6'
3
+ DRIVER_VERSION = '3.4.5'
4
4
  end
@@ -441,6 +441,35 @@ shared_examples_for "connection" do
441
441
  end
442
442
  end
443
443
 
444
+ describe :child_watcher_behavior do
445
+ describe :async_watch, :async => true do
446
+ it_should_behave_like "all success return values"
447
+
448
+ before do
449
+ @watcher = Zookeeper::Callbacks::WatcherCallback.new
450
+ @cb = Zookeeper::Callbacks::StringsCallback.new
451
+
452
+ @rv = zk.get_children(:path => path, :watcher => @watcher, :watcher_context => path, :callback => @cb, :callback_context => path)
453
+ wait_until { @cb.completed? }
454
+ @cb.should be_completed
455
+ end
456
+
457
+ it %[should fire the watcher when the node has been deleted] do
458
+ @watcher.should_not be_completed
459
+
460
+ zk.delete(:path => path)[:rc].should == Zookeeper::ZOK
461
+
462
+ wait_until { @watcher.completed? }
463
+ @watcher.should be_completed
464
+
465
+ @watcher.path.should == path
466
+ @watcher.context.should == path
467
+ @watcher.type.should == Zookeeper::ZOO_DELETED_EVENT
468
+ end
469
+ end
470
+ end
471
+
472
+
444
473
  # NOTE: the jruby version of stat on non-existent node will have a
445
474
  # return_code of 0, but the C version will have a return_code of -101
446
475
  describe :stat do
@@ -5,7 +5,7 @@ module RSpec
5
5
  module Formatters
6
6
  class ProgressFormatter
7
7
  def example_started(example)
8
- SpecGlobalLogger.logger << yellow("\n=====<([ #{example.full_description} ])>=====\n")
8
+ SpecGlobalLogger.logger << pending_color("\n=====<([ #{example.full_description} ])>=====\n")
9
9
  super(example)
10
10
  end
11
11
  end
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ awk '{ if (prev == $0) count++; else { if (count > 0) { print " --- Line repeated " count " times --- " } print; prev = $0; count = 0 } }' $*
@@ -0,0 +1,194 @@
1
+ require 'zookeeper'
2
+ require 'zk-server'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ SLEEP_TIME = 30
7
+ STDOUT.sync = true
8
+
9
+ if ENV['DEBUG']
10
+ def zookeeper_logger(from)
11
+ l = Logger.new(STDOUT)
12
+ l.formatter = proc do |sev, time, c, msg|
13
+ "t=#{time.to_i} from=#{from} level=#{sev.downcase} message=#{msg.inspect}\n"
14
+ end
15
+ l
16
+ end
17
+
18
+ Zookeeper.logger = zookeeper_logger('zookeeper')
19
+ Zookeeper.set_debug_level(Zookeeper::ZOO_LOG_LEVEL_DEBUG)
20
+ end
21
+
22
+ class Worker
23
+ def initialize(body = nil, &block)
24
+ raise ArgumentError, "Cannot include both body and block" if body && block
25
+ @body = body || block
26
+ end
27
+
28
+ def body
29
+ @body || method(:call)
30
+ end
31
+
32
+ def start
33
+ @thread = Thread.new do
34
+ Thread.current.abort_on_exception = true
35
+ body.call
36
+ end
37
+ end
38
+
39
+ def stop
40
+ if @thread
41
+ @thread.kill
42
+ @thread = nil
43
+ end
44
+ end
45
+
46
+ def join
47
+ if @thread
48
+ @thread.join
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+ base_dir = Dir.mktmpdir('zk-server-cluster')
56
+ num_cluster = 3
57
+ cluster = ZK::Server::Cluster.new(num_cluster, :base_dir => base_dir)
58
+
59
+ class Reader < Worker
60
+ attr_reader :client
61
+
62
+ def initialize(zookeeper_hosts)
63
+ @zookeeper_hosts = zookeeper_hosts
64
+ @log_from = :reader
65
+ end
66
+
67
+ def call
68
+ @client = Zookeeper.new(@zookeeper_hosts, 10, method(:watcher))
69
+ client.wait_until_connected
70
+
71
+ client.create(:path => "/test", :data => '') rescue client.set(:path => "/test", :data => '')
72
+
73
+ while true
74
+ error = nil
75
+ t = Benchmark.realtime do
76
+ begin
77
+ client.get(:path => "/test")
78
+ rescue => e
79
+ error = e
80
+ end
81
+ end
82
+
83
+ msg = "host=#{client.connected_host || 'nil'} session_id=#{client.session_id} state=#{client.state_by_value(client.state)} time=#{"%0.4f" % t}"
84
+ if error
85
+ msg << " error=#{error.class} error_message=#{error.to_s.inspect}"
86
+ msg << " closed=#{client.closed?} running=#{client.running?} shutting_down=#{client.shutting_down?}"
87
+ end
88
+
89
+ log msg
90
+
91
+ sleep 1
92
+ end
93
+ end
94
+
95
+ def log(message)
96
+ puts "t=#{Time.now.to_i} from=#{@log_from} #{message}\n"
97
+ end
98
+
99
+ def watcher(event)
100
+ if event[:state] == Zookeeper::ZOO_EXPIRED_SESSION_STATE
101
+ if client
102
+ log "action=reconnecting state=#{client.state_by_value(event[:state])} session_id=#{client.session_id}"
103
+ client.reopen
104
+ end
105
+ end
106
+
107
+ end
108
+ end
109
+
110
+ class Writer < Worker
111
+ def initialize(zookeeper_hosts)
112
+ @zookeeper_hosts = zookeeper_hosts
113
+ @log_from = :writer
114
+ end
115
+
116
+ def call
117
+ client = Zookeeper.new(@zookeeper_hosts)
118
+ client.wait_until_connected
119
+
120
+ while true
121
+ error = nil
122
+ t = Benchmark.realtime do
123
+ begin
124
+ client.create(:path => "/test", :data => '') rescue client.set(:path => "/test", :data => '')
125
+ rescue => e
126
+ error = e
127
+ end
128
+ end
129
+
130
+ msg = "host=#{client.connected_host || 'nil'} session_id=#{client.session_id} state=#{client.state_by_value(client.state)} time=#{"%0.4f" % t}"
131
+ msg << " error=#{error.class} error_message=#{error.to_s.inspect}" if error
132
+ log msg
133
+
134
+ sleep 1
135
+ end
136
+ end
137
+
138
+ def log(message)
139
+ puts "t=#{Time.now.to_i} from=#{@log_from} #{message}\n"
140
+ end
141
+ end
142
+
143
+ class ZooMonkey < Worker
144
+ attr_reader :cluster
145
+
146
+ def initialize(cluster)
147
+ @cluster = cluster
148
+ @log_from = :server
149
+ end
150
+
151
+ def call
152
+ while true
153
+ sleep SLEEP_TIME
154
+
155
+ cluster.processes.each do |server|
156
+ host = "127.0.0.1:#{server.client_port}"
157
+ log "host=#{host} pid=#{server.pid} action=pausing"
158
+ server.kill "STOP"
159
+ sleep SLEEP_TIME
160
+
161
+ log "host=#{host} pid=#{server.pid} action=resuming"
162
+ server.kill "CONT"
163
+ sleep SLEEP_TIME
164
+ end
165
+ end
166
+ end
167
+
168
+ def log(message)
169
+ puts "t=#{Time.now.to_i} from=#{@log_from} #{message}\n"
170
+ end
171
+ end
172
+
173
+ begin
174
+ cluster.run
175
+
176
+ zookeeper_hosts = cluster.processes.map { |p| "127.0.0.1:#{p.client_port}" }
177
+ zookeeper_spec = (zookeeper_hosts * 2).join(',')
178
+
179
+ reader = Reader.new(zookeeper_spec)
180
+ reader.start
181
+
182
+ # writer = Writer.new(zookeeper_spec)
183
+ # writer.start
184
+
185
+ monkey = ZooMonkey.new(cluster)
186
+ monkey.start
187
+
188
+ reader.join
189
+ writer.join
190
+ monkey.join
191
+ ensure
192
+ cluster.clobber!
193
+ FileUtils.remove_entry(base_dir)
194
+ end
metadata CHANGED
@@ -1,15 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zookeeper
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.6
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 4
9
- - 4
10
- version: 1.4.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Phillip Pearson
14
9
  - Eric Maland
15
10
  - Evan Weaver
@@ -19,27 +14,30 @@ authors:
19
14
  autorequire:
20
15
  bindir: bin
21
16
  cert_chain: []
22
-
23
- date: 2013-04-27 00:00:00 Z
17
+ date: 2013-09-09 00:00:00.000000000 Z
24
18
  dependencies: []
19
+ description: ! 'A low-level multi-Ruby wrapper around the ZooKeeper API bindings.
20
+ For a
25
21
 
26
- description: |+
27
- A low-level multi-Ruby wrapper around the ZooKeeper API bindings. For a
28
22
  friendlier interface, see http://github.com/slyphon/zk. Currently supported:
23
+
29
24
  MRI: {1.8.7, 1.9.2, 1.9.3}, JRuby: ~> 1.6.7, Rubinius: 2.0.testing, REE 1.8.7.
30
-
31
- This library uses version 3.3.5 of zookeeper bindings.
32
-
33
- email:
25
+
26
+
27
+ This library uses version 3.4.5 of zookeeper bindings.
28
+
29
+
30
+ '
31
+ email:
34
32
  - slyphon@gmail.com
35
33
  executables: []
36
-
37
- extensions:
34
+ extensions:
38
35
  - ext/extconf.rb
39
36
  extra_rdoc_files: []
40
-
41
- files:
37
+ files:
42
38
  - .ctags_paths
39
+ - .dotfiles/ruby-gemset
40
+ - .dotfiles/ruby-version
43
41
  - .dotfiles/rvmrc
44
42
  - .gitignore
45
43
  - .gitmodules
@@ -62,8 +60,9 @@ files:
62
60
  - ext/event_lib.h
63
61
  - ext/extconf.rb
64
62
  - ext/generate_gvl_code.rb
65
- - ext/patch-zookeeper
66
- - ext/zkc-3.3.5.tar.gz
63
+ - ext/patches/zkc-3.3.5-network.patch
64
+ - ext/patches/zkc-3.4.5-logging.patch
65
+ - ext/zkc-3.4.5.tar.gz
67
66
  - ext/zkrb.c
68
67
  - ext/zkrb_wrapper.c
69
68
  - ext/zkrb_wrapper.h
@@ -113,41 +112,34 @@ files:
113
112
  - spec/support/zookeeper_spec_helpers.rb
114
113
  - spec/zookeeper_spec.rb
115
114
  - zookeeper.gemspec
115
+ - zoomonkey/duplicates
116
+ - zoomonkey/zoomonkey.rb
116
117
  homepage: https://github.com/slyphon/zookeeper
117
118
  licenses: []
118
-
119
119
  post_install_message:
120
120
  rdoc_options: []
121
-
122
- require_paths:
121
+ require_paths:
123
122
  - lib
124
123
  - ext
125
- required_ruby_version: !ruby/object:Gem::Requirement
124
+ required_ruby_version: !ruby/object:Gem::Requirement
126
125
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
134
- required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
131
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
- version: "0"
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
143
136
  requirements: []
144
-
145
137
  rubyforge_project:
146
138
  rubygems_version: 1.8.25
147
139
  signing_key:
148
140
  specification_version: 3
149
141
  summary: Apache ZooKeeper driver for Rubies
150
- test_files:
142
+ test_files:
151
143
  - spec/c_zookeeper_spec.rb
152
144
  - spec/chrooted_connection_spec.rb
153
145
  - spec/compatibilty_spec.rb
@@ -165,3 +157,4 @@ test_files:
165
157
  - spec/support/progress_formatter.rb
166
158
  - spec/support/zookeeper_spec_helpers.rb
167
159
  - spec/zookeeper_spec.rb
160
+ has_rdoc:
data/ext/zkc-3.3.5.tar.gz DELETED
Binary file