zk-eventmachine 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/Rakefile +29 -44
- data/lib/z_k/z_k_event_machine/client.rb +38 -0
- data/lib/z_k/z_k_event_machine/version.rb +1 -1
- data/spec/support/logging.rb +1 -1
- data/spec/z_k/z_k_event_machine/client_spec.rb +42 -13
- data/spec/z_k/z_k_event_machine/event_handler_e_m_spec.rb +1 -1
- data/zk-eventmachine.gemspec +2 -2
- metadata +15 -14
data/.gitmodules
ADDED
data/Rakefile
CHANGED
@@ -1,62 +1,47 @@
|
|
1
|
-
|
2
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
gemset_name = 'zk-em'
|
3
2
|
|
4
|
-
|
5
|
-
Bundler.setup
|
6
|
-
require 'yard'
|
3
|
+
release_ops_path = File.expand_path('../releaseops/lib', __FILE__)
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
# if the special submodule is availabe, use it
|
6
|
+
# we use a submodule because it doesn't depend on anything else (*cough* bundler)
|
7
|
+
# and can be shared across projects
|
8
|
+
#
|
9
|
+
if File.exists?(release_ops_path)
|
10
|
+
require File.join(release_ops_path, 'releaseops')
|
11
|
+
|
12
|
+
# sets up the multi-ruby zk:test_all rake tasks
|
13
|
+
ReleaseOps::TestTasks.define_for(*%w[1.8.7 1.9.2 jruby ree 1.9.3])
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
# sets up the task :default => 'spec:run' and defines a simple
|
16
|
+
# "run the specs with the current rvm profile" task
|
17
|
+
ReleaseOps::TestTasks.define_simple_default_for_travis
|
14
18
|
|
15
|
-
|
19
|
+
# Define a task to run code coverage tests
|
20
|
+
ReleaseOps::TestTasks.define_simplecov_tasks
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
# set up yard:server, yard:gems, and yard:clean tasks
|
23
|
+
# for doing documentation stuff
|
24
|
+
ReleaseOps::YardTasks.define
|
19
25
|
|
20
|
-
|
21
|
-
|
22
|
-
bundle_task_name = "mb:#{ns_name}:bundle_install"
|
23
|
-
rspec_task_name = "mb:#{ns_name}:run_rspec"
|
24
|
-
|
25
|
-
phony_gemfile_link_name = "Gemfile.#{ns_name}"
|
26
|
-
phony_gemfile_lock_name = "#{phony_gemfile_link_name}.lock"
|
26
|
+
ReleaseOps::GemTasks.define('zk-eventmachine.gemspec')
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
# apparently, rake doesn't deal with symlinks intelligently :P
|
30
|
-
ln_s('Gemfile', phony_gemfile_link_name) unless File.symlink?(phony_gemfile_link_name)
|
31
|
-
end
|
29
|
+
task 'mb:test_all' => 'zk:test_all'
|
32
30
|
|
31
|
+
namespace :yard do
|
33
32
|
task :clean do
|
34
|
-
rm_rf
|
33
|
+
rm_rf '.yardoc'
|
35
34
|
end
|
36
35
|
|
37
|
-
task
|
38
|
-
sh "
|
36
|
+
task :server => :clean do
|
37
|
+
sh "yard server --reload --port=8810"
|
39
38
|
end
|
40
39
|
|
41
|
-
task
|
42
|
-
sh
|
40
|
+
task :gems do
|
41
|
+
sh 'yard server --gems --port=8811'
|
43
42
|
end
|
44
|
-
|
45
|
-
task rspec_task_name => bundle_task_name do
|
46
|
-
sh "rvm #{ruby_with_gemset} do env BUNDLE_GEMFILE=#{phony_gemfile_link_name} bundle exec rspec spec --fail-fast"
|
47
|
-
end
|
48
|
-
|
49
|
-
task "mb:#{ns_name}" => rspec_task_name
|
50
|
-
|
51
|
-
task "mb:test_all_rubies" => rspec_task_name
|
52
43
|
end
|
53
44
|
|
54
|
-
task '
|
55
|
-
require 'benchmark'
|
56
|
-
tm = Benchmark.realtime do
|
57
|
-
Rake::Task['mb:test_all_rubies'].invoke
|
58
|
-
end
|
45
|
+
task :clean => 'yard:clean'
|
59
46
|
|
60
|
-
$stderr.puts "Test run took: #{tm}"
|
61
|
-
end
|
62
47
|
|
@@ -1,5 +1,29 @@
|
|
1
1
|
module ZK
|
2
2
|
module ZKEventMachine
|
3
|
+
# @example use of on_connecting
|
4
|
+
#
|
5
|
+
# def handle_connecting_event(event=nil)
|
6
|
+
#
|
7
|
+
# # this (re-)registers this hook for the next time this event is called
|
8
|
+
# @zkem.on_connecting(&:handle_connecting_event)
|
9
|
+
#
|
10
|
+
# return unless event # nil is the initial registration case
|
11
|
+
#
|
12
|
+
# logger.warn { "Oh no! got a connecting event, taking evasive action!" }
|
13
|
+
#
|
14
|
+
# # do stuff
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# # your setup method would then look like
|
19
|
+
# def run
|
20
|
+
# @zkem.connect do
|
21
|
+
# handle_connecting_event
|
22
|
+
#
|
23
|
+
# do_the_rest_of_your_stuff
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
3
27
|
class Client < ZK::Client::Base
|
4
28
|
include Deferred::Accessors
|
5
29
|
include ZK::Logging
|
@@ -14,6 +38,10 @@ module ZK
|
|
14
38
|
# once this deferred has been fired, it will be replaced with a new
|
15
39
|
# deferred, so callbacks must be re-registered, and *should* be
|
16
40
|
# re-registered *within* the callback to avoid missing events
|
41
|
+
#
|
42
|
+
# @note if you want to be notified when the connection state has not
|
43
|
+
# become *invalid* but you are in a possibly recoverable state, then
|
44
|
+
# you should hook the {#on_connecting} method
|
17
45
|
#
|
18
46
|
# @method on_connection_lost
|
19
47
|
# @return [Deferred::Default]
|
@@ -43,8 +71,18 @@ module ZK
|
|
43
71
|
#
|
44
72
|
# This event is triggered when we have become disconnected from the
|
45
73
|
# cluster and are in the process of reconnecting.
|
74
|
+
#
|
75
|
+
# @note this would more accurately be called `on_disconnection`, but because
|
76
|
+
# it's fired also when the client is starting up, it has the name it does.
|
77
|
+
# there's an alias for this `on_disconnection`. (It's not `on_disconnected`
|
78
|
+
# because the '-ion' seems to indicate that the condition may be temporary)
|
79
|
+
#
|
80
|
+
# @method on_connecting
|
81
|
+
# @return [Deferred::Default]
|
46
82
|
deferred_event :connecting
|
47
83
|
|
84
|
+
alias :on_disconnection :on_connecting
|
85
|
+
|
48
86
|
# called back once the connection has been closed.
|
49
87
|
#
|
50
88
|
# @method on_close
|
data/spec/support/logging.rb
CHANGED
@@ -22,7 +22,7 @@ module SpecGlobalLogger
|
|
22
22
|
# sets the log level to FATAL for the duration of the block
|
23
23
|
def mute_logger
|
24
24
|
orig_level, ZK.logger.level = ZK.logger.level, Logger::FATAL
|
25
|
-
orig_zk_level, Zookeeper.debug_level = Zookeeper.debug_level,
|
25
|
+
orig_zk_level, Zookeeper.debug_level = Zookeeper.debug_level, Zookeeper::Constants::ZOO_LOG_LEVEL_ERROR
|
26
26
|
yield
|
27
27
|
ensure
|
28
28
|
ZK.logger.level = orig_level
|
@@ -70,7 +70,7 @@ module ZK::ZKEventMachine
|
|
70
70
|
logger.debug { "got callback with #{a.inspect}" }
|
71
71
|
a.should_not be_empty
|
72
72
|
a.first.should == @data
|
73
|
-
a.last.should be_instance_of(
|
73
|
+
a.last.should be_instance_of(Zookeeper::Stat)
|
74
74
|
EM.reactor_thread?.should be_true
|
75
75
|
@zkem.close! { done }
|
76
76
|
end
|
@@ -88,7 +88,7 @@ module ZK::ZKEventMachine
|
|
88
88
|
@zkem.get(@path) do |exc,data,stat|
|
89
89
|
exc.should be_nil
|
90
90
|
data.should == @data
|
91
|
-
stat.should be_instance_of(
|
91
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
92
92
|
EM.reactor_thread?.should be_true
|
93
93
|
@zkem.close! { done }
|
94
94
|
end
|
@@ -253,7 +253,7 @@ module ZK::ZKEventMachine
|
|
253
253
|
dfr = @zkem.set(@path, @new_data)
|
254
254
|
|
255
255
|
dfr.callback do |stat|
|
256
|
-
stat.should be_instance_of(
|
256
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
257
257
|
stat.version.should > @orig_stat.version
|
258
258
|
EM.reactor_thread?.should be_true
|
259
259
|
|
@@ -275,7 +275,7 @@ module ZK::ZKEventMachine
|
|
275
275
|
@zkem.connect do
|
276
276
|
@zkem.set(@path, @new_data) do |exc,stat|
|
277
277
|
exc.should be_nil
|
278
|
-
stat.should be_instance_of(
|
278
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
279
279
|
EM.reactor_thread?.should be_true
|
280
280
|
|
281
281
|
@zkem.get(@path) do |_,data|
|
@@ -386,7 +386,7 @@ module ZK::ZKEventMachine
|
|
386
386
|
dfr.callback do |stat|
|
387
387
|
stat.should_not be_nil
|
388
388
|
stat.should == @orig_stat
|
389
|
-
stat.should be_instance_of(
|
389
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
390
390
|
EM.reactor_thread?.should be_true
|
391
391
|
@zkem.close! { done }
|
392
392
|
end
|
@@ -403,7 +403,7 @@ module ZK::ZKEventMachine
|
|
403
403
|
@zkem.connect do
|
404
404
|
@zkem.stat(@path) do |exc,stat|
|
405
405
|
exc.should be_nil
|
406
|
-
stat.should be_instance_of(
|
406
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
407
407
|
EM.reactor_thread?.should be_true
|
408
408
|
@zkem.close! { done }
|
409
409
|
end
|
@@ -426,7 +426,7 @@ module ZK::ZKEventMachine
|
|
426
426
|
dfr.callback do |stat|
|
427
427
|
stat.should_not be_nil
|
428
428
|
stat.exists?.should be_false
|
429
|
-
stat.should be_instance_of(
|
429
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
430
430
|
EM.reactor_thread?.should be_true
|
431
431
|
@zkem.close! { done }
|
432
432
|
end
|
@@ -539,7 +539,7 @@ module ZK::ZKEventMachine
|
|
539
539
|
children.should include('child_1')
|
540
540
|
children.should include('child_2')
|
541
541
|
|
542
|
-
stat.should be_instance_of(
|
542
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
543
543
|
|
544
544
|
EM.reactor_thread?.should be_true
|
545
545
|
@zkem.close! { done }
|
@@ -561,7 +561,7 @@ module ZK::ZKEventMachine
|
|
561
561
|
children.length.should == 2
|
562
562
|
children.should include('child_1')
|
563
563
|
children.should include('child_2')
|
564
|
-
stat.should be_instance_of(
|
564
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
565
565
|
EM.reactor_thread?.should be_true
|
566
566
|
@zkem.close! { done }
|
567
567
|
end
|
@@ -621,8 +621,8 @@ module ZK::ZKEventMachine
|
|
621
621
|
|
622
622
|
dfr.callback do |acls,stat|
|
623
623
|
acls.should be_kind_of(Array)
|
624
|
-
acls.first.should be_kind_of(
|
625
|
-
stat.should be_instance_of(
|
624
|
+
acls.first.should be_kind_of(Zookeeper::ACLs::ACL)
|
625
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
626
626
|
|
627
627
|
EM.reactor_thread?.should be_true
|
628
628
|
@zkem.close! { done }
|
@@ -641,8 +641,8 @@ module ZK::ZKEventMachine
|
|
641
641
|
@zkem.get_acl(@path) do |exc,acls,stat|
|
642
642
|
exc.should be_nil
|
643
643
|
acls.should be_kind_of(Array)
|
644
|
-
acls.first.should be_kind_of(
|
645
|
-
stat.should be_instance_of(
|
644
|
+
acls.first.should be_kind_of(Zookeeper::ACLs::ACL)
|
645
|
+
stat.should be_instance_of(Zookeeper::Stat)
|
646
646
|
EM.reactor_thread?.should be_true
|
647
647
|
@zkem.close! { done }
|
648
648
|
end
|
@@ -811,6 +811,35 @@ module ZK::ZKEventMachine
|
|
811
811
|
end
|
812
812
|
end
|
813
813
|
end
|
814
|
+
|
815
|
+
it %[should re-register when the hook in the documentation is used] do
|
816
|
+
|
817
|
+
@perform_count = 0
|
818
|
+
|
819
|
+
hook = proc do |ev|
|
820
|
+
@zkem.on_connecting(&hook)
|
821
|
+
|
822
|
+
if ev
|
823
|
+
@perform_count += 1
|
824
|
+
end
|
825
|
+
|
826
|
+
if @perform_count == 2
|
827
|
+
@zkem.close! { done }
|
828
|
+
end
|
829
|
+
end
|
830
|
+
|
831
|
+
em do
|
832
|
+
hook.call(nil)
|
833
|
+
|
834
|
+
@zkem.connect do
|
835
|
+
event = event_mock(:connecting_event).tap do |ev|
|
836
|
+
ev.should_receive(:state).and_return(Zookeeper::ZOO_CONNECTING_STATE)
|
837
|
+
end
|
838
|
+
|
839
|
+
2.times { EM.next_tick { @zkem.event_handler.process(event) } }
|
840
|
+
end
|
841
|
+
end
|
842
|
+
end
|
814
843
|
end # on_connecting
|
815
844
|
end # Client
|
816
845
|
|
@@ -72,7 +72,7 @@ module ZK::ZKEventMachine
|
|
72
72
|
@zkem.children(@path, :watch => true).callback { |ary,stat|
|
73
73
|
logger.debug { "called back with: #{ary.inspect}" }
|
74
74
|
ary.should be_empty
|
75
|
-
stat.should be_kind_of(
|
75
|
+
stat.should be_kind_of(Zookeeper::Stat)
|
76
76
|
|
77
77
|
@zkem.create(@child_path, '').callback { |p|
|
78
78
|
p.should == @child_path
|
data/zk-eventmachine.gemspec
CHANGED
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{ZK client for EventMachine-based (async) applications}
|
13
13
|
s.description = s.description
|
14
14
|
|
15
|
-
s.add_dependency 'zk', '~> 1.
|
15
|
+
s.add_dependency 'zk', '~> 1.4.1'
|
16
16
|
|
17
17
|
# zk depends on slyphon-zookeeper, but we need at least this version
|
18
|
-
s.add_dependency '
|
18
|
+
s.add_dependency 'zookeeper', '~> 1.1.0'
|
19
19
|
s.add_dependency 'eventmachine', '~> 1.0.0.beta.4'
|
20
20
|
s.add_dependency 'deferred', '~> 0.5.3'
|
21
21
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk-eventmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan D. Simms
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: zk
|
@@ -25,28 +25,28 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 5
|
29
29
|
segments:
|
30
30
|
- 1
|
31
|
-
-
|
32
|
-
-
|
33
|
-
version: 1.
|
31
|
+
- 4
|
32
|
+
- 1
|
33
|
+
version: 1.4.1
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: zookeeper
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 19
|
45
45
|
segments:
|
46
|
+
- 1
|
47
|
+
- 1
|
46
48
|
- 0
|
47
|
-
|
48
|
-
- 2
|
49
|
-
version: 0.9.2
|
49
|
+
version: 1.1.0
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - ~>
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 3300709603
|
61
61
|
segments:
|
62
62
|
- 1
|
63
63
|
- 0
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- .dev_extras/rvmrc
|
99
99
|
- .dev_extras/slyphon-project.vimrc
|
100
100
|
- .gitignore
|
101
|
+
- .gitmodules
|
101
102
|
- .yardopts
|
102
103
|
- Gemfile
|
103
104
|
- LICENSE
|