dripdrop 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe "zmq xreq/xrep" do
4
+ def xr_tranceive_messages(to_send,&block)
5
+ responses = []
6
+ req = nil
7
+ rep = nil
8
+
9
+ @ddn = DripDrop::Node.new do
10
+ addr = rand_addr
11
+
12
+ rep = zmq_xrep(addr, :bind)
13
+ req = zmq_xreq(addr, :connect)
14
+
15
+ rep.on_recv do |identities,seq,message|
16
+ yield(identities,seq,message) if block
17
+ responses << {:identities => identities, :seq => seq, :message => message}
18
+ end
19
+
20
+ to_send.each {|message| req.send_message(message)}
21
+ end
22
+
23
+ @ddn.start
24
+ sleep 0.1
25
+ @ddn.stop
26
+
27
+ {:responses => responses, :handlers => {:req => req, :rep => rep}}
28
+ end
29
+ describe "basic sending and receiving" do
30
+ before(:all) do
31
+ @sent = []
32
+ 10.times {|i| @sent << DripDrop::Message.new("test-#{i}")}
33
+ xr_info = xr_tranceive_messages(@sent)
34
+ @responses = xr_info[:responses]
35
+ @req_handler = xr_info[:handlers][:req]
36
+ @rep_handler = xr_info[:handlers][:rep]
37
+ end
38
+
39
+ it "should receive all sent messages in order" do
40
+ @sent.zip(@responses).each do |sent,response|
41
+ sent.name.should == response[:message].name
42
+ end
43
+ end
44
+
45
+ it "should have a monotonically incrementing seq for responses" do
46
+ last_seq = 0
47
+ @responses.each do |resp|
48
+ resp[:seq].should == last_seq + 1
49
+ last_seq = resp[:seq]
50
+ end
51
+ end
52
+
53
+ it "should include the identity of the sending socket" do
54
+ @responses.each {|resp| resp[:identities].should_not be_nil}
55
+ end
56
+
57
+ it "should send responses back to the proper xreq sender" do
58
+ received_count = 0
59
+
60
+ ddn = DripDrop::Node.new do
61
+ addr = rand_addr
62
+
63
+ rep = zmq_xrep(addr, :bind)
64
+ req1 = zmq_xreq(addr, :connect)
65
+ req2 = zmq_xreq(addr, :connect)
66
+
67
+ rep.on_recv do |identities,seq,message|
68
+ rep.send_message(identities,seq,message)
69
+ end
70
+
71
+ r1_msg = DripDrop::Message.new("REQ1 Message")
72
+ r2_msg = DripDrop::Message.new("REQ2 Message")
73
+
74
+ 10.times do
75
+ req1.send_message(r1_msg) do |message|
76
+ received_count += 1
77
+ message.name.should == r1_msg.name
78
+ end
79
+ req2.send_message(r2_msg) do |message|
80
+ received_count += 1
81
+ message.name.should == r2_msg.name
82
+ end
83
+ end
84
+ end
85
+ ddn.start
86
+ sleep 0.2
87
+ ddn.stop rescue nil #This should work...
88
+
89
+ received_count.should == 20
90
+ end
91
+ end
92
+ end
data/spec/node_spec.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe DripDrop::Node do
4
+ describe "initialization" do
5
+ before do
6
+ @ddn = DripDrop::Node.new {}
7
+ @ddn.start
8
+ sleep 0.1
9
+ end
10
+
11
+ it "should start EventMachine" do
12
+ EM.reactor_running?.should be_true
13
+ end
14
+
15
+ it "should start ZMQMachine" do
16
+ @ddn.zm_reactor.running?.should be_true
17
+ end
18
+
19
+ after do
20
+ @ddn.stop rescue nil
21
+ end
22
+ end
23
+
24
+ describe "shutdown" do
25
+ before do
26
+ @ddn = DripDrop::Node.new {}
27
+ @ddn.start
28
+ sleep 0.1
29
+ @ddn.stop
30
+ sleep 0.1
31
+ end
32
+
33
+ it "should stop EventMachine" do
34
+ EM.reactor_running?.should be_false
35
+ end
36
+
37
+ it "should stop ZMQMachine" do
38
+ @ddn.zm_reactor.running?.should be_false
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib dripdrop]))
2
+ Thread.abort_on_exception = true
3
+
4
+ def rand_addr
5
+ "tcp://127.0.0.1:#{rand(10_000) + 20_000}"
6
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dripdrop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
7
+ - 2
9
8
  - 0
10
- version: 0.1.0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Andrew Cholakian
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-05 00:00:00 -07:00
17
+ date: 2010-10-10 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -68,7 +64,6 @@ dependencies:
68
64
  requirements:
69
65
  - - ">="
70
66
  - !ruby/object:Gem::Version
71
- hash: 3
72
67
  segments:
73
68
  - 0
74
69
  version: "0"
@@ -93,14 +88,26 @@ files:
93
88
  - doc_img/topology.png
94
89
  - dripdrop.gemspec
95
90
  - example/agent_test.rb
91
+ - example/http.rb
96
92
  - example/pubsub.rb
97
93
  - example/pushpull.rb
94
+ - example/xreq_xrep.rb
95
+ - js/dripdrop.html
96
+ - js/dripdrop.js
97
+ - js/jack.js
98
+ - js/qunit.css
99
+ - js/qunit.js
98
100
  - lib/dripdrop.rb
99
101
  - lib/dripdrop/agent.rb
102
+ - lib/dripdrop/handlers/http.rb
100
103
  - lib/dripdrop/handlers/websockets.rb
101
104
  - lib/dripdrop/handlers/zeromq.rb
102
105
  - lib/dripdrop/message.rb
103
106
  - lib/dripdrop/node.rb
107
+ - spec/node/zmq_pushpull.rb
108
+ - spec/node/zmq_xrepxreq.rb
109
+ - spec/node_spec.rb
110
+ - spec/spec_helper.rb
104
111
  has_rdoc: true
105
112
  homepage: http://github.com/andrewvc/dripdrop
106
113
  licenses: []
@@ -115,7 +122,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
122
  requirements:
116
123
  - - ">="
117
124
  - !ruby/object:Gem::Version
118
- hash: 3
119
125
  segments:
120
126
  - 0
121
127
  version: "0"
@@ -124,7 +130,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
130
  requirements:
125
131
  - - ">="
126
132
  - !ruby/object:Gem::Version
127
- hash: 3
128
133
  segments:
129
134
  - 0
130
135
  version: "0"
@@ -135,5 +140,8 @@ rubygems_version: 1.3.7
135
140
  signing_key:
136
141
  specification_version: 3
137
142
  summary: 0MQ App Stats
138
- test_files: []
139
-
143
+ test_files:
144
+ - spec/node/zmq_pushpull.rb
145
+ - spec/node/zmq_xrepxreq.rb
146
+ - spec/node_spec.rb
147
+ - spec/spec_helper.rb