ezmq 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/doc/_index.html CHANGED
@@ -188,7 +188,7 @@
188
188
  </div>
189
189
 
190
190
  <div id="footer">
191
- Generated on Mon Feb 2 15:37:50 2015 by
191
+ Generated on Tue Feb 3 09:55:04 2015 by
192
192
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
193
193
  0.8.7.6 (ruby-2.0.0).
194
194
  </div>
data/doc/file.README.html CHANGED
@@ -84,7 +84,9 @@
84
84
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
85
85
 
86
86
  <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
87
- <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
87
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
88
+ <span class='id identifier rubyid_message'>message</span>
89
+ <span class='kw'>end</span>
88
90
  </code></pre>
89
91
 
90
92
  <h2>Synchronous Client Request</h2>
@@ -118,7 +120,9 @@
118
120
  <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
119
121
 
120
122
  <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>decode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
121
- <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
123
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
124
+ <span class='id identifier rubyid_message'>message</span>
125
+ <span class='kw'>end</span>
122
126
  </code></pre>
123
127
 
124
128
  <h2>JSON Synchronous Client Request</h2>
@@ -154,7 +158,9 @@
154
158
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
155
159
 
156
160
  <span class='id identifier rubyid_subscriber'>subscriber</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='period'>.</span><span class='const'>Subscriber</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>topic:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>foorever</span><span class='tstring_end'>&#39;</span></span>
157
- <span class='id identifier rubyid_subscriber'>subscriber</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
161
+ <span class='id identifier rubyid_subscriber'>subscriber</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_topic'>topic</span><span class='op'>|</span>
162
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_topic'>topic</span> <span class='embexpr_end'>}</span><span class='tstring_content'>] </span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_message'>message</span> <span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
163
+ <span class='kw'>end</span>
158
164
  </code></pre>
159
165
 
160
166
  <h2>Pipeline Work Generator</h2>
@@ -208,7 +214,9 @@
208
214
  <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
209
215
 
210
216
  <span class='id identifier rubyid_collector'>collector</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Puller</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>port:</span> <span class='int'>5556</span>
211
- <span class='id identifier rubyid_collector'>collector</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
217
+ <span class='id identifier rubyid_collector'>collector</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
218
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_message'>message</span>
219
+ <span class='kw'>end</span>
212
220
  </code></pre>
213
221
 
214
222
  <h1>Operating System Notes</h1>
@@ -230,7 +238,7 @@ sudo aptitude install libzmq3-dev
230
238
  </div></div>
231
239
 
232
240
  <div id="footer">
233
- Generated on Mon Feb 2 15:37:50 2015 by
241
+ Generated on Tue Feb 3 09:55:04 2015 by
234
242
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
235
243
  0.8.7.6 (ruby-2.0.0).
236
244
  </div>
data/doc/index.html CHANGED
@@ -84,7 +84,9 @@
84
84
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
85
85
 
86
86
  <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
87
- <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
87
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
88
+ <span class='id identifier rubyid_message'>message</span>
89
+ <span class='kw'>end</span>
88
90
  </code></pre>
89
91
 
90
92
  <h2>Synchronous Client Request</h2>
@@ -118,7 +120,9 @@
118
120
  <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
119
121
 
120
122
  <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>decode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
121
- <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
123
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
124
+ <span class='id identifier rubyid_message'>message</span>
125
+ <span class='kw'>end</span>
122
126
  </code></pre>
123
127
 
124
128
  <h2>JSON Synchronous Client Request</h2>
@@ -154,7 +158,9 @@
154
158
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
155
159
 
156
160
  <span class='id identifier rubyid_subscriber'>subscriber</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='period'>.</span><span class='const'>Subscriber</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>topic:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>foorever</span><span class='tstring_end'>&#39;</span></span>
157
- <span class='id identifier rubyid_subscriber'>subscriber</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
161
+ <span class='id identifier rubyid_subscriber'>subscriber</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_topic'>topic</span><span class='op'>|</span>
162
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_topic'>topic</span> <span class='embexpr_end'>}</span><span class='tstring_content'>] </span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_message'>message</span> <span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
163
+ <span class='kw'>end</span>
158
164
  </code></pre>
159
165
 
160
166
  <h2>Pipeline Work Generator</h2>
@@ -208,7 +214,9 @@
208
214
  <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
