rjr 0.12.2 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/README.md +49 -36
  2. data/Rakefile +2 -0
  3. data/bin/rjr-client +11 -9
  4. data/bin/rjr-server +12 -10
  5. data/examples/amqp.rb +29 -0
  6. data/examples/client.rb +32 -0
  7. data/examples/complete.rb +36 -0
  8. data/examples/local.rb +29 -0
  9. data/examples/server.rb +26 -0
  10. data/examples/tcp.rb +29 -0
  11. data/examples/web.rb +22 -0
  12. data/examples/ws.rb +29 -0
  13. data/lib/rjr/common.rb +7 -12
  14. data/lib/rjr/dispatcher.rb +171 -239
  15. data/lib/rjr/em_adapter.rb +33 -66
  16. data/lib/rjr/message.rb +43 -12
  17. data/lib/rjr/node.rb +197 -103
  18. data/lib/rjr/nodes/amqp.rb +216 -0
  19. data/lib/rjr/nodes/easy.rb +159 -0
  20. data/lib/rjr/nodes/local.rb +118 -0
  21. data/lib/rjr/{missing_node.rb → nodes/missing.rb} +4 -2
  22. data/lib/rjr/nodes/multi.rb +79 -0
  23. data/lib/rjr/nodes/tcp.rb +211 -0
  24. data/lib/rjr/nodes/web.rb +197 -0
  25. data/lib/rjr/nodes/ws.rb +187 -0
  26. data/lib/rjr/stats.rb +70 -0
  27. data/lib/rjr/thread_pool.rb +178 -123
  28. data/site/index.html +45 -0
  29. data/site/jquery-latest.js +9404 -0
  30. data/site/jrw.js +297 -0
  31. data/site/json.js +199 -0
  32. data/specs/dispatcher_spec.rb +244 -198
  33. data/specs/em_adapter_spec.rb +52 -80
  34. data/specs/message_spec.rb +223 -197
  35. data/specs/node_spec.rb +67 -163
  36. data/specs/nodes/amqp_spec.rb +82 -0
  37. data/specs/nodes/easy_spec.rb +13 -0
  38. data/specs/nodes/local_spec.rb +72 -0
  39. data/specs/nodes/multi_spec.rb +65 -0
  40. data/specs/nodes/tcp_spec.rb +75 -0
  41. data/specs/nodes/web_spec.rb +77 -0
  42. data/specs/nodes/ws_spec.rb +78 -0
  43. data/specs/stats_spec.rb +59 -0
  44. data/specs/thread_pool_spec.rb +44 -35
  45. metadata +40 -30
  46. data/lib/rjr/amqp_node.rb +0 -330
  47. data/lib/rjr/inspect.rb +0 -65
  48. data/lib/rjr/local_node.rb +0 -150
  49. data/lib/rjr/multi_node.rb +0 -65
  50. data/lib/rjr/tcp_node.rb +0 -323
  51. data/lib/rjr/thread_pool2.rb +0 -272
  52. data/lib/rjr/util.rb +0 -104
  53. data/lib/rjr/web_node.rb +0 -266
  54. data/lib/rjr/ws_node.rb +0 -289
  55. data/lib/rjr.rb +0 -16
  56. data/specs/amqp_node_spec.rb +0 -31
  57. data/specs/inspect_spec.rb +0 -60
  58. data/specs/local_node_spec.rb +0 -43
  59. data/specs/multi_node_spec.rb +0 -45
  60. data/specs/tcp_node_spec.rb +0 -33
  61. data/specs/util_spec.rb +0 -46
  62. data/specs/web_node_spec.rb +0 -32
  63. data/specs/ws_node_spec.rb +0 -32
  64. /data/lib/rjr/{tcp_node2.rb → nodes/tcp2.rb} +0 -0
  65. /data/lib/rjr/{udp_node.rb → nodes/udp.rb} +0 -0
@@ -1,203 +1,229 @@
1
1
  require 'rjr/dispatcher'
2
2
  require 'rjr/message'
3
3
 
