celluloid-zmq 0.15.0 → 0.16.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/celluloid-zmq.gemspec +1 -1
- data/lib/celluloid/zmq.rb +11 -4
- data/lib/celluloid/zmq/sockets.rb +16 -0
- data/lib/celluloid/zmq/version.rb +1 -1
- data/lib/celluloid/zmq/waker.rb +1 -0
- data/log/test.log +5000 -0
- data/spec/celluloid/zmq/socket_spec.rb +15 -0
- data/spec/celluloid/zmq_spec.rb +152 -0
- data/spec/spec_helper.rb +14 -0
- metadata +30 -29
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'celluloid/rspec'
|
3
|
+
|
4
|
+
describe Celluloid::ZMQ::Socket, actor_system: :global do
|
5
|
+
|
6
|
+
it "allows setting and getting ZMQ options on the socket" do
|
7
|
+
socket = Celluloid::ZMQ::RepSocket.new
|
8
|
+
socket.set(::ZMQ::IDENTITY, "Identity")
|
9
|
+
|
10
|
+
identity = socket.get(::ZMQ::IDENTITY)
|
11
|
+
|
12
|
+
identity.should == "Identity"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Celluloid::ZMQ do
|
4
|
+
before { @sockets = [] }
|
5
|
+
after { @sockets.each(&:close) }
|
6
|
+
|
7
|
+
def connect(socket, index=0)
|
8
|
+
socket.connect("inproc://celluloid-spec-#{index}")
|
9
|
+
@sockets << socket
|
10
|
+
socket
|
11
|
+
end
|
12
|
+
|
13
|
+
def bind(socket, index=0)
|
14
|
+
socket.bind("inproc://celluloid-spec-#{index}")
|
15
|
+
@sockets << socket
|
16
|
+
socket
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".init" do
|
20
|
+
it "inits a ZMQ context", :no_init do
|
21
|
+
Celluloid::ZMQ.init
|
22
|
+
server = bind(Celluloid::ZMQ.context.socket(::ZMQ::REQ))
|
23
|
+
client = connect(Celluloid::ZMQ.context.socket(::ZMQ::REP))
|
24
|
+
|
25
|
+
server.send_string("hello world")
|
26
|
+
message = ""
|
27
|
+
client.recv_string(message)
|
28
|
+
message.should eq("hello world")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can set ZMQ context manually", :no_init do
|
32
|
+
context = ::ZMQ::Context.new(1)
|
33
|
+
begin
|
34
|
+
Celluloid::ZMQ.context = context
|
35
|
+
Celluloid::ZMQ.context.should eq(context)
|
36
|
+
ensure
|
37
|
+
context.terminate
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an error when trying to access context and it isn't initialized", :no_init do
|
42
|
+
expect { Celluloid::ZMQ.context }.to raise_error(Celluloid::ZMQ::UninitializedError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises an error when trying to access context after it is terminated" do
|
46
|
+
Celluloid::ZMQ.terminate
|
47
|
+
expect { Celluloid::ZMQ.context }.to raise_error(Celluloid::ZMQ::UninitializedError)
|
48
|
+
Celluloid::ZMQ.init
|
49
|
+
Celluloid::ZMQ.context.should_not be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe Celluloid::ZMQ::RepSocket do
|
54
|
+
let(:actor) do
|
55
|
+
Class.new do
|
56
|
+
include Celluloid::ZMQ
|
57
|
+
|
58
|
+
finalizer :close_socket
|
59
|
+
|
60
|
+
def initialize(index)
|
61
|
+
@socket = Celluloid::ZMQ::RepSocket.new
|
62
|
+
@socket.connect("inproc://celluloid-spec-#{index}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def say_hi
|
66
|
+
"Hi!"
|
67
|
+
end
|
68
|
+
|
69
|
+
def fetch
|
70
|
+
@socket.read
|
71
|
+
end
|
72
|
+
|
73
|
+
def close_socket
|
74
|
+
@socket.close
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "receives messages" do
|
80
|
+
server = bind(Celluloid::ZMQ.context.socket(::ZMQ::REQ))
|
81
|
+
client = actor.new(0)
|
82
|
+
|
83
|
+
server.send_string("hello world")
|
84
|
+
result = client.fetch
|
85
|
+
result.should eq("hello world")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "suspends actor while waiting for message" do
|
89
|
+
server = bind(Celluloid::ZMQ.context.socket(::ZMQ::REQ))
|
90
|
+
client = actor.new(0)
|
91
|
+
|
92
|
+
result = client.future.fetch
|
93
|
+
client.say_hi.should eq("Hi!")
|
94
|
+
server.send_string("hello world")
|
95
|
+
result.value.should eq("hello world")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe Celluloid::ZMQ::ReqSocket do
|
100
|
+
let(:actor) do
|
101
|
+
Class.new do
|
102
|
+
include Celluloid::ZMQ
|
103
|
+
|
104
|
+
finalizer :close_socket
|
105
|
+
|
106
|
+
def initialize(index)
|
107
|
+
@socket = Celluloid::ZMQ::ReqSocket.new
|
108
|
+
@socket.connect("inproc://celluloid-spec-#{index}")
|
109
|
+
end
|
110
|
+
|
111
|
+
def say_hi
|
112
|
+
"Hi!"
|
113
|
+
end
|
114
|
+
|
115
|
+
def send(message)
|
116
|
+
@socket.write(message)
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
def close_socket
|
121
|
+
@socket.close
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "sends messages" do
|
127
|
+
client = bind(Celluloid::ZMQ.context.socket(::ZMQ::REP))
|
128
|
+
server = actor.new(0)
|
129
|
+
|
130
|
+
server.send("hello world")
|
131
|
+
|
132
|
+
message = ""
|
133
|
+
client.recv_string(message)
|
134
|
+
message.should eq("hello world")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "suspends actor while waiting for message to be sent" do
|
138
|
+
client = bind(Celluloid::ZMQ.context.socket(::ZMQ::REP))
|
139
|
+
server = actor.new(0)
|
140
|
+
|
141
|
+
result = server.future.send("hello world")
|
142
|
+
|
143
|
+
server.say_hi.should eq("Hi!")
|
144
|
+
|
145
|
+
message = ""
|
146
|
+
client.recv_string(message)
|
147
|
+
message.should eq("hello world")
|
148
|
+
|
149
|
+
result.value.should be_true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,3 +6,17 @@ require 'celluloid/zmq'
|
|
6
6
|
|
7
7
|
logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a')
|
8
8
|
Celluloid.logger = Logger.new(logfile)
|
9
|
+
|
10
|
+
Celluloid.shutdown_timeout = 1
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
|
15
|
+
config.around do |ex|
|
16
|
+
Celluloid::ZMQ.init(1) unless example.metadata[:no_init]
|
17
|
+
Celluloid.boot
|
18
|
+
ex.run
|
19
|
+
Celluloid.shutdown
|
20
|
+
Celluloid::ZMQ.terminate
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-zmq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.15.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.15.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ffi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ffi-rzmq
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Celluloid bindings to the ffi-rzmq library
|
@@ -87,28 +87,27 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
-
|
90
|
+
- ".gitignore"
|
91
91
|
- CHANGES.md
|
92
|
-
- examples/publish_subscribe.rb
|
93
92
|
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- celluloid-zmq.gemspec
|
97
|
+
- examples/publish_subscribe.rb
|
98
|
+
- lib/celluloid/zmq.rb
|
94
99
|
- lib/celluloid/zmq/mailbox.rb
|
95
100
|
- lib/celluloid/zmq/reactor.rb
|
96
101
|
- lib/celluloid/zmq/sockets.rb
|
97
102
|
- lib/celluloid/zmq/version.rb
|
98
103
|
- lib/celluloid/zmq/waker.rb
|
99
|
-
- lib/celluloid/zmq.rb
|
100
|
-
- LICENSE.txt
|
101
104
|
- log/test.log
|
102
105
|
- logo.png
|
103
|
-
- pkg/celluloid-zmq-0.14.0.gem
|
104
|
-
- pkg/celluloid-zmq-0.14.0.pre.gem
|
105
|
-
- pkg/celluloid-zmq-0.15.0.pre.gem
|
106
|
-
- Rakefile
|
107
|
-
- README.md
|
108
106
|
- spec/celluloid/zmq/actor_spec.rb
|
109
107
|
- spec/celluloid/zmq/mailbox_spec.rb
|
108
|
+
- spec/celluloid/zmq/socket_spec.rb
|
109
|
+
- spec/celluloid/zmq_spec.rb
|
110
110
|
- spec/spec_helper.rb
|
111
|
-
- .gitignore
|
112
111
|
homepage: http://github.com/celluloid/celluloid-zmq
|
113
112
|
licenses: []
|
114
113
|
metadata: {}
|
@@ -118,17 +117,17 @@ require_paths:
|
|
118
117
|
- lib
|
119
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
119
|
requirements:
|
121
|
-
- -
|
120
|
+
- - ">="
|
122
121
|
- !ruby/object:Gem::Version
|
123
122
|
version: '0'
|
124
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
124
|
requirements:
|
126
|
-
- -
|
125
|
+
- - ">"
|
127
126
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
127
|
+
version: 1.3.1
|
129
128
|
requirements: []
|
130
129
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.0
|
130
|
+
rubygems_version: 2.2.0
|
132
131
|
signing_key:
|
133
132
|
specification_version: 4
|
134
133
|
summary: Celluloid::ZMQ provides concurrent Celluloid actors that can listen for 0MQ
|
@@ -136,5 +135,7 @@ summary: Celluloid::ZMQ provides concurrent Celluloid actors that can listen for
|
|
136
135
|
test_files:
|
137
136
|
- spec/celluloid/zmq/actor_spec.rb
|
138
137
|
- spec/celluloid/zmq/mailbox_spec.rb
|
138
|
+
- spec/celluloid/zmq/socket_spec.rb
|
139
|
+
- spec/celluloid/zmq_spec.rb
|
139
140
|
- spec/spec_helper.rb
|
140
|
-
- .gitignore
|
141
|
+
- ".gitignore"
|