zss 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +27 -0
- data/Gemfile.lock +6 -1
- data/README.md +2 -1
- data/Rakefile +2 -0
- data/lib/zss/client.rb +49 -0
- data/lib/zss/socket.rb +81 -0
- data/lib/zss/version.rb +1 -1
- data/spec/integration/client_spec.rb +38 -0
- data/spec/integration/socket_spec.rb +39 -0
- data/spec/spec_helper.rb +8 -3
- data/spec/unit/client_spec.rb +155 -0
- data/spec/unit/socket_spec.rb +135 -0
- data/zss.gemspec +2 -0
- metadata +64 -24
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTZlYWU5ZmYzMDE4YmJkYmNiOWQ1OTJmOTYxZTU1ZWM0MWNjMDgzNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjlhYWQxYmRkM2NkMmI4NWMxMDA0NjRmMmFhOTQyZDhhOGUyZmZiZg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODVhMzQ4ZGI1MzEwM2M4NGViM2YyMmM2MmQ3ZWIyODkyMWI0ZjgwMDZlNThk
|
10
|
+
NTUzOGEzM2MxNTJhZmVkYjJmMGVkMmEzOGY3ZGE1YzE5NGYyMmQ4YzY5YjBm
|
11
|
+
YjBlMDRmMmIxNWM0NjM3ZDViMTI0ZjQyYzY2NDMxZDZhOTg4YjU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjFmNTEzMzJlYjNhODZiNjgxNGMxOTNjZDczYTc3NDg0ZjkzZDJiNGJjNDU1
|
14
|
+
M2UzNjgwNDUwZjEwM2VjODgzYjM3MDQ3MTdlOTk1ZjVlNTdiYjRlOGExYTEz
|
15
|
+
ZjRkNWYyYjhhZGQ4NjVkZmQ4OWNiZGY0ZTA5NGU4NDIzNjM1ZGE=
|
data/.travis.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache:
|
3
|
+
- bundler
|
4
|
+
- apt
|
5
|
+
rvm:
|
6
|
+
- 2.1.2
|
7
|
+
branches:
|
8
|
+
only:
|
9
|
+
- master
|
10
|
+
env:
|
11
|
+
global:
|
12
|
+
- ZSS_ENV=test
|
13
|
+
- DISPLAY=:99.0
|
14
|
+
before_install:
|
15
|
+
- sudo apt-get install libzmq3-dev
|
16
|
+
- gem install bundler --no-rdoc --no-ri 1>/dev/null
|
17
|
+
script:
|
18
|
+
- "bundle exec rspec"
|
19
|
+
addons:
|
20
|
+
code_climate:
|
21
|
+
repo_token:
|
22
|
+
secure: U6d5emmLhWdFAqrVgtHtXDs1lR2f40is89mZfOp1HbnTQKnClGbmCuEGfeHL8HbaMZjpxFb7g9Ery26E3g1gCsE82sP8SkD0qY46LbWlufRctZWsD4d+TZZZttqo2eNNObKkW5JbzW2pGiRqQb7RCfsxsOnqqhXl3uXVOHK24x4=
|
23
|
+
deploy:
|
24
|
+
provider: rubygems
|
25
|
+
api_key:
|
26
|
+
secure: OsOTnuz+qiZe4RY2hOhYsv46LJE7eQf3jZAX5oBBxsSaC6V91SgyHgl1mexMM6r1CPvgOlG4b33AU2Um9NIVrO11fwl/psSeh6zrMf46l5tmn+QCtjOuoM1jtKpomYAPXioH0KkZWoRcqPyNZemZx14YJQW0/fLtrc5xUS20Re0=
|
27
|
+
gemspec: zss.gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zss (0.0.
|
4
|
+
zss (0.0.1)
|
5
5
|
activesupport
|
6
6
|
ffi-rzmq
|
7
7
|
hashie
|
@@ -16,6 +16,9 @@ GEM
|
|
16
16
|
minitest (~> 5.1)
|
17
17
|
thread_safe (~> 0.1)
|
18
18
|
tzinfo (~> 1.1)
|
19
|
+
bump (0.5.0)
|
20
|
+
codeclimate-test-reporter (0.3.0)
|
21
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
19
22
|
coderay (1.1.0)
|
20
23
|
diff-lcs (1.2.5)
|
21
24
|
docile (1.1.5)
|
@@ -62,7 +65,9 @@ PLATFORMS
|
|
62
65
|
ruby
|
63
66
|
|
64
67
|
DEPENDENCIES
|
68
|
+
bump
|
65
69
|
bundler (~> 1.6)
|
70
|
+
codeclimate-test-reporter
|
66
71
|
pry
|
67
72
|
rake
|
68
73
|
rspec
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/pjanuario/zmq-service-suite-ruby.svg?branch=master)](https://travis-ci.org/pjanuario/zmq-service-suite-ruby)
|
2
2
|
[![Code Climate](https://codeclimate.com/github/pjanuario/zmq-service-suite-ruby.png)](https://codeclimate.com/github/pjanuario/zmq-service-suite-ruby)
|
3
|
-
[![Coverage](
|
3
|
+
[![Coverage](https://codeclimate.com/github/pjanuario/zmq-service-suite-ruby/coverage.png)](https://codeclimate.com/github/pjanuario/zmq-service-suite-ruby)
|
4
4
|
[![Dependency Status](https://gemnasium.com/pjanuario/zmq-service-suite-ruby.svg)](https://gemnasium.com/pjanuario/zmq-service-suite-ruby)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/zss.svg)](http://badge.fury.io/rb/zss)
|
5
6
|
|
6
7
|
# ZMQ SOA Suite - Ruby Client & Service
|
7
8
|
|
data/Rakefile
ADDED
data/lib/zss/client.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'zss/socket'
|
2
|
+
|
3
|
+
module ZSS
|
4
|
+
class Client
|
5
|
+
|
6
|
+
attr_reader :sid, :frontend, :identity, :timeout
|
7
|
+
|
8
|
+
def initialize sid, config = nil
|
9
|
+
@frontend = config.try(:frontend) || Configuration.default.frontend
|
10
|
+
@sid = sid.to_s.upcase
|
11
|
+
@identity = config.try(:identity) || "client"
|
12
|
+
@timeout = config.try(:timeout) || 1000
|
13
|
+
end
|
14
|
+
|
15
|
+
def call verb, payload = nil, headers: {}, timeout: nil
|
16
|
+
action = verb.to_s.upcase#.gsub('_', '/')
|
17
|
+
address = Message::Address.new(sid: sid, verb: action)
|
18
|
+
|
19
|
+
request = Message.new(
|
20
|
+
address: address,
|
21
|
+
headers: headers,
|
22
|
+
payload: payload)
|
23
|
+
|
24
|
+
response = socket.call(request)
|
25
|
+
fail ZSS::Error.new(response.status, response.payload) if response.is_error?
|
26
|
+
|
27
|
+
response.payload
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def method_missing method, payload = nil, headers: {}
|
33
|
+
# since we cannot use / on method names we replace _ with /
|
34
|
+
verb = method.to_s.gsub('_', '/')
|
35
|
+
call verb, payload, headers: headers
|
36
|
+
end
|
37
|
+
|
38
|
+
def socket
|
39
|
+
config = Hashie::Mash.new(
|
40
|
+
socket_address: frontend,
|
41
|
+
identity: identity,
|
42
|
+
timeout: timeout
|
43
|
+
)
|
44
|
+
|
45
|
+
Socket.new config
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/zss/socket.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'ffi-rzmq'
|
2
|
+
|
3
|
+
module ZSS
|
4
|
+
class Socket
|
5
|
+
|
6
|
+
class Error < StandardError; end
|
7
|
+
class TimeoutError < Socket::Error; end
|
8
|
+
|
9
|
+
attr_reader :timeout, :socket_address, :identity
|
10
|
+
|
11
|
+
def initialize config
|
12
|
+
@identity = config.identity
|
13
|
+
@timeout = config.timeout || 1000
|
14
|
+
@socket_address = config.socket_address
|
15
|
+
end
|
16
|
+
|
17
|
+
def call request, call_timeout = nil
|
18
|
+
fail Socket::Error, 'invalid request' unless request
|
19
|
+
|
20
|
+
response = nil
|
21
|
+
t = (call_timeout || timeout) / 1000.0
|
22
|
+
|
23
|
+
context do |ctx|
|
24
|
+
socket ctx do |sock|
|
25
|
+
begin
|
26
|
+
::Timeout.timeout t do
|
27
|
+
send_message sock, request
|
28
|
+
response = receive_message(sock)
|
29
|
+
end
|
30
|
+
rescue ::Timeout::Error
|
31
|
+
raise ZSS::Socket::TimeoutError, "call timeout after #{t}s"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def context
|
42
|
+
context = ZMQ::Context.create(1)
|
43
|
+
fail Socket::Error, 'failed to create context' unless context
|
44
|
+
yield context
|
45
|
+
ensure
|
46
|
+
check!(context.terminate) if context
|
47
|
+
end
|
48
|
+
|
49
|
+
def socket context
|
50
|
+
socket = context.socket ZMQ::DEALER
|
51
|
+
fail Socket::Error, 'failed to create socket' unless socket
|
52
|
+
socket.identity = "#{identity}##{SecureRandom.uuid}"
|
53
|
+
socket.setsockopt(ZMQ::LINGER, 0)
|
54
|
+
socket.bind(socket_address)
|
55
|
+
yield socket
|
56
|
+
ensure
|
57
|
+
check! socket.close if socket
|
58
|
+
end
|
59
|
+
|
60
|
+
def send_message socket, message
|
61
|
+
frames = message.to_frames
|
62
|
+
first = frames.shift
|
63
|
+
last = frames.pop
|
64
|
+
frames.each { |f| check! socket.send_string f.to_s, ZMQ::SNDMORE }
|
65
|
+
check! socket.send_string last
|
66
|
+
end
|
67
|
+
|
68
|
+
def receive_message socket
|
69
|
+
check! socket.recv_strings(frames = [])
|
70
|
+
Message.parse frames
|
71
|
+
end
|
72
|
+
|
73
|
+
def check! result_code
|
74
|
+
return if ZMQ::Util.resultcode_ok? result_code
|
75
|
+
|
76
|
+
fail Socket::Error, "operation failed, errno [#{ZMQ::Util.errno}], " +
|
77
|
+
"description [#{ZMQ::Util.error_string}]"
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
data/lib/zss/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spec_broker_helper'
|
3
|
+
require 'zss/client'
|
4
|
+
|
5
|
+
describe ZSS::Client do
|
6
|
+
include BrokerHelper
|
7
|
+
|
8
|
+
let(:broker_frontend) { "ipc://socket_test" }
|
9
|
+
|
10
|
+
let(:config) do
|
11
|
+
Hashie::Mash.new(
|
12
|
+
frontend: broker_frontend,
|
13
|
+
identity: "spec_client",
|
14
|
+
timeout: 500
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
after :each do
|
19
|
+
@broker.terminate if @broker
|
20
|
+
@broker = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
subject do
|
24
|
+
described_class.new(:pong, config)
|
25
|
+
end
|
26
|
+
|
27
|
+
it('returns service response') do
|
28
|
+
@broker = run_broker(broker_frontend) do |msg|
|
29
|
+
expect(msg.payload).to eq("ping")
|
30
|
+
msg.status = 200
|
31
|
+
msg.payload = "PONG"
|
32
|
+
end
|
33
|
+
|
34
|
+
result = subject.ping("ping", headers: { something: "data" })
|
35
|
+
expect(result).to eq("PONG")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spec_broker_helper'
|
3
|
+
require 'zss/socket'
|
4
|
+
|
5
|
+
describe ZSS::Socket do
|
6
|
+
include BrokerHelper
|
7
|
+
|
8
|
+
let(:broker_frontend) { "ipc://socket_test" }
|
9
|
+
|
10
|
+
let(:config) { Hashie::Mash.new(socket_address: broker_frontend) }
|
11
|
+
|
12
|
+
let(:address) { ZSS::Message::Address.new(sid: "service", verb: "verb") }
|
13
|
+
|
14
|
+
let(:message) { ZSS::Message.new(address: address, payload: "PING") }
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
@broker.terminate if @broker
|
18
|
+
@broker = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
describe("#call") do
|
22
|
+
|
23
|
+
subject { ZSS::Socket.new(config) }
|
24
|
+
|
25
|
+
it('returns service response') do
|
26
|
+
@broker = run_broker(broker_frontend) do |msg|
|
27
|
+
msg.status = 200
|
28
|
+
msg.payload = "PONG"
|
29
|
+
end
|
30
|
+
|
31
|
+
result = subject.call(message)
|
32
|
+
expect(result).to be_truthy
|
33
|
+
expect(result.payload).to eq("PONG")
|
34
|
+
expect(result.status).to eq(200)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
ENV['ZSS_ENV'] ||= 'test'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
4
|
+
require "codeclimate-test-reporter"
|
5
|
+
CodeClimate::TestReporter.start
|
6
|
+
else
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/spec/'
|
10
|
+
end
|
6
11
|
end
|
7
12
|
|
8
13
|
$:.push '.'
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'zss/client'
|
3
|
+
|
4
|
+
describe ZSS::Client do
|
5
|
+
|
6
|
+
describe('#ctor') do
|
7
|
+
|
8
|
+
it('returns a client with default config') do
|
9
|
+
subject = described_class.new(:pong)
|
10
|
+
expect(subject.frontend).to eq(ZSS::Configuration.default.frontend)
|
11
|
+
expect(subject.identity).to eq("client")
|
12
|
+
expect(subject.timeout).to eq(1000)
|
13
|
+
end
|
14
|
+
|
15
|
+
it('returns a client with config') do
|
16
|
+
config = Hashie::Mash.new(
|
17
|
+
frontend: "socket",
|
18
|
+
identity: "identity",
|
19
|
+
timeout: 2000
|
20
|
+
)
|
21
|
+
subject = described_class.new(:pong, config)
|
22
|
+
expect(subject.frontend).to eq("socket")
|
23
|
+
expect(subject.identity).to eq("identity")
|
24
|
+
expect(subject.timeout).to eq(2000)
|
25
|
+
end
|
26
|
+
|
27
|
+
it('returns a client with sid') do
|
28
|
+
subject = described_class.new(:pong)
|
29
|
+
expect(subject.sid).to eq("PONG")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe("#call") do
|
35
|
+
|
36
|
+
subject do
|
37
|
+
described_class.new(:pong)
|
38
|
+
end
|
39
|
+
|
40
|
+
it('creates a socket with configs') do
|
41
|
+
socket = double('socket').as_null_object
|
42
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
43
|
+
allow(socket).to receive(:call) do |msg|
|
44
|
+
msg.status = 200
|
45
|
+
msg
|
46
|
+
end
|
47
|
+
expect(ZSS::Socket).to receive(:new)
|
48
|
+
.with(
|
49
|
+
Hashie::Mash.new(
|
50
|
+
socket_address: ZSS::Configuration.default.frontend,
|
51
|
+
identity: "client",
|
52
|
+
timeout: 1000
|
53
|
+
)
|
54
|
+
)
|
55
|
+
subject.call(:ping)
|
56
|
+
end
|
57
|
+
|
58
|
+
context('on success') do
|
59
|
+
|
60
|
+
it('calls pong service') do
|
61
|
+
socket = double('socket')
|
62
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
63
|
+
expect(socket).to receive(:call) do |msg|
|
64
|
+
expect(msg).to be_truthy
|
65
|
+
expect(msg.address.sid).to eq("PONG")
|
66
|
+
expect(msg.address.verb).to eq("PING")
|
67
|
+
expect(msg.payload).to eq("ping")
|
68
|
+
msg.status = 200
|
69
|
+
msg
|
70
|
+
end
|
71
|
+
result = subject.call(:ping, "ping")
|
72
|
+
end
|
73
|
+
|
74
|
+
it('calls pong service with headers') do
|
75
|
+
socket = double('socket')
|
76
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
77
|
+
expect(socket).to receive(:call) do |msg|
|
78
|
+
expect(msg).to be_truthy
|
79
|
+
expect(msg.headers[:something]).to eq("something")
|
80
|
+
msg.status = 200
|
81
|
+
msg
|
82
|
+
end
|
83
|
+
result = subject.call(:ping, "ping", headers: { something: "something" })
|
84
|
+
end
|
85
|
+
|
86
|
+
it('returns service message from pong service') do
|
87
|
+
socket = double('socket')
|
88
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
89
|
+
allow(socket).to receive(:call) do |msg|
|
90
|
+
msg.payload = "pong"
|
91
|
+
msg.status = 200
|
92
|
+
msg
|
93
|
+
end
|
94
|
+
result = subject.call(:ping, "ping")
|
95
|
+
expect(result).to eq("pong")
|
96
|
+
end
|
97
|
+
|
98
|
+
context('with implicit method implementation') do
|
99
|
+
|
100
|
+
it('returns service message from pong service') do
|
101
|
+
socket = double('socket')
|
102
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
103
|
+
allow(socket).to receive(:call) do |msg|
|
104
|
+
msg.payload = "pong"
|
105
|
+
msg.status = 200
|
106
|
+
msg
|
107
|
+
end
|
108
|
+
result = subject.ping("ping")
|
109
|
+
expect(result).to eq("pong")
|
110
|
+
end
|
111
|
+
|
112
|
+
it('calls pong service with special verb') do
|
113
|
+
socket = double('socket')
|
114
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
115
|
+
expect(socket).to receive(:call) do |msg|
|
116
|
+
expect(msg).to be_truthy
|
117
|
+
expect(msg.address.sid).to eq("PONG")
|
118
|
+
expect(msg.address.verb).to eq("PONG/PING")
|
119
|
+
|
120
|
+
msg.payload = "pong"
|
121
|
+
msg.status = 200
|
122
|
+
msg
|
123
|
+
end
|
124
|
+
result = subject.pong_ping("ping")
|
125
|
+
expect(result).to eq("pong")
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
context('on error') do
|
133
|
+
|
134
|
+
it('raise service error') do
|
135
|
+
socket = double('socket')
|
136
|
+
allow(ZSS::Socket).to receive(:new) { socket }
|
137
|
+
allow(socket).to receive(:call) do |msg|
|
138
|
+
msg.payload = Hashie::Mash.new(
|
139
|
+
userMessage: "user info",
|
140
|
+
developerMessage: "dev info"
|
141
|
+
)
|
142
|
+
msg.status = 500
|
143
|
+
msg
|
144
|
+
end
|
145
|
+
|
146
|
+
expect { subject.call(:ping, "ping") }.to raise_exception(ZSS::Error) do |error|
|
147
|
+
expect(error.code).to eq(500)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'zss/socket'
|
3
|
+
require 'ffi-rzmq'
|
4
|
+
|
5
|
+
describe ZSS::Socket do
|
6
|
+
|
7
|
+
let(:broker_frontend) { "ipc://socket_spec" }
|
8
|
+
|
9
|
+
let :config do
|
10
|
+
Hashie::Mash.new(
|
11
|
+
socket_address: broker_frontend,
|
12
|
+
identity: 'socket-identity',
|
13
|
+
timeout: 300
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:address) { ZSS::Message::Address.new(sid: "service", verb: "verb") }
|
18
|
+
|
19
|
+
let(:message) { ZSS::Message.new(address: address, payload: "PING") }
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
allow(SecureRandom).to receive(:uuid) { "uuid" }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe("#call") do
|
26
|
+
|
27
|
+
subject { ZSS::Socket.new(config) }
|
28
|
+
|
29
|
+
context('open ZMQ Socket') do
|
30
|
+
|
31
|
+
it('with dealer type') do
|
32
|
+
context = double('ZMQ::Context').as_null_object
|
33
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
34
|
+
allow(context).to receive(:socket) { nil }
|
35
|
+
expect(context).to receive(:socket).with(ZMQ::DEALER)
|
36
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
37
|
+
end
|
38
|
+
|
39
|
+
it('with identity set') do
|
40
|
+
context = double('ZMQ::Context').as_null_object
|
41
|
+
socket = double('ZMQ::Socket').as_null_object
|
42
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
43
|
+
allow(context).to receive(:socket) { socket }
|
44
|
+
allow(socket).to receive(:send_string) { -1 }
|
45
|
+
expect(socket).to receive(:identity=).with("socket-identity#uuid")
|
46
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
47
|
+
end
|
48
|
+
|
49
|
+
it('with linger set to 0') do
|
50
|
+
context = double('ZMQ::Context').as_null_object
|
51
|
+
socket = double('ZMQ::Socket').as_null_object
|
52
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
53
|
+
allow(context).to receive(:socket) { socket }
|
54
|
+
allow(socket).to receive(:send_string) { -1 }
|
55
|
+
expect(socket).to receive(:setsockopt).with(ZMQ::LINGER, 0)
|
56
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
57
|
+
end
|
58
|
+
|
59
|
+
it('bind to frontend') do
|
60
|
+
context = double('ZMQ::Context').as_null_object
|
61
|
+
socket = double('ZMQ::Socket').as_null_object
|
62
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
63
|
+
allow(context).to receive(:socket) { socket }
|
64
|
+
allow(socket).to receive(:send_string) { -1 }
|
65
|
+
expect(socket).to receive(:bind).with(broker_frontend)
|
66
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context('on error') do
|
72
|
+
|
73
|
+
it('raises Socket::Error on invalid request') do
|
74
|
+
expect { subject.call(nil) }.
|
75
|
+
to raise_exception(ZSS::Socket::Error)
|
76
|
+
end
|
77
|
+
|
78
|
+
it('raises ::Timeout::Error on subject timeout') do
|
79
|
+
expect { subject.call(message) }.
|
80
|
+
to raise_exception(ZSS::Socket::TimeoutError, "call timeout after 0.3s")
|
81
|
+
end
|
82
|
+
|
83
|
+
it('raises ::Timeout::Error on call timeout') do
|
84
|
+
expect { subject.call(message, 200) }.
|
85
|
+
to raise_exception(ZSS::Socket::TimeoutError, "call timeout after 0.2s")
|
86
|
+
end
|
87
|
+
|
88
|
+
it('raises Socket::Error on invalid context') do
|
89
|
+
allow(ZMQ::Context).to receive(:create) { nil }
|
90
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
91
|
+
end
|
92
|
+
|
93
|
+
it('raises Socket::Error on invalid socket') do
|
94
|
+
context = double('ZMQ::Context').as_null_object
|
95
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
96
|
+
allow(context).to receive(:socket) { nil }
|
97
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
98
|
+
end
|
99
|
+
|
100
|
+
it('raises Socket::Error on invalid send send_string') do
|
101
|
+
context = double('ZMQ::Context').as_null_object
|
102
|
+
socket = double('ZMQ::Socket').as_null_object
|
103
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
104
|
+
allow(context).to receive(:socket) { socket }
|
105
|
+
allow(socket).to receive(:send_string) { -1 }
|
106
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
context('clean up resources') do
|
112
|
+
|
113
|
+
it('terminates context') do
|
114
|
+
context = double('ZMQ::Context').as_null_object
|
115
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
116
|
+
allow(context).to receive(:socket) { nil }
|
117
|
+
expect(context).to receive(:terminate)
|
118
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
119
|
+
end
|
120
|
+
|
121
|
+
it('closes socket') do
|
122
|
+
context = double('ZMQ::Context').as_null_object
|
123
|
+
socket = double('ZMQ::Socket').as_null_object
|
124
|
+
allow(ZMQ::Context).to receive(:create) { context }
|
125
|
+
allow(context).to receive(:socket) { socket }
|
126
|
+
allow(socket).to receive(:send_string) { -1 }
|
127
|
+
expect(socket).to receive(:close)
|
128
|
+
expect { subject.call(message) }.to raise_exception(ZSS::Socket::Error)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
data/zss.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'rspec'
|
23
23
|
spec.add_development_dependency 'pry'
|
24
24
|
spec.add_development_dependency 'simplecov'
|
25
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
26
|
+
spec.add_development_dependency 'bump'
|
25
27
|
|
26
28
|
spec.add_dependency 'msgpack'
|
27
29
|
spec.add_dependency 'ffi-rzmq'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Januário
|
@@ -14,126 +14,154 @@ dependencies:
|
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
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: :development
|
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: rspec
|
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: :development
|
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: pry
|
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: simplecov
|
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
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bump
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: msgpack
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- -
|
115
|
+
- - ! '>='
|
88
116
|
- !ruby/object:Gem::Version
|
89
117
|
version: '0'
|
90
118
|
type: :runtime
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- -
|
122
|
+
- - ! '>='
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: ffi-rzmq
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
|
-
- -
|
129
|
+
- - ! '>='
|
102
130
|
- !ruby/object:Gem::Version
|
103
131
|
version: '0'
|
104
132
|
type: :runtime
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
|
-
- -
|
136
|
+
- - ! '>='
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: activesupport
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
|
-
- -
|
143
|
+
- - ! '>='
|
116
144
|
- !ruby/object:Gem::Version
|
117
145
|
version: '0'
|
118
146
|
type: :runtime
|
119
147
|
prerelease: false
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
121
149
|
requirements:
|
122
|
-
- -
|
150
|
+
- - ! '>='
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: hashie
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
|
-
- -
|
157
|
+
- - ! '>='
|
130
158
|
- !ruby/object:Gem::Version
|
131
159
|
version: '0'
|
132
160
|
type: :runtime
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
|
-
- -
|
164
|
+
- - ! '>='
|
137
165
|
- !ruby/object:Gem::Version
|
138
166
|
version: '0'
|
139
167
|
description: ZeroMQ SOA Suite
|
@@ -143,27 +171,35 @@ executables: []
|
|
143
171
|
extensions: []
|
144
172
|
extra_rdoc_files: []
|
145
173
|
files:
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
174
|
+
- .gitignore
|
175
|
+
- .rspec
|
176
|
+
- .rvmrc.example
|
177
|
+
- .travis.yml
|
149
178
|
- Gemfile
|
150
179
|
- Gemfile.lock
|
151
180
|
- LICENSE
|
152
181
|
- README.md
|
182
|
+
- Rakefile
|
153
183
|
- lib/zss.rb
|
184
|
+
- lib/zss/client.rb
|
154
185
|
- lib/zss/configuration.rb
|
155
186
|
- lib/zss/environment.rb
|
156
187
|
- lib/zss/error.rb
|
157
188
|
- lib/zss/message.rb
|
158
189
|
- lib/zss/message/message_address.rb
|
159
190
|
- lib/zss/message/message_type.rb
|
191
|
+
- lib/zss/socket.rb
|
160
192
|
- lib/zss/version.rb
|
193
|
+
- spec/integration/client_spec.rb
|
194
|
+
- spec/integration/socket_spec.rb
|
161
195
|
- spec/spec_broker_helper.rb
|
162
196
|
- spec/spec_helper.rb
|
197
|
+
- spec/unit/client_spec.rb
|
163
198
|
- spec/unit/environment_spec.rb
|
164
199
|
- spec/unit/error_spec.rb
|
165
200
|
- spec/unit/message_address_spec.rb
|
166
201
|
- spec/unit/message_spec.rb
|
202
|
+
- spec/unit/socket_spec.rb
|
167
203
|
- zss.gemspec
|
168
204
|
homepage: https://github.com/pjanuario/zmq-service-suite-ruby
|
169
205
|
licenses:
|
@@ -175,12 +211,12 @@ require_paths:
|
|
175
211
|
- lib
|
176
212
|
required_ruby_version: !ruby/object:Gem::Requirement
|
177
213
|
requirements:
|
178
|
-
- -
|
214
|
+
- - ! '>='
|
179
215
|
- !ruby/object:Gem::Version
|
180
216
|
version: '0'
|
181
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
218
|
requirements:
|
183
|
-
- -
|
219
|
+
- - ! '>='
|
184
220
|
- !ruby/object:Gem::Version
|
185
221
|
version: '0'
|
186
222
|
requirements: []
|
@@ -190,9 +226,13 @@ signing_key:
|
|
190
226
|
specification_version: 4
|
191
227
|
summary: ZeroMQ SOA Suite
|
192
228
|
test_files:
|
229
|
+
- spec/integration/client_spec.rb
|
230
|
+
- spec/integration/socket_spec.rb
|
193
231
|
- spec/spec_broker_helper.rb
|
194
232
|
- spec/spec_helper.rb
|
233
|
+
- spec/unit/client_spec.rb
|
195
234
|
- spec/unit/environment_spec.rb
|
196
235
|
- spec/unit/error_spec.rb
|
197
236
|
- spec/unit/message_address_spec.rb
|
198
237
|
- spec/unit/message_spec.rb
|
238
|
+
- spec/unit/socket_spec.rb
|