rjr 0.9.0 → 0.11.7
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/bin/rjr-client +150 -0
- data/bin/rjr-client-launcher +38 -0
- data/bin/rjr-server +54 -32
- data/lib/rjr/amqp_node.rb +95 -37
- data/lib/rjr/common.rb +60 -10
- data/lib/rjr/dispatcher.rb +98 -16
- data/lib/rjr/em_adapter.rb +110 -0
- data/lib/rjr/inspect.rb +66 -0
- data/lib/rjr/local_node.rb +1 -0
- data/lib/rjr/message.rb +123 -3
- data/lib/rjr/missing_node.rb +17 -0
- data/lib/rjr/multi_node.rb +3 -0
- data/lib/rjr/node.rb +79 -67
- data/lib/rjr/tcp_node.rb +146 -53
- data/lib/rjr/tcp_node2.rb +4 -0
- data/lib/rjr/thread_pool2.rb +271 -0
- data/lib/rjr/util.rb +104 -0
- data/lib/rjr/web_node.rb +115 -23
- data/lib/rjr/ws_node.rb +162 -34
- data/lib/rjr.rb +5 -10
- data/specs/dispatcher_spec.rb +81 -0
- data/specs/em_adapter_spec.rb +85 -0
- data/specs/inspect_spec.rb +60 -0
- data/specs/message_spec.rb +58 -0
- data/specs/multi_node_spec.rb +5 -4
- data/specs/node_spec.rb +140 -4
- data/specs/tcp_node_spec.rb +1 -0
- data/specs/thread_pool_spec.rb +41 -0
- data/specs/util_spec.rb +46 -0
- data/specs/web_node_spec.rb +1 -0
- data/specs/ws_node_spec.rb +1 -1
- metadata +24 -8
- data/lib/rjr/web_socket.rb +0 -589
data/specs/node_spec.rb
CHANGED
@@ -15,12 +15,11 @@ describe RJR::Node do
|
|
15
15
|
node = RJR::Node.new :node_id => 'foobar',
|
16
16
|
:headers => {:h => 123}
|
17
17
|
node.em_run {
|
18
|
-
|
19
|
-
|
20
|
-
EventMachine.reactor_running?.should be_true
|
18
|
+
ThreadPool2Manager.running?.should be_true
|
19
|
+
EMAdapter.running?.should be_true
|
21
20
|
block1_called = true
|
22
21
|
node.em_run {
|
23
|
-
|
22
|
+
EMAdapter.running?.should be_true
|
24
23
|
block2_called = true
|
25
24
|
node.halt
|
26
25
|
}
|
@@ -30,4 +29,141 @@ describe RJR::Node do
|
|
30
29
|
block1_called.should be_true
|
31
30
|
block2_called.should be_true
|
32
31
|
end
|
32
|
+
|
33
|
+
#it "should gracefully stop managed subsystems" do
|
34
|
+
# # TODO test w/ keep_alive
|
35
|
+
# node = RJR::Node.new :node_id => 'foobar',
|
36
|
+
# :headers => {:h => 123}
|
37
|
+
# node.em_run {}
|
38
|
+
# EMAdapter.running?.should be_true
|
39
|
+
# ThreadPool2Manager.running?.should be_true
|
40
|
+
# node.stop
|
41
|
+
# node.join
|
42
|
+
#end
|
43
|
+
|
44
|
+
it "should halt managed subsystems" do
|
45
|
+
node = RJR::Node.new :node_id => 'foobar',
|
46
|
+
:headers => {:h => 123}
|
47
|
+
node.em_run {}
|
48
|
+
EMAdapter.running?.should be_true
|
49
|
+
ThreadPool2Manager.running?.should be_true
|
50
|
+
node.halt
|
51
|
+
node.join
|
52
|
+
EMAdapter.running?.should be_false
|
53
|
+
ThreadPool2Manager.running?.should be_false
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should run a block directly via eventmachine" do
|
57
|
+
block1_called = false
|
58
|
+
block1_thread = nil
|
59
|
+
|
60
|
+
node = RJR::Node.new :node_id => 'foobar',
|
61
|
+
:headers => {:h => 123}
|
62
|
+
node.em_run {
|
63
|
+
block1_called = true
|
64
|
+
block1_thread = Thread.current
|
65
|
+
node.halt
|
66
|
+
}
|
67
|
+
reactor_thread = EMAdapter.instance_variable_get(:@em_manager).instance_variable_get(:@reactor_thread)
|
68
|
+
node.join
|
69
|
+
block1_called.should be_true
|
70
|
+
block1_thread.should == reactor_thread
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should run a block in a thread via eventmachine" do
|
74
|
+
block1_called = false
|
75
|
+
block1_thread = nil
|
76
|
+
|
77
|
+
node = RJR::Node.new :node_id => 'foobar',
|
78
|
+
:headers => {:h => 123}
|
79
|
+
node.em_run_async {
|
80
|
+
block1_called = true
|
81
|
+
block1_thread = Thread.current
|
82
|
+
node.halt
|
83
|
+
}
|
84
|
+
reactor_thread = EMAdapter.instance_variable_get(:@em_manager).instance_variable_get(:@reactor_thread)
|
85
|
+
worker_threads = ThreadPool2Manager.thread_pool.instance_variable_get(:@worker_threads)
|
86
|
+
node.join
|
87
|
+
block1_called.should be_true
|
88
|
+
block1_thread.should_not == reactor_thread
|
89
|
+
worker_threads.should include(block1_thread)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should schedule a job to be run in a thread via eventmachine after a specified interval" do
|
93
|
+
block1_called = false
|
94
|
+
block1_thread = nil
|
95
|
+
|
96
|
+
node = RJR::Node.new :node_id => 'foobar',
|
97
|
+
:headers => {:h => 123}
|
98
|
+
node.em_schedule_async(1) {
|
99
|
+
block1_called = true
|
100
|
+
block1_thread = Thread.current
|
101
|
+
node.halt
|
102
|
+
}
|
103
|
+
reactor_thread = EMAdapter.instance_variable_get(:@em_manager).instance_variable_get(:@reactor_thread)
|
104
|
+
worker_threads = ThreadPool2Manager.thread_pool.instance_variable_get(:@worker_threads)
|
105
|
+
|
106
|
+
sleep 0.5
|
107
|
+
block1_called.should be_false
|
108
|
+
|
109
|
+
node.join
|
110
|
+
block1_called.should be_true
|
111
|
+
block1_thread.should_not == reactor_thread
|
112
|
+
worker_threads.should include(block1_thread)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should schedule a job to be run directly via eventmachine repeatidly with specified interval" do
|
116
|
+
block1_threads = []
|
117
|
+
|
118
|
+
node = RJR::Node.new :node_id => 'foobar',
|
119
|
+
:headers => {:h => 123}
|
120
|
+
node.em_repeat(1) {
|
121
|
+
block1_threads << Thread.current
|
122
|
+
}
|
123
|
+
reactor_thread = EMAdapter.instance_variable_get(:@em_manager).instance_variable_get(:@reactor_thread)
|
124
|
+
|
125
|
+
sleep 0.5
|
126
|
+
block1_threads.size.should == 0
|
127
|
+
|
128
|
+
sleep 0.6
|
129
|
+
block1_threads.size.should == 1
|
130
|
+
|
131
|
+
sleep 1.1
|
132
|
+
block1_threads.size.should == 2
|
133
|
+
node.halt
|
134
|
+
node.join
|
135
|
+
|
136
|
+
block1_threads.each { |bt|
|
137
|
+
bt.should == reactor_thread
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should schedule a job to be run in a thread via eventmachine repeatidly with specified interval" do
|
142
|
+
block1_threads = []
|
143
|
+
|
144
|
+
node = RJR::Node.new :node_id => 'foobar',
|
145
|
+
:headers => {:h => 123}
|
146
|
+
node.em_repeat_async(1) {
|
147
|
+
block1_threads << Thread.current
|
148
|
+
}
|
149
|
+
reactor_thread = EMAdapter.instance_variable_get(:@em_manager).instance_variable_get(:@reactor_thread)
|
150
|
+
worker_threads = ThreadPool2Manager.thread_pool.instance_variable_get(:@worker_threads)
|
151
|
+
|
152
|
+
sleep 0.5
|
153
|
+
block1_threads.size.should == 0
|
154
|
+
|
155
|
+
sleep 0.6
|
156
|
+
block1_threads.size.should == 1
|
157
|
+
|
158
|
+
sleep 1.1
|
159
|
+
block1_threads.size.should == 2
|
160
|
+
node.halt
|
161
|
+
node.join
|
162
|
+
|
163
|
+
block1_threads.each { |bt|
|
164
|
+
bt.should_not == reactor_thread
|
165
|
+
worker_threads.should include(bt)
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
33
169
|
end
|
data/specs/tcp_node_spec.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rjr/dispatcher'
|
2
|
+
require 'rjr/thread_pool2'
|
3
|
+
|
4
|
+
# TODO ? test ThreadPoolJob being_executed?, completed?, exec, handle_timeout!
|
5
|
+
|
6
|
+
describe ThreadPool2 do
|
7
|
+
it "should start and stop successfully" do
|
8
|
+
tp = ThreadPool2.new 10, :timeout => 10
|
9
|
+
tp.running?.should be_false
|
10
|
+
|
11
|
+
tp.start
|
12
|
+
tp.running?.should be_true
|
13
|
+
tp.instance_variable_get(:@worker_threads).size.should == 10
|
14
|
+
tp.instance_variable_get(:@manager_thread).should_not be_nil
|
15
|
+
['run', 'sleep'].should include(tp.instance_variable_get(:@manager_thread).status)
|
16
|
+
sleep 0.5
|
17
|
+
|
18
|
+
tp.stop
|
19
|
+
tp.running?.should be_false
|
20
|
+
tp.instance_variable_get(:@manager_thread).should be_nil
|
21
|
+
tp.instance_variable_get(:@worker_threads).size.should == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accept and run work" do
|
25
|
+
tp = ThreadPool2.new 10, :timeout => 10
|
26
|
+
tp.start
|
27
|
+
|
28
|
+
tp.instance_variable_get(:@work_queue).size.should == 0
|
29
|
+
jobs_executed = []
|
30
|
+
tp << ThreadPool2Job.new { jobs_executed << 1 }
|
31
|
+
tp << ThreadPool2Job.new { jobs_executed << 2 }
|
32
|
+
tp.instance_variable_get(:@work_queue).size.should == 2
|
33
|
+
|
34
|
+
sleep 0.5
|
35
|
+
jobs_executed.should include(1)
|
36
|
+
jobs_executed.should include(2)
|
37
|
+
tp.instance_variable_get(:@work_queue).size.should == 0
|
38
|
+
|
39
|
+
tp.stop
|
40
|
+
end
|
41
|
+
end
|
data/specs/util_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rjr/dispatcher'
|
2
|
+
require 'rjr/util'
|
3
|
+
|
4
|
+
describe RJR::Definitions do
|
5
|
+
include RJR::Definitions
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
RJR::Dispatcher.init_handlers
|
9
|
+
RJR::Definitions.reset
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should define methods" do
|
13
|
+
foobar = lambda {}
|
14
|
+
barfoo = lambda {}
|
15
|
+
rjr_method :foobar => foobar, :barfoo => barfoo
|
16
|
+
RJR::Dispatcher.handler_for('foobar').handler_proc.should == foobar
|
17
|
+
RJR::Dispatcher.handler_for('barfoo').handler_proc.should == barfoo
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should track messages" do
|
21
|
+
rjr_message :foobar => { :foo => :bar }
|
22
|
+
rjr_message('foobar').should == {:foo => :bar}
|
23
|
+
|
24
|
+
rjr_message :foobar => { :bar => :foo }
|
25
|
+
rjr_message('foobar').should == {:bar => :foo}
|
26
|
+
|
27
|
+
rjr_message('money').should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should generate random message" do
|
31
|
+
rjr_message :foobar => { :foo => :bar, :transports => [:local, :amqp] }
|
32
|
+
rjr_message :barfoo => { :bar => :foo, :transports => [:local] }
|
33
|
+
rjr_message :forzzy => { :for => :zzy, :transports => [:amqp] }
|
34
|
+
rjr_message :moneyy => { :mon => :eyy }
|
35
|
+
|
36
|
+
[:foo, :bar, :for, :mon].should include(RJR::Definitions::rand_msg.first.first)
|
37
|
+
[:foo, :bar, :mon].should include(RJR::Definitions::rand_msg(:local).first.first)
|
38
|
+
[:foo, :for, :mon].should include(RJR::Definitions::rand_msg(:amqp).first.first)
|
39
|
+
RJR::Definitions::rand_msg(:tcp).first.first.should == :mon
|
40
|
+
|
41
|
+
RJR::Definitions.reset
|
42
|
+
rjr_message :foobar => { :foo => :bar, :transports => [:local, :amqp] }
|
43
|
+
|
44
|
+
RJR::Definitions::rand_msg(:tcp).should == nil
|
45
|
+
end
|
46
|
+
end
|
data/specs/web_node_spec.rb
CHANGED
data/specs/ws_node_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -32,17 +32,17 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 1.0.1
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 1.0.1
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: json
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,23 +63,30 @@ description: Ruby Json Rpc library
|
|
63
63
|
email: mo@morsi.org
|
64
64
|
executables:
|
65
65
|
- rjr-server
|
66
|
+
- rjr-client
|
67
|
+
- rjr-client-launcher
|
66
68
|
extensions: []
|
67
69
|
extra_rdoc_files: []
|
68
70
|
files:
|
69
71
|
- lib/rjr/semaphore.rb
|
70
72
|
- lib/rjr/udp_node.rb
|
73
|
+
- lib/rjr/em_adapter.rb
|
71
74
|
- lib/rjr/errors.rb
|
75
|
+
- lib/rjr/missing_node.rb
|
76
|
+
- lib/rjr/inspect.rb
|
72
77
|
- lib/rjr/ws_node.rb
|
73
78
|
- lib/rjr/tcp_node.rb
|
74
79
|
- lib/rjr/web_node.rb
|
75
80
|
- lib/rjr/node.rb
|
81
|
+
- lib/rjr/thread_pool2.rb
|
76
82
|
- lib/rjr/common.rb
|
77
83
|
- lib/rjr/thread_pool.rb
|
78
84
|
- lib/rjr/message.rb
|
79
|
-
- lib/rjr/
|
85
|
+
- lib/rjr/tcp_node2.rb
|
80
86
|
- lib/rjr/multi_node.rb
|
81
87
|
- lib/rjr/local_node.rb
|
82
88
|
- lib/rjr/dispatcher.rb
|
89
|
+
- lib/rjr/util.rb
|
83
90
|
- lib/rjr/amqp_node.rb
|
84
91
|
- lib/rjr.rb
|
85
92
|
- specs/dispatcher_spec.rb
|
@@ -87,14 +94,20 @@ files:
|
|
87
94
|
- specs/amqp_node_spec.rb
|
88
95
|
- specs/tcp_node_spec.rb
|
89
96
|
- specs/multi_node_spec.rb
|
97
|
+
- specs/util_spec.rb
|
90
98
|
- specs/local_node_spec.rb
|
91
99
|
- specs/web_node_spec.rb
|
92
100
|
- specs/ws_node_spec.rb
|
101
|
+
- specs/inspect_spec.rb
|
102
|
+
- specs/thread_pool_spec.rb
|
93
103
|
- specs/message_spec.rb
|
104
|
+
- specs/em_adapter_spec.rb
|
94
105
|
- LICENSE
|
95
106
|
- Rakefile
|
96
107
|
- README.md
|
97
108
|
- bin/rjr-server
|
109
|
+
- bin/rjr-client
|
110
|
+
- bin/rjr-client-launcher
|
98
111
|
homepage: http://github.com/movitto/rjr
|
99
112
|
licenses: []
|
100
113
|
post_install_message:
|
@@ -113,7 +126,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
126
|
- - ! '>='
|
114
127
|
- !ruby/object:Gem::Version
|
115
128
|
version: 1.3.3
|
116
|
-
requirements:
|
129
|
+
requirements:
|
130
|
+
- amqp gem is needed to use the amqp node
|
131
|
+
- eventmachine_httpserver and em-http-request gems are needed to use the web node
|
132
|
+
- em-websocket and em-websocket-client gems are needed to use the web socket node
|
117
133
|
rubyforge_project:
|
118
134
|
rubygems_version: 1.8.24
|
119
135
|
signing_key:
|