209
215
 
210
216
  <span class='id identifier rubyid_collector'>collector</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Puller</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>port:</span> <span class='int'>5556</span>
211
- <span class='id identifier rubyid_collector'>collector</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
217
+ <span class='id identifier rubyid_collector'>collector</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
218
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_message'>message</span>
219
+ <span class='kw'>end</span>
212
220
  </code></pre>
213
221
 
214
222
  <h1>Operating System Notes</h1>
@@ -230,7 +238,7 @@ sudo aptitude install libzmq3-dev
230
238
  </div></div>
231
239
 
232
240
  <div id="footer">
233
- Generated on Mon Feb 2 15:37:50 2015 by
241
+ Generated on Tue Feb 3 09:55:04 2015 by
234
242
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
235
243
  0.8.7.6 (ruby-2.0.0).
236
244
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Mon Feb 2 15:37:50 2015 by
106
+ Generated on Tue Feb 3 09:55:04 2015 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.6 (ruby-2.0.0).
109
109
  </div>
data/ezmq.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ezmq'
3
- gem.version = '0.3.7'
3
+ gem.version = '0.4.0'
4
4
  gem.licenses = 'MIT'
5
5
  gem.authors = ['Chris Olstrom']
6
6
  gem.email = 'chris@olstrom.com'
@@ -24,4 +24,8 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency 'churn'
25
25
  gem.add_development_dependency 'yard'
26
26
  gem.add_development_dependency 'inch'
27
+ gem.add_development_dependency 'kintama'
28
+ gem.add_development_dependency 'simplecov'
29
+ gem.add_development_dependency 'coveralls'
30
+ gem.add_development_dependency 'codeclimate-test-reporter'
27
31
  end
data/lib/ezmq/context.rb CHANGED
@@ -10,7 +10,7 @@ module EZMQ
10
10
  # allow multiple sockets to share access to system resources, and an
11
11
  # entire context can be terminated, closing all sockets within it.
12
12
  #
13
- # Contexts are useful when dealing with the 'inproc' transport / protocol.
13
+ # Contexts are useful when dealing with the :inproc transport.
14
14
  # Any sockets that need to communicate in-process must share a context.
15
15
  #
16
16
  # @return [Context] a new instance of Context.
data/lib/ezmq/pair.rb CHANGED
@@ -22,15 +22,15 @@ module EZMQ
22
22
  end
23
23
 
24
24
  # Returns a pair of EZMQ::Pair sockets connected to each other.
25
- #
25
+ #
26
26
  # @param [Hash] options optional parameters.
27
27
  # @see EZMQ::Socket EZMQ::Socket for optional parameters.
28
- #
28
+ #
29
29
  # @return [Array<EZMQ::Pair>]
30
30
  #
31
31
  def self.create_linked_pair(**options)
32
32
  options[:context] ||= EZMQ::Context.new
33
- options[:protocol] ||= 'inproc'
33
+ options[:transport] ||= :inproc
34
34
  options[:address] ||= options[:context].context.address
35
35
  %i(bind connect).map do |mode|
36
36
  EZMQ::Pair.new mode, options
data/lib/ezmq/socket.rb CHANGED
@@ -16,10 +16,10 @@ module EZMQ
16
16
  # (one will be created if not provided).
17
17
  # @option options [lambda] encode how to encode messages.
18
18
  # @option options [lambda] decode how to decode messages.
19
- # @option options [String] protocol ('tcp') protocol for transport.
19
+ # @option options [Symbol] transport (:tcp) transport for transport.
20
20
  # @option options [String] address ('127.0.0.1') address for endpoint.
21
21
  # @option options [Fixnum] port (5555) port for endpoint.
22
- # @note port is ignored unless protocol is one of 'tcp', 'pgm' or 'epgm'.
22
+ # @note port is ignored unless transport is one of :tcp, :pgm or :epgm
23
23
  #
24
24
  # @return [Socket] a new instance of Socket.
25
25
  #
@@ -29,7 +29,7 @@ module EZMQ
29
29
  @socket = @context.socket type
30
30
  @encode = options[:encode] || -> m { m }
31
31
  @decode = options[:decode] || -> m { m }
32
- endpoint = options.select { |k, _| %i(protocol address port).include? k }
32
+ endpoint = options.select { |k, _| %i(transport address port).include? k }
33
33
  method(mode).call endpoint