4
- describe RJR::RequestMessage do
5
- it "should accept request parameters" do
6
- msg = RJR::RequestMessage.new :method => 'test',
7
- :args => ['a', 1],
8
- :headers => {:h => 2}
9
- msg.jr_method.should == "test"
10
- msg.jr_args.should =~ ['a', 1]
11
- msg.headers.should have_key(:h)
12
- msg.headers[:h].should == 2
13
- msg.msg_id.should =~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
4
+ module RJR
5
+ describe RequestMessage do
6
+ it "should accept request parameters" do
7
+ msg = RequestMessage.new :method => 'test',
8
+ :args => ['a', 1],
9
+ :headers => {:h => 2}
10
+ msg.jr_method.should == "test"
11
+ msg.jr_args.should =~ ['a', 1]
12
+ msg.headers.should have_key(:h)
13
+ msg.headers[:h].should == 2
14
+ msg.msg_id.should =~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
15
+ end
16
+
17
+ it "should return bool indicating if string is a request msg"
18
+
19
+ it "should produce valid json" do
20
+ msg = RequestMessage.new :method => 'test',
21
+ :args => ['a', 1],
22
+ :headers => {:h => 2}
23
+
24
+ msg_string = msg.to_s
25
+ msg_string.should include('"h":2')
26
+ msg_string.should include('"method":"test"')
27
+ msg_string.should include('"params":["a",1]')
28
+ msg_string.should include('"jsonrpc":"2.0"')
29
+ msg_string.should include('"id":"'+msg.msg_id+'"')
30
+ end
31
+
32
+ it "should parse request message string" do
33
+ msg_uuid = gen_uuid
34
+ msg_string = '{"jsonrpc": "2.0", ' +
35
+ '"id": "' + msg_uuid + '", ' +
36
+ '"method": "test", "params": ["a", 1]}'
37
+ msg = RequestMessage.new :message => msg_string
38
+ msg.json_message.should == msg_string
39
+ msg.jr_method.should == 'test'
40
+ msg.jr_args.should =~ ['a', 1]
41
+ msg.msg_id.should == msg_uuid
42
+ end
43
+
44
+ it "should extract optional headers from message string" do
45
+ msg_uuid = gen_uuid
46
+ msg_string = '{"jsonrpc": "2.0", ' +
47
+ '"id": "' + msg_uuid + '", ' +
48
+ '"method": "test", "params": ["a", 1], ' +
49
+ '"h": 2}'
50
+ msg = RequestMessage.new :message => msg_string, :headers => {'f' => 'g'}
51
+ msg.json_message.should == msg_string
52
+ msg.headers.should have_key 'h'
53
+ msg.headers.should have_key 'f'
54
+ msg.headers['h'].should == 2
55
+ msg.headers['f'].should == 'g'
56
+ end
57
+
58
+ it "should fail if parsing invalid message string" do
59
+ lambda {
60
+ msg = RequestMessage.new :message => 'foobar'
61
+ }.should raise_error JSON::ParserError
62
+ end
63
+
64
+ end
65
+
66
+ describe ResponseMessage do
67
+ it "should accept response parameters" do
68
+ msg_id = gen_uuid
69
+ msg = ResponseMessage.new :id => msg_id,
70
+ :result => Result.new(:result => 'success'),
71
+ :headers => {:h => 2}
72
+ msg.msg_id.should == msg_id
73
+ msg.result.result == 'success'
74
+ msg.headers.should have_key(:h)
75
+ msg.headers[:h].should == 2
76
+ end
77
+
78
+ it "should return bool indicating if string is a response msg"
79
+
80
+ it "should produce valid result response json" do
81
+ msg_id = gen_uuid
82
+ msg = ResponseMessage.new :id => msg_id,
83
+ :result => RJR::Result.new(:result => 'success'),
84
+ :headers => {:h => 2}
85
+ msg_string = msg.to_s
86
+ msg_string.should include('"id":"'+msg_id+'"')
87
+ msg_string.should include('"result":"success"')
88
+ msg_string.should include('"h":2')
89
+ msg_string.should include('"jsonrpc":"2.0"')
90
+ end
91
+
92
+ it "should produce valid error response json" do
93
+ msg_id = gen_uuid
94
+ msg = ResponseMessage.new :id => msg_id,
95
+ :result =>
96
+ RJR::Result.new(:error_code => 404,
97
+ :error_msg => 'not found',
98
+ :error_class => ArgumentError),
99
+ :headers => {:h => 2}
100
+ msg_string = msg.to_s
101
+ msg_string.should include('"id":"'+msg_id+'"')
102
+ msg_string.should include('"h":2')
103
+ msg_string.should include('"jsonrpc":"2.0"')
104
+ msg_string.should include('"error":{')
105
+ msg_string.should include('"code":404')
106
+ msg_string.should include('"message":"not found"')
107
+ end
108
+
109
+
110
+ it "should parse result response message string" do
111
+ msg_id = gen_uuid
112
+ msg_string = '{"id":"' + msg_id + '", ' +
113
+ '"result":"success","jsonrpc":"2.0"}'
114
+ msg = ResponseMessage.new :message => msg_string
115
+ msg.json_message.should == msg_string
116
+ msg.msg_id.should == msg_id
117
+ msg.result.success.should == true
118
+ msg.result.failed.should == false
119
+ msg.result.result.should == "success"
120
+ end
121
+
122
+ it "should parse error response message string" do
123
+ msg_id = gen_uuid
124
+ msg_string = '{"id":"' + msg_id + '", ' +
125
+ '"error":{"code":404,"message":"not found","class":"ArgumentError"}, "jsonrpc":"2.0"}'
126
+ msg = ResponseMessage.new :message => msg_string
127
+ msg.json_message.should == msg_string
128
+ msg.msg_id.should == msg_id
129
+ msg.result.success.should == false
130
+ msg.result.failed.should == true
131
+ msg.result.error_code.should == 404
132
+ msg.result.error_msg.should == "not found"
133
+ msg.result.error_class.should == 'ArgumentError'
134
+ end
135
+
136
+ it "should extract optional headers from message string" do
137
+ msg_id = gen_uuid
138
+ msg_string = '{"id":"' + msg_id + '", ' +
139
+ '"result":"success","h":2,"jsonrpc":"2.0"}'
140
+ msg = ResponseMessage.new :message => msg_string
141
+ msg.json_message.should == msg_string
142
+ msg.headers.should have_key 'h'
143
+ msg.headers['h'].should == 2
144
+ end
145
+
146
+ it "should fail if parsing invalid message string" do
147
+ lambda {
148
+ msg = ResponseMessage.new :message => 'foobar'
149
+ }.should raise_error JSON::ParserError
150
+ end
151
+ end
152
+
153
+ describe NotificationMessage do
154
+ it "should accept notification parameters" do
155
+ msg = NotificationMessage.new :method => 'test',
156
+ :args => ['a', 1],
157
+ :headers => {:h => 2}
158
+ msg.jr_method.should == "test"
159
+ msg.jr_args.should =~ ['a', 1]
160
+ msg.headers.should have_key(:h)
161
+ msg.headers[:h].should == 2
162
+ end
163
+
164
+ it "should return bool indicating if string is a notification msg"
165
+
166
+ it "should produce valid json" do
167
+ msg = NotificationMessage.new :method => 'test',
168
+ :args => ['a', 1],
169
+ :headers => {:h => 2}
170
+
171
+ msg_string = msg.to_s
172
+ msg_string.should include('"h":2')
173
+ msg_string.should include('"method":"test"')
174
+ msg_string.should include('"params":["a",1]')
175
+ msg_string.should include('"jsonrpc":"2.0"')
176
+ msg_string.should_not include('"id":"')
177
+ end
178
+
179
+ it "should parse notification message string" do
180
+ msg_string = '{"jsonrpc": "2.0", ' +
181
+ '"method": "test", "params": ["a", 1]}'
182
+ msg = NotificationMessage.new :message => msg_string
183
+ msg.json_message.should == msg_string
184
+ msg.jr_method.should == 'test'
185
+ msg.jr_args.should =~ ['a', 1]
186
+ end
187
+
188
+ it "should extract optional headers from message string" do
189
+ msg_string = '{"jsonrpc": "2.0", ' +
190
+ '"method": "test", "params": ["a", 1], ' +
191
+ '"h": 2}'
192
+ msg = NotificationMessage.new :message => msg_string, :headers => {'f' => 'g'}
193
+ msg.json_message.should == msg_string
194
+ msg.headers.should have_key 'h'
195
+ msg.headers.should have_key 'f'
196
+ msg.headers['h'].should == 2
197
+ msg.headers['f'].should == 'g'
198
+ end
199
+
200
+ it "should fail if parsing invalid message string" do
201
+ lambda {
202
+ msg = NotificationMessage.new :message => 'foobar'
203
+ }.should raise_error JSON::ParserError
204
+ end
205
+ end
206
+
207
+ describe MessageUtil do
208
+ after(:each) do
209
+ MessageUtil.clear
210
+ end
211
+
212
+ it "should extract json messages out of a message stream"
213
+
214
+ it "should store preformatted messages" do
215
+ MessageUtil.message 'foobar', 'raboof'
216
+ MessageUtil.message('foobar').should == 'raboof'
217
+ end
218
+
219
+ it "should clear preformatted messages" do
220
+ MessageUtil.message 'foobar', 'raboof'
221
+ MessageUtil.clear
222
+ MessageUtil.message('foobar').should be_nil
223
+ end
224
+
225
+ it "should return rand preformatted message"
226
+ it "should return rand preformatted message matching transport"
14
227
  end
