dripdrop 0.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.document +5 -0
  2. data/.gitignore +31 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +20 -0
  5. data/README.md +164 -0
  6. data/Rakefile +16 -0
  7. data/dripdrop.gemspec +37 -0
  8. data/example/agent_test.rb +14 -0
  9. data/example/combined.rb +33 -0
  10. data/example/complex/README +22 -0
  11. data/example/complex/client.rb +20 -0
  12. data/example/complex/server.rb +102 -0
  13. data/example/complex/service.rb +8 -0
  14. data/example/complex/websocket.rb +442 -0
  15. data/example/http.rb +23 -0
  16. data/example/pubsub.rb +29 -0
  17. data/example/pushpull.rb +21 -0
  18. data/example/subclass.rb +54 -0
  19. data/example/xreq_xrep.rb +24 -0
  20. data/js/dripdrop.html +186 -0
  21. data/js/dripdrop.js +107 -0
  22. data/js/qunit.css +155 -0
  23. data/js/qunit.js +1261 -0
  24. data/lib/dripdrop.rb +2 -0
  25. data/lib/dripdrop/agent.rb +40 -0
  26. data/lib/dripdrop/handlers/base.rb +42 -0
  27. data/lib/dripdrop/handlers/http_client.rb +38 -0
  28. data/lib/dripdrop/handlers/http_server.rb +59 -0
  29. data/lib/dripdrop/handlers/mongrel2.rb +163 -0
  30. data/lib/dripdrop/handlers/websocket_server.rb +86 -0
  31. data/lib/dripdrop/handlers/zeromq.rb +300 -0
  32. data/lib/dripdrop/message.rb +190 -0
  33. data/lib/dripdrop/node.rb +351 -0
  34. data/lib/dripdrop/node/nodelet.rb +35 -0
  35. data/lib/dripdrop/version.rb +3 -0
  36. data/spec/gimite-websocket.rb +442 -0
  37. data/spec/message_spec.rb +94 -0
  38. data/spec/node/http_spec.rb +77 -0
  39. data/spec/node/nodelet_spec.rb +67 -0
  40. data/spec/node/routing_spec.rb +67 -0
  41. data/spec/node/websocket_spec.rb +98 -0
  42. data/spec/node/zmq_m2_spec.rb +77 -0
  43. data/spec/node/zmq_pushpull_spec.rb +54 -0
  44. data/spec/node/zmq_xrepxreq_spec.rb +108 -0
  45. data/spec/node_spec.rb +85 -0
  46. data/spec/spec_helper.rb +20 -0
  47. metadata +167 -0
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'set'
3
+
4
+ describe "zmq push/pull" do
5
+ def pp_send_messages(to_send)
6
+ responses = []
7
+ push = nil
8
+ pull = nil
9
+
10
+ @node = run_reactor(2) do
11
+ addr = rand_addr
12
+
13
+ push = zmq_push(addr, :bind)
14
+
15
+ pull1 = zmq_pull(addr, :connect)
16
+ pull2 = zmq_pull(addr, :connect)
17
+ pull = [pull1, pull2]
18
+
19
+ pull1.on_recv do |message|
20
+ message.head['recv_sock'] = 1
21
+ responses << message
22
+ end
23
+ pull2.on_recv do |message|
24
+ message.head['recv_sock'] = 2
25
+ responses << message
26
+ end
27
+
28
+ sleep 1
29
+
30
+ to_send.each {|message| push.send_message(message)}
31
+ end
32
+
33
+ {:responses => responses, :handlers => { :push => push, :pull => [pull] }}
34
+ end
35
+ describe "basic sending and receiving" do
36
+ before(:all) do
37
+ @sent = []
38
+ 10.times {|i| @sent << DripDrop::Message.new("test-#{i}")}
39
+ pp_info = pp_send_messages(@sent)
40
+ @responses = pp_info[:responses]
41
+ @push_handler = pp_info[:handlers][:push]
42
+ @pull_handlers = pp_info[:handlers][:pull]
43
+ end
44
+
45
+ it "should receive all sent messages" do
46
+ resp_names = @responses.map(&:name).inject(Set.new) {|memo,rn| memo << rn}
47
+ @sent.map(&:name).each {|sn| resp_names.should include(sn)}
48
+ end
49
+
50
+ it "should receive messages on both pull sockets" do
51
+ @responses.map {|r| r.head['recv_sock']}.uniq.sort.should == [1,2]
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe "zmq xreq/xrep" do
4
+ def xr_tranceive_messages(to_send,&block)
5
+ recvd = []
6
+ replied = []
7
+ req = nil
8
+ rep = nil
9
+
10
+ @node = run_reactor(1.5) do
11
+ addr = rand_addr
12
+
13
+ rep = zmq_xrep(addr, :bind)
14
+ req = zmq_xreq(addr, :connect)
15
+
16
+ rep.on_recv do |message,response|
17
+ recvd << {:message => message, :response => response}
18
+
19
+ response.send_message :name => 'response', :body => {'orig_name' => message.name}
20
+ end
21
+
22
+ to_send.each do |message|
23
+ req.send_message(message) do |reply_message|
24
+ replied << reply_message
25
+ end
26
+ end
27
+ end
28
+
29
+ {:recvd => recvd, :replied => replied, :handlers => {:req => req, :rep => rep}}
30
+ end
31
+ describe "basic sending and receiving" do
32
+ before(:all) do
33
+ @sent = []
34
+ 10.times {|i| @sent << DripDrop::Message.new("test-#{i}")}
35
+ xr_info = xr_tranceive_messages(@sent)
36
+ @recvd = xr_info[:recvd]
37
+ @replied = xr_info[:replied]
38
+ @req_handler = xr_info[:handlers][:req]
39
+ @rep_handler = xr_info[:handlers][:rep]
40
+ end
41
+
42
+ it "should receive all sent messages in order" do
43
+ @sent.zip(@recvd).each do |sent,recvd|
44
+ recvd[:message].should be_a(DripDrop::Message)
45
+ recvd[:message].name.should == sent.name
46
+ end
47
+ end
48
+
49
+ it "should receive a reply message for each sent message" do
50
+ @sent.zip(@replied).each do |sent, replied|
51
+ replied.should be_a(DripDrop::Message)
52
+ replied.body['orig_name'].should == sent.name
53
+ end
54
+ end
55
+
56
+ it "should pass a ZMQXrepHandler::Response object to the response callback" do
57
+ @recvd.each do |recvd_item|
58
+ recvd_item[:response].should be_instance_of(DripDrop::ZMQXRepHandler::Response)
59
+ end
60
+ end
61
+
62
+ it "should have a monotonically incrementing seq for responses" do
63
+ last_seq = 0
64
+ @recvd.each do |recvd_item|
65
+ recvd_item[:response].seq.should == last_seq + 1
66
+ last_seq = recvd_item[:response].seq
67
+ end
68
+ end
69
+
70
+ it "should include the identity of the sending socket" do
71
+ @recvd.each do |recvd_item|
72
+ recvd_item[:response].identities.should_not be_nil
73
+ end
74
+ end
75
+
76
+ it "should send responses back to the proper xreq sender" do
77
+ received_count = 0
78
+
79
+ run_reactor(0.5) do
80
+ addr = rand_addr
81
+
82
+ rep = zmq_xrep(addr, :bind)
83
+ req1 = zmq_xreq(addr, :connect)
84
+ req2 = zmq_xreq(addr, :connect)
85
+
86
+ rep.on_recv do |message,response|
87
+ response.send_message(message)
88
+ end
89
+
90
+ r1_msg = DripDrop::Message.new("REQ1 Message")
91
+ r2_msg = DripDrop::Message.new("REQ2 Message")
92
+
93
+ 10.times do
94
+ req1.send_message(r1_msg) do |message|
95
+ received_count += 1
96
+ message.name.should == r1_msg.name
97
+ end
98
+ req2.send_message(r2_msg) do |message|
99
+ received_count += 1
100
+ message.name.should == r2_msg.name
101
+ end
102
+ end
103
+ end
104
+
105
+ received_count.should == 20
106
+ end
107
+ end
108
+ end
data/spec/node_spec.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe DripDrop::Node do
4
+ shared_examples_for "all initialization methods" do
5
+ it "should start EventMachine" do
6
+ EM.reactor_running?.should be_true
7
+ end
8
+
9
+ it "should start ZMQMachine" do
10
+ pending "This is not repeatedly reliable"
11
+ @ddn.zm_reactor.running?.should be_true
12
+ end
13
+
14
+ it "should run the block" do
15
+ @reactor_ran.should be_true
16
+ end
17
+ end
18
+
19
+ #These tests break all subsequent ones,
20
+ #so require a special flag to test them
21
+ if ENV['DRIPDROP_INITSPEC'] == 'true'
22
+ describe "initialization with a block" do
23
+ before(:all) do
24
+ reactor_ran = false
25
+ @ddn = DripDrop::Node.new do
26
+ reactor_ran = true
27
+ end
28
+ @ddn.start
29
+ sleep 1
30
+
31
+ @reactor_ran = reactor_ran
32
+ end
33
+
34
+ it_should_behave_like "all initialization methods"
35
+ end
36
+
37
+ describe "initialization as a class" do
38
+ before(:all) do
39
+ class InitializationTest < DripDrop::Node
40
+ attr_accessor :reactor_ran
41
+ def action
42
+ @reactor_ran = true
43
+ end
44
+ end
45
+
46
+ @ddn = InitializationTest.new
47
+ @ddn.start
48
+ sleep 1
49
+
50
+ @reactor_ran = @ddn.reactor_ran
51
+ end
52
+
53
+ it_should_behave_like "all initialization methods"
54
+ end
55
+ end
56
+
57
+ describe "shutdown" do
58
+ before do
59
+ @ddn = DripDrop::Node.new {}
60
+ @ddn.start
61
+ sleep 0.1
62
+ @ddn.stop rescue nil
63
+ sleep 0.1
64
+ end
65
+
66
+ it "should stop EventMachine" do
67
+ EM.reactor_running?.should be_false
68
+ end
69
+ end
70
+
71
+ describe "exceptions in EM reactor" do
72
+ class TestException < StandardError; end
73
+
74
+ it "should rescue exceptions in the EM reactor" do
75
+ pending "Not sure why em-java doesn't support this" if RUBY_PLATFORM == 'java'
76
+ expectations = an_instance_of(TestException)
77
+ reactor = run_reactor do
78
+ self.class.should_receive(:error_handler).with(expectations)
79
+ EM.next_tick do
80
+ raise TestException, "foo"
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[. .. lib dripdrop]))
2
+ require 'set'
3
+
4
+ Thread.abort_on_exception = true
5
+
6
+ # Used to test websocket clients.
7
+ require 'gimite-websocket'
8
+
9
+ def rand_addr(scheme='tcp')
10
+ "#{scheme}://127.0.0.1:#{rand(10_000) + 20_000}"
11
+ end
12
+
13
+ def run_reactor(time=0.2,opts={},&block)
14
+ ddn = DripDrop::Node.new(opts,&block)
15
+ ddn.start
16
+ sleep time
17
+ ddn.stop
18
+ sleep 0.1
19
+ ddn
20
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dripdrop
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.10.0
6
+ platform: java
7
+ authors:
8
+ - Andrew Cholakian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-12 23:00:00 -08:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: eventmachine
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.12.10
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: em-websocket
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: em-zeromq
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.1
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.5.1
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.4.0
69
+ type: :development
70
+ version_requirements: *id005
71
+ description: Evented framework for ZeroMQ and EventMachine Apps.
72
+ email:
73
+ - andrew@andrewvc.com
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - LICENSE
80
+ - README.md
81
+ files:
82
+ - .document
83
+ - .gitignore
84
+ - Gemfile
85
+ - LICENSE
86
+ - README.md
87
+ - Rakefile
88
+ - dripdrop.gemspec
89
+ - example/agent_test.rb
90
+ - example/combined.rb
91
+ - example/complex/README
92
+ - example/complex/client.rb
93
+ - example/complex/server.rb
94
+ - example/complex/service.rb
95
+ - example/complex/websocket.rb
96
+ - example/http.rb
97
+ - example/pubsub.rb
98
+ - example/pushpull.rb
99
+ - example/subclass.rb
100
+ - example/xreq_xrep.rb
101
+ - js/dripdrop.html
102
+ - js/dripdrop.js
103
+ - js/qunit.css
104
+ - js/qunit.js
105
+ - lib/dripdrop.rb
106
+ - lib/dripdrop/agent.rb
107
+ - lib/dripdrop/handlers/base.rb
108
+ - lib/dripdrop/handlers/http_client.rb
109
+ - lib/dripdrop/handlers/http_server.rb
110
+ - lib/dripdrop/handlers/mongrel2.rb
111
+ - lib/dripdrop/handlers/websocket_server.rb
112
+ - lib/dripdrop/handlers/zeromq.rb
113
+ - lib/dripdrop/message.rb
114
+ - lib/dripdrop/node.rb
115
+ - lib/dripdrop/node/nodelet.rb
116
+ - lib/dripdrop/version.rb
117
+ - spec/gimite-websocket.rb
118
+ - spec/message_spec.rb
119
+ - spec/node/http_spec.rb
120
+ - spec/node/nodelet_spec.rb
121
+ - spec/node/routing_spec.rb
122
+ - spec/node/websocket_spec.rb
123
+ - spec/node/zmq_m2_spec.rb
124
+ - spec/node/zmq_pushpull_spec.rb
125
+ - spec/node/zmq_xrepxreq_spec.rb
126
+ - spec/node_spec.rb
127
+ - spec/spec_helper.rb
128
+ has_rdoc: true
129
+ homepage: https://github.com/andrewvc/dripdrop
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options: []
134
+
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: "0"
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: "0"
149
+ requirements: []
150
+
151
+ rubyforge_project: dripdrop
152
+ rubygems_version: 1.5.1
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: Evented framework for ZeroMQ and EventMachine Apps.
156
+ test_files:
157
+ - spec/gimite-websocket.rb
158
+ - spec/message_spec.rb
159
+ - spec/node/http_spec.rb
160
+ - spec/node/nodelet_spec.rb
161
+ - spec/node/routing_spec.rb
162
+ - spec/node/websocket_spec.rb
163
+ - spec/node/zmq_m2_spec.rb
164
+ - spec/node/zmq_pushpull_spec.rb
165
+ - spec/node/zmq_xrepxreq_spec.rb
166
+ - spec/node_spec.rb
167
+ - spec/spec_helper.rb