34
34
  end
35
35
 
@@ -76,37 +76,33 @@ module EZMQ
76
76
  # @note This method can be called as #bind, in which case it binds to the
77
77
  # specified address instead.
78
78
  #
79
- # @param [String] protocol ('tcp') protocol for transport.
79
+ # @param [Symbol] transport (:tcp) transport for transport.
80
80
  # @param [String] address ('127.0.0.1') address for endpoint.
81
81
  # @note Binding to 'localhost' is not consistent on all platforms.
82
82
  # Prefer '127.0.0.1' instead.
83
83
  # @param [Fixnum] port (5555) port for endpoint.
84
- # @note port is ignored unless protocol is one of 'tcp', 'pgm' or 'epgm'.
84
+ # @note port is ignored unless transport is one of :tcp, :pgm or :epgm
85
85
  #
86
86
  # @return [Boolean] was connection successful?
87
87
  #
88
- def connect(protocol: 'tcp', address: '127.0.0.1', port: 5555)
89
- endpoint = "#{ protocol }://#{ address }"
90
- endpoint = "#{ endpoint }:#{ port }" if %w(tcp pgm epgm).include? protocol
88
+ def connect(transport: :tcp, address: '127.0.0.1', port: 5555)
89
+ endpoint = "#{ transport }://#{ address }"
90
+ endpoint << ":#{ port }" if %i(tcp pgm epgm).include? transport
91
91
  @socket.method(__callee__).call(endpoint) == 0
92
92
  end
93
93
 
94
94
  alias_method :bind, :connect
95
95
 
96
- # By default, waits for a message and prints it to STDOUT.
96
+ # Like receive, but doesn't stop at one message.
97
97
  #
98
98
  # @yield message passes the message received to the block.
99
99
  # @yieldparam [String] message the message received.
100
100
  #
101
101
  # @return [void]
102
102
  #
103
- def listen
103
+ def listen(&block)
104
104
  loop do
105
- if block_given?
106
- yield receive
107
- else
108
- puts receive
109
- end
105
+ block.call receive
110
106
  end
111
107
  end
112
108
  end
@@ -46,7 +46,7 @@ module EZMQ
46
46
  end
47
47
  end
48
48
 
49
- # By default, waits for a message and prints it to STDOUT.
49
+ # Like receive, but doesn't stop at one message.
50
50
  #
51
51
  # @yield [message, topic] passes the message body and topic to the block.
52
52
  # @yieldparam [String] message the message received.
@@ -54,14 +54,9 @@ module EZMQ
54
54
  #
55
55
  # @return [void]
56
56
  #
57
- def listen
57
+ def listen(&block)
58
58
  loop do
59
- if block_given?
60
- yield(*receive)
61
- else
62
- message, topic = receive
63
- puts "#{ topic } #{ message }"
64
- end
59
+ block.call(*receive)
65
60
  end
66
61
  end
67
62
 