15
228
 
16
- it "should produce valid json" do
17
- msg = RJR::RequestMessage.new :method => 'test',
18
- :args => ['a', 1],
19
- :headers => {:h => 2}
20
-
21
- msg_string = msg.to_s
22
- msg_string.should include('"h":2')
23
- msg_string.should include('"method":"test"')
24
- msg_string.should include('"params":["a",1]')
25
- msg_string.should include('"jsonrpc":"2.0"')
26
- msg_string.should include('"id":"'+msg.msg_id+'"')
27
- end
28
-
29
- it "should parse request message string" do
30
- msg_uuid = RJR::RequestMessage.gen_uuid
31
- msg_string = '{"jsonrpc": "2.0", ' +
32
- '"id": "' + msg_uuid + '", ' +
33
- '"method": "test", "params": ["a", 1]}'
34
- msg = RJR::RequestMessage.new :message => msg_string
35
- msg.json_message.should == msg_string
36
- msg.jr_method.should == 'test'
37
- msg.jr_args.should =~ ['a', 1]
38
- msg.msg_id.should == msg_uuid
39
- end
40
-
41
- it "should extract optional headers from message string" do
42
- msg_uuid = RJR::RequestMessage.gen_uuid
43
- msg_string = '{"jsonrpc": "2.0", ' +
44
- '"id": "' + msg_uuid + '", ' +
45
- '"method": "test", "params": ["a", 1], ' +
46
- '"h": 2}'
47
- msg = RJR::RequestMessage.new :message => msg_string, :headers => {'f' => 'g'}
48
- msg.json_message.should == msg_string
49
- msg.headers.should have_key 'h'
50
- msg.headers.should have_key 'f'
51
- msg.headers['h'].should == 2
52
- msg.headers['f'].should == 'g'
53
- end
54
-
55
- it "should fail if parsing invalid message string" do
56
- lambda {
57
- msg = RJR::RequestMessage.new :message => 'foobar'
58
- }.should raise_error JSON::ParserError
59
- end
60
- end
61
-
62
- describe RJR::ResponseMessage do
63
- it "should accept response parameters" do
64
- msg_id = RJR::RequestMessage.gen_uuid
65
- msg = RJR::ResponseMessage.new :id => msg_id,
66
- :result => RJR::Result.new(:result => 'success'),
67
- :headers => {:h => 2}
68
- msg.msg_id.should == msg_id
69
- msg.result.result == 'success'
70
- msg.headers.should have_key(:h)
71
- msg.headers[:h].should == 2
72
- end
73
-
74
- it "should produce valid result response json" do
75
- msg_id = RJR::RequestMessage.gen_uuid
76
- msg = RJR::ResponseMessage.new :id => msg_id,
77
- :result => RJR::Result.new(:result => 'success'),
78
- :headers => {:h => 2}
79
- msg_string = msg.to_s
80
- msg_string.should include('"id":"'+msg_id+'"')
81
- msg_string.should include('"result":"success"')
82
- msg_string.should include('"h":2')
83
- msg_string.should include('"jsonrpc":"2.0"')
84
- end
85
-
86
- it "should produce valid error response json" do
87
- msg_id = RJR::RequestMessage.gen_uuid
88
- msg = RJR::ResponseMessage.new :id => msg_id,
89
- :result => RJR::Result.new(:error_code => 404,
90
- :error_msg => 'not found',
91
- :error_class => ArgumentError),
92
- :headers => {:h => 2}
93
- msg_string = msg.to_s
94
- msg_string.should include('"id":"'+msg_id+'"')
95
- msg_string.should include('"h":2')
96
- msg_string.should include('"jsonrpc":"2.0"')
97
- msg_string.should include('"error":{')
98
- msg_string.should include('"code":404')
99
- msg_string.should include('"message":"not found"')
100
- end
101
-
102
-
103
- it "should parse result response message string" do
104
- msg_id = RJR::RequestMessage.gen_uuid
105
- msg_string = '{"id":"' + msg_id + '", ' +
106
- '"result":"success","jsonrpc":"2.0"}'
107
- msg = RJR::ResponseMessage.new :message => msg_string
108
- msg.json_message.should == msg_string
109
- msg.msg_id.should == msg_id
110
- msg.result.success.should == true
111
- msg.result.failed.should == false
112
- msg.result.result.should == "success"
113
- end
114
-
115
- it "should parse error response message string" do
116
-
117
- msg_id = RJR::RequestMessage.gen_uuid
118
- msg_string = '{"id":"' + msg_id + '", ' +
119
- '"error":{"code":404,"message":"not found","class":"ArgumentError"}, "jsonrpc":"2.0"}'
120
- msg = RJR::ResponseMessage.new :message => msg_string
121
- msg.json_message.should == msg_string
122
- msg.msg_id.should == msg_id
123
- msg.result.success.should == false
124
- msg.result.failed.should == true
125
- msg.result.error_code.should == 404
126
- msg.result.error_msg.should == "not found"
127
- msg.result.error_class.should == 'ArgumentError'
128
- end
129
-
130
- it "should extract optional headers from message string" do
131
- msg_id = RJR::RequestMessage.gen_uuid
132
- msg_string = '{"id":"' + msg_id + '", ' +
133
- '"result":"success","h":2,"jsonrpc":"2.0"}'
134
- msg = RJR::ResponseMessage.new :message => msg_string
135
- msg.json_message.should == msg_string
136
- msg.headers.should have_key 'h'
137
- msg.headers['h'].should == 2
138
- end
139
-
140
- it "should fail if parsing invalid message string" do
141
- lambda {
142
- msg = RJR::ResponseMessage.new :message => 'foobar'
143
- }.should raise_error JSON::ParserError
144
- end
145
- end
146
-
147
- describe RJR::NotificationMessage do
148
- it "should accept notification parameters" do
149
- msg = RJR::NotificationMessage.new :method => 'test',
150
- :args => ['a', 1],
151
- :headers => {:h => 2}
152
- msg.jr_method.should == "test"
153
- msg.jr_args.should =~ ['a', 1]
154
- msg.headers.should have_key(:h)
155
- msg.headers[:h].should == 2
156
- end
157
-
158
- it "should produce valid json" do
159
- msg = RJR::NotificationMessage.new :method => 'test',
160
- :args => ['a', 1],
161
- :headers => {:h => 2}
162
-
163
- msg_string = msg.to_s
164
- msg_string.should include('"h":2')
165
- msg_string.should include('"method":"test"')
166
- msg_string.should include('"params":["a",1]')
167
- msg_string.should include('"jsonrpc":"2.0"')
168
- msg_string.should_not include('"id":"')
169
- end
170
-
171
- it "should parse notification message string" do
172
- msg_string = '{"jsonrpc": "2.0", ' +
173
- '"method": "test", "params": ["a", 1]}'
174
- msg = RJR::NotificationMessage.new :message => msg_string
175
- msg.json_message.should == msg_string
176
- msg.jr_method.should == 'test'
177
- msg.jr_args.should =~ ['a', 1]
178
- end
179
-
180
- it "should extract optional headers from message string" do
181
- msg_string = '{"jsonrpc": "2.0", ' +
182
- '"method": "test", "params": ["a", 1], ' +
183
- '"h": 2}'
184
- msg = RJR::NotificationMessage.new :message => msg_string, :headers => {'f' => 'g'}
185
- msg.json_message.should == msg_string
186
- msg.headers.should have_key 'h'
187
- msg.headers.should have_key 'f'
188
- msg.headers['h'].should == 2
189
- msg.headers['f'].should == 'g'
190
- end
191
-
192
- it "should fail if parsing invalid message string" do
193
- lambda {
194
- msg = RJR::NotificationMessage.new :message => 'foobar'
195
- }.should raise_error JSON::ParserError
196
- end
197
- end
198
-
199
- describe RJR::MessageUtil do
200
- it "should extract json messages out of a message stream" do
201
- # TODO!
202
- end
203
229
  end
