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,60 +0,0 @@
1
- require 'rjr/inspect'
2
-
3
- describe 'rjr/inspect.rb' do
4
- describe "select_stats" do
5
- before(:each) do
6
- RJR::DispatcherStat.reset
7
-
8
- req1 = RJR::Request.new :rjr_node_type => :local, :method => 'foobar'
9
- req2 = RJR::Request.new :rjr_node_type => :tcp, :method => 'barfoo'
10
- req3 = RJR::Request.new :rjr_node_type => :amqp, :method => 'foobar'
11
- res1 = RJR::Result.new :result => true
12
- res2 = RJR::Result.new :error_code => 123
13
- res3 = RJR::Result.new :error_code => 123
14
-
15
- @stat1 = RJR::DispatcherStat.new req1, res1
16
- @stat2 = RJR::DispatcherStat.new req2, res2
17
- @stat3 = RJR::DispatcherStat.new req3, res3
18
- RJR::DispatcherStat << @stat1 << @stat2 << @stat3
19
- end
20
-
21
- it "should get all dispatcherstats" do
22
- stats = select_stats
23
- stats.size.should == 3
24
- stats.first.should == @stat1
25
- stats[1].should == @stat2
26
- stats.last.should == @stat3
27
- end
28
-
29
- it "should get all dispatcherstats for a node" do
30
- stats = select_stats 'on_node', 'local'
31
- stats.size.should == 1
32
- stats.first.should == @stat1
33
- end
34
-
35
- it "should get all dispatcherstats for a method" do
36
- stats = select_stats 'for_method', 'foobar'
37
- stats.size.should == 2
38
- stats.first.should == @stat1
39
- stats.last.should == @stat3
40
- end
41
-
42
- it "should get all successfull/failed dispatcherstats" do
43
- stats = select_stats 'successful'
44
- stats.size.should == 1
45
- stats.first.should == @stat1
46
-
47
- stats = select_stats 'failed'
48
- stats.size.should == 2
49
- stats.first.should == @stat2
50
- stats.last.should == @stat3
51
- end
52
-
53
- it "should get dispatcher stats meeting multiple criteria" do
54
- stats = select_stats 'for_method', 'foobar', 'successful'
55
- stats.size.should == 1
56
- stats.first.should == @stat1
57
- end
58
- end
59
-
60
- end
@@ -1,43 +0,0 @@
1
- require 'rjr/local_node'
2
- require 'rjr/dispatcher'
3
-
4
- describe RJR::LocalNode do
5
- it "should invoke requests against local handler" do
6
- node = RJR::LocalNode.new :node_id => 'aaa'
7
- foobar_invoked = false
8
- RJR::Dispatcher.init_handlers
9
- RJR::Dispatcher.add_handler('foobar') { |param|
10
- @rjr_node.should == node
11
- @rjr_node_id.should == 'aaa'
12
- @rjr_node_type.should == :local
13
- param.should == 'myparam'
14
- foobar_invoked = true
15
- 'retval'
16
- }
17
-
18
- res = node.invoke_request 'foobar', 'myparam'
19
- foobar_invoked.should == true
20
- res.should == 'retval'
21
- end
22
-
23
- it "should invoke callbacks against local handlers" do
24
- foobar_invoked = false
25
- callback_invoked = false
26
- RJR::Dispatcher.init_handlers
27
- RJR::Dispatcher.add_handler('foobar') {
28
- foobar_invoked = true
29
- @rjr_callback.invoke('callback', 'cp')
30
- }
31
- RJR::Dispatcher.add_handler('callback') { |*params|
32
- params.length.should == 1
33
- params[0].should == 'cp'
34
- callback_invoked = true
35
- }
36
-
37
- node = RJR::LocalNode.new
38
- node.invoke_request 'foobar', 'myparam'
39
- end
40
-
41
- # TODO make sure object attributes not serialized to json
42
- # are not available on remote end of local node invocation/response
43
- end
@@ -1,45 +0,0 @@
1
- require 'rjr/multi_node'
2
- require 'rjr/amqp_node'
3
- require 'rjr/web_node'
4
- require 'rjr/dispatcher'
5
-
6
- describe RJR::MultiNode do
7
- it "should invoke and satisfy requests over multiple protocols" do
8
- foolbar_invoked = false
9
- barfoo_invoked = false
10
- RJR::Dispatcher.init_handlers
11
- RJR::Dispatcher.add_handler('foolbar') { |param|
12
- @rjr_node_id.should == 'amqp'
13
- @rjr_node_type.should == :amqp
14
- param.should == 'myparam1'
15
- foolbar_invoked = true
16
- 'retval1'
17
- }
18
- RJR::Dispatcher.add_handler('barfoo') { |param|
19
- @rjr_node_id.should == 'web'
20
- @rjr_node_type.should == :web
21
- param.should == 'myparam2'
22
- barfoo_invoked = true
23
- 'retval2'
24
- }
25
-
26
- amqp = RJR::AMQPNode.new :node_id => 'amqp', :broker => 'localhost'
27
- web = RJR::WebNode.new :node_id => 'web', :host => 'localhost', :port => 9876
28
- multi = RJR::MultiNode.new :node_id => 'multi', :nodes => [amqp, web], :keep_alive => true
29
-
30
- multi.listen
31
-
32
- amqp_client = RJR::AMQPNode.new :node_id => 'client', :broker => 'localhost', :keep_alive => true # see comment about keepalive in amqp_node_spec
33
- res = amqp_client.invoke_request 'amqp-queue', 'foolbar', 'myparam1'
34
- res.should == 'retval1'
35
-
36
- web_client = RJR::WebNode.new
37
- res = web_client.invoke_request 'http://localhost:9876', 'barfoo', 'myparam2'
38
- res.should == 'retval2'
39
-
40
- multi.halt
41
- multi.join
42
- foolbar_invoked.should == true
43
- barfoo_invoked.should == true
44
- end
45
- end
@@ -1,33 +0,0 @@
1
- require 'rjr/tcp_node'
2
- require 'rjr/dispatcher'
3
-
4
- describe RJR::TCPNode do
5
- it "should invoke and satisfy tcp requests" do
6
- server = RJR::TCPNode.new :node_id => 'tcp', :host => 'localhost', :port => 9987
7
- client = RJR::TCPNode.new
8
-
9
- foobar_invoked = false
10
- RJR::Dispatcher.init_handlers
11
- RJR::Dispatcher.add_handler('foobar') { |param|
12
- @client_ip.should == "127.0.0.1"
13
- #@client_port.should == 9987
14
- @rjr_node.should == server
15
- @rjr_node_id.should == 'tcp'
16
- @rjr_node_type.should == :tcp
17
- param.should == 'myparam'
18
- foobar_invoked = true
19
- 'retval'
20
- }
21
-
22
- server.listen
23
- sleep 1
24
- res = client.invoke_request 'jsonrpc://localhost:9987', 'foobar', 'myparam'
25
- res.should == 'retval'
26
- server.halt
27
- server.join
28
- foobar_invoked.should == true
29
- end
30
-
31
- # TODO ensure closed / error event handlers are invoked
32
- # TODO ensure callbacks can be invoked over established connection w/ json-rpc notifications
33
- end
data/specs/util_spec.rb DELETED
@@ -1,46 +0,0 @@
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
@@ -1,32 +0,0 @@
1
- require 'rjr/web_node'
2
- require 'rjr/dispatcher'
3
-
4
- describe RJR::WebNode do
5
- it "should invoke and satisfy http requests" do
6
- server = RJR::WebNode.new :node_id => 'www', :host => 'localhost', :port => 9678
7
- client = RJR::WebNode.new
8
-
9
- foobar_invoked = false
10
- RJR::Dispatcher.init_handlers
11
- RJR::Dispatcher.add_handler('foobar') { |param|
12
- @client_ip.should == "127.0.0.1"
13
- #@client_port.should == 9678
14
- @rjr_node.should == server
15
- @rjr_node_id.should == 'www'
16
- @rjr_node_type.should == :web
17
- param.should == 'myparam'
18
- foobar_invoked = true
19
- 'retval'
20
- }
21
-
22
- server.listen
23
- sleep 1
24
-
25
- res = client.invoke_request 'http://localhost:9678', 'foobar', 'myparam'
26
- res.should == 'retval'
27
- server.halt
28
-
29
- server.join
30
- foobar_invoked.should == true
31
- end
32
- end
@@ -1,32 +0,0 @@
1
- require 'rjr/ws_node'
2
- require 'rjr/dispatcher'
3
-
4
- describe RJR::WSNode do
5
- it "should invoke and satisfy websocket requests" do
6
- server = RJR::WSNode.new :node_id => 'ws', :host => 'localhost', :port => 9876
7
- client = RJR::WSNode.new
8
-
9
- foobar_invoked = false
10
- RJR::Dispatcher.init_handlers
11
- RJR::Dispatcher.add_handler('foobar') { |param|
12
- @client_ip.should == "127.0.0.1"
13
- #@client_port.should == 9678
14
- @rjr_node.should == server
15
- @rjr_node_id.should == 'ws'
16
- @rjr_node_type.should == :ws
17
- param.should == 'myparam'
18
- foobar_invoked = true
19
- 'retval'
20
- }
21
-
22
- server.listen
23
- sleep 1
24
- res = client.invoke_request 'ws://localhost:9876', 'foobar', 'myparam'
25
- res.should == 'retval'
26
- server.halt
27
- server.join
28
- foobar_invoked.should == true
29
- end
30
-
31
- # TODO ensure closed / error event handlers are invoked
32
- end
File without changes
File without changes