data/tests/ezmq.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
5
+
6
+ require 'simplecov'
7
+ require 'coveralls'
8
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter
11
+ ]
12
+ SimpleCov.command_name 'Kintama'
13
+ SimpleCov.start { add_filter '/tests/' }
14
+
15
+ require 'kintama'
16
+ require 'timeout'
17
+ require 'json'
18
+
19
+ require_relative '../lib/ezmq'
20
+ require_relative 'ezmq/context'
21
+ require_relative 'ezmq/socket'
22
+ require_relative 'ezmq/request'
23
+ require_relative 'ezmq/reply'
24
+ require_relative 'ezmq/publish'
25
+ require_relative 'ezmq/subscribe'
26
+ require_relative 'ezmq/push'
27
+ require_relative 'ezmq/pull'
28
+ require_relative 'ezmq/pair'
@@ -0,0 +1,9 @@
1
+ context 'Contexts' do
2
+ setup do
3
+ @context = EZMQ::Context.new
4
+ end
5
+
6
+ should 'instantiate properly' do
7
+ assert_kind_of EZMQ::Context, @context
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ context 'Paired sockets' do
2
+ setup do
3
+ @bound, @connected = EZMQ.create_linked_pair
4
+ end
5
+
6
+ should 'initialize properly' do
7
+ assert_kind_of EZMQ::Socket, @bound
8
+ assert_kind_of EZMQ::Socket, @connected
9
+ end
10
+
11
+ should 'return the length of messages they send' do
12
+ assert_equal 7, @connected.send('message')
13
+ end
14
+
15
+ should 'return the contents of messages they receive' do
16
+ @connected.send 'message'
17
+ assert_equal 'message', @bound.receive
18
+ end
19
+
20
+ should 'yield the contents of messages they receive, if given a block' do
21
+ @bound.send 'message'
22
+ assert_equal 'message', @connected.receive { |m| m }
23
+ end
24
+
25
+ should 'block if no message is present' do
26
+ assert_raises Timeout::Error do
27
+ Timeout.timeout(0.1) do
28
+ @connected.receive
29
+ end
30
+ end
31
+ end
32
+
33
+ should 'receive multiple messages if listening' do
34
+ 3.times { @bound.send 'message' }
35
+ messages = []
36
+ begin
37
+ Timeout.timeout(0.1) do
38
+ @connected.listen do |message|
39
+ messages << message
40
+ end
41
+ end
42
+ rescue Timeout::Error
43
+ assert_equal 3, messages.size
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'Paired sockets with encoding/decoding' do
49
+ setup do
50
+ e = -> message { JSON.dump message }
51
+ d = -> message { JSON.load message }
52
+ @bound, @connected = EZMQ.create_linked_pair encoding: e, decoding: d
53
+ end
54
+
55
+ should 'return the length of messages they send' do
56
+ assert_equal 7, @connected.send('message')
57
+ end
58
+
59
+ should 'return the contents of messages they receive' do
60
+ @connected.send 'message'
61
+ assert_equal 'message', @bound.receive
62
+ end
63
+ end
@@ -0,0 +1,19 @@
1
+ context 'Publishers' do
2
+ setup do
3
+ @context = EZMQ::Context.new
4
+ options = { transport: :inproc, address: 'test', context: @context }
5
+ @publisher = EZMQ::Publisher.new options
6
+ @subscriber = EZMQ::Subscriber.new options
7
+ Thread.new do
8
+ socket.receive
9
+ end
10
+ end
11
+
12
+ should 'return the length of messages they send (without a topic)' do
13
+ assert_equal 8, @publisher.send('message')
14
+ end
15
+
16
+ should 'return the length of messages they send (with a topic)' do
17
+ assert_equal 8, @publisher.send('message')
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ context 'Pullers' do
2
+ setup do
3
+ @context = EZMQ::Context.new
4
+ options = { transport: :inproc, address: 'test', context: @context }
5
+ @pusher = EZMQ::Pusher.new options
6
+ @puller = EZMQ::Puller.new options
7
+ Thread.new do
8
+ @pusher.send 'message'
9
+ end
10
+ end
11
+
12
+ should 'return the contents of messages they receive' do
13
+ assert_equal 'message', @puller.receive
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ context 'Pushers' do
2
+ setup do
3
+ @context = EZMQ::Context.new
4
+ options = { transport: :inproc, address: 'test', context: @context }
5
+ @pusher = EZMQ::Pusher.new options
6
+ @puller = EZMQ::Puller.new options
7
+ end
8
+
9
+ should 'return the length of messages they send' do
10
+ assert_equal 7, @pusher.send('message')
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ context 'Servers' do
2
+ setup do
3
+ @context = EZMQ::Context.new
4
+ options = { transport: :inproc, address: 'test', context: @context }
5
+ @server = EZMQ::Server.new options
6
+ @client = EZMQ::Client.new options
7
+ Thread.new do
8
+ @client.request 'message'
9
+ end
10
+ end
11
+
12
+ should 'yield the contents of a request, if given a block' do
13
+ assert_nothing_raised do
14
+ Timeout.timeout(0.1) do
15
+ @server.listen do |request|
16
+ assert_equal request, 'message'
17
+ break
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ should 'return the length of messages they send' do
24
+ @server.receive
25
+ assert_equal 7, @server.send('message')
26
+ end
27
+
28
+ should 'return the contents of a request they receive' do
29
+ assert_equal 'message', @server.receive
30
+ end
31
+
32
+ should 'yield the contents of reply, if given a block' do
33
+ assert_equal 'message', @server.receive { |m| m }
34
+ end
35
+ end