data/specs/node_spec.rb CHANGED
@@ -1,169 +1,73 @@
1
+ require 'rjr/dispatcher'
1
2
  require 'rjr/node'
2
3
 
3
- describe RJR::Node do
4
- it "should initialize properly from params" do
5
- node = RJR::Node.new :node_id => 'foobar',
6
- :headers => {:h => 123}
7
- node.node_id.should == 'foobar'
8
- node.message_headers[:h].should == 123
4
+ module RJR
5
+ describe Node do
6
+
7
+ it "should initialize properly from params" do
8
+ d = Dispatcher.new
9
+ node = Node.new :node_id => 'foobar',
10
+ :headers => {:h => 123},
11
+ :dispatcher => d
12
+ node.node_id.should == 'foobar'
13
+ node.message_headers[:h].should == 123
14
+ node.dispatcher.should == d
15
+ end
16
+
17
+ it "should create a new dispatcher" do
18
+ node = Node.new
19
+ node.dispatcher.should_not be_nil
20
+ node.dispatcher.class.should == Dispatcher
21
+ end
22
+
23
+ it "should start the thread pool" do
24
+ ThreadPool.instance.stop.join
25
+ node = Node.new
26
+ ThreadPool.instance.should be_running
27
+ end
28
+
29
+ it "should start event machine" do
30
+ EMAdapter.instance.halt.join
31
+ node = Node.new
32
+ EMAdapter.instance.reactor_running?.should be_true
33
+ end
34
+
35
+ it "should halt the thread pool" do
36
+ node = Node.new
37
+ node.halt.join
38
+ ThreadPool.instance.should_not be_running
39
+ end
40
+
41
+ it "should halt event machine" do
42
+ node = Node.new
43
+ node.halt.join
44
+ EMAdapter.instance.reactor_running?.should be_false
45
+ end
46
+
47
+ it "should handle connection events" do
48
+ node = Node.new
49
+ closed = false
50
+ error = false
51
+ node.on :closed do
52
+ closed = true
53
+ end
54
+ node.on :error do
55
+ error = true
56
+ end
57
+ node.send(:connection_event, :error)
58
+ error.should be_true
59
+
60
+ node.send(:connection_event, :closed)
61
+ closed.should be_true
62
+ end
63
+
64
+ it "should handle request messages"
65
+ it "should handle notification messages"
66
+ it "should handle response messages"
67
+ it "should block until reponse is received"
9
68
  end
10
69
 
11
- it "should start eventmachine and allow multiple blocks to be invoked in its context" do
12
- block1_called = false
13
- block2_called = false
14
-
15
- node = RJR::Node.new :node_id => 'foobar',
16
- :headers => {:h => 123}
17
- node.em_run {
18
- ThreadPool2Manager.running?.should be_true
19
- EMAdapter.running?.should be_true
20
- block1_called = true
21
- node.em_run {
22
- EMAdapter.running?.should be_true
23
- block2_called = true
24
- node.halt
25
- }
26
- }
27
- node.join
28
-
29
- block1_called.should be_true
30
- block2_called.should be_true
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)
70
+ describe NodeCallback do
71
+ it "should send notifications"
113
72
  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
-
169
73
  end