elementary-rpc 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/elementary/connection.rb +5 -1
- data/lib/elementary/transport/http.rb +10 -2
- data/lib/elementary/version.rb +1 -1
- data/spec/connection_spec.rb +56 -39
- data/spec/transport/http_spec.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69b9b5d2909967aae631ba36ee3209ada7a5f139
|
4
|
+
data.tar.gz: ee1e219ebba8f88da2da2d9141cd26166c97e497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 171be7ee2734311afa37c71fa8f71ed65908c8aafc859988c226789272485c6d86f74d08e5cdadb4fe061fff057fdaea01a3c2240cc370547e1f5e69e5da9a9c
|
7
|
+
data.tar.gz: 6f25161ef2b97092eb75442d167b2a42289e55047d766b754b835714ef6b994a72db3dd78173daf321c8af192bbfc66337631fb80a8fd9b23d5a609fc0cb4241
|
@@ -18,6 +18,9 @@ module Elementary
|
|
18
18
|
# in the +Elementary::Transport+ module
|
19
19
|
# @optiosn opts [Array] :hosts An array of {:host => 'localhost', :port =>
|
20
20
|
# 8080} hashes to instruct the connection
|
21
|
+
# @option opts [Hash] :transport_options A +Hash+ of request options that
|
22
|
+
# will be passed down to the transport layer. This will depend on what
|
23
|
+
# options are available by the underlying transport
|
21
24
|
def initialize(service, opts={})
|
22
25
|
if service.nil? || service.superclass != Protobuf::Rpc::Service
|
23
26
|
raise ArgumentError,
|
@@ -27,6 +30,7 @@ module Elementary
|
|
27
30
|
@service = service
|
28
31
|
@transport = opts[:transport]
|
29
32
|
@hosts = opts[:hosts] || DEFAULT_HOSTS
|
33
|
+
@transport_opts = opts[:transport_options] || {}
|
30
34
|
end
|
31
35
|
|
32
36
|
def rpc
|
@@ -34,7 +38,7 @@ module Elementary
|
|
34
38
|
end
|
35
39
|
|
36
40
|
def select_transport
|
37
|
-
Elementary::Transport::HTTP.new(@hosts)
|
41
|
+
Elementary::Transport::HTTP.new(@hosts, @transport_opts)
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -12,8 +12,15 @@ module Elementary
|
|
12
12
|
ERROR_HEADER_MSG = 'x-protobuf-error'
|
13
13
|
ERROR_HEADER_CODE = 'x-protobuf-error-reason'
|
14
14
|
|
15
|
-
|
15
|
+
# Create a HTTP transport object for sending protobuf objects to the
|
16
|
+
# service host names enumerated in +hosts+
|
17
|
+
#
|
18
|
+
# @param [Array] hosts A collection of host declarations ({:host => '',
|
19
|
+
# :port => 0, :prefix => '/'})
|
20
|
+
# @param [Hash] opts Options to be passed directly into Faraday.
|
21
|
+
def initialize(hosts, opts={})
|
16
22
|
@hosts = hosts
|
23
|
+
@options = opts
|
17
24
|
end
|
18
25
|
|
19
26
|
def call(service, rpc_method, *params)
|
@@ -51,7 +58,8 @@ module Elementary
|
|
51
58
|
def client
|
52
59
|
return @client if @client
|
53
60
|
|
54
|
-
|
61
|
+
faraday_options = @options.merge({:url => host_url})
|
62
|
+
@client = Faraday.new(faraday_options) do |f|
|
55
63
|
f.response :logger
|
56
64
|
f.adapter :net_http_persistent
|
57
65
|
end
|
data/lib/elementary/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -21,60 +21,77 @@ describe Elementary::Connection do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
context 'with a simple RPC service' do
|
25
|
+
let(:opts) { {} }
|
26
|
+
let(:connection) do
|
27
|
+
described_class.new(Elementary::Rspec::Simple, opts)
|
28
|
+
end
|
29
|
+
describe '#select_transport' do
|
30
|
+
subject(:transport) { connection.select_transport }
|
31
|
+
|
32
|
+
context 'by default' do
|
33
|
+
it { should be_instance_of Elementary::Transport::HTTP }
|
34
|
+
end
|
27
35
|
|
28
|
-
|
29
|
-
|
36
|
+
context 'with transport_options' do
|
37
|
+
let(:opts) { {:transport_options => transport_opts} }
|
38
|
+
let(:transport_opts) do
|
39
|
+
{
|
40
|
+
:timeout => 3,
|
41
|
+
:open_timeout => 1,
|
42
|
+
}
|
43
|
+
end
|
30
44
|
|
31
|
-
|
32
|
-
|
45
|
+
it 'should pass request_options to the transport' do
|
46
|
+
expect(Elementary::Transport::HTTP).to receive(:new).with(anything, transport_opts).and_call_original
|
47
|
+
expect(transport).to be_instance_of Elementary::Transport::HTTP
|
48
|
+
end
|
49
|
+
end
|
33
50
|
end
|
34
|
-
end
|
35
51
|
|
36
52
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
describe 'an error request', :type => :integration do
|
54
|
+
describe 'rpc' do
|
55
|
+
describe '#error' do
|
56
|
+
subject(:response) { connection.rpc.error(request) }
|
57
|
+
let(:request) { Elementary::Rspec::String.new(:data => 'rspec') }
|
42
58
|
|
43
|
-
|
44
|
-
|
45
|
-
|
59
|
+
before :each do
|
60
|
+
response.value
|
61
|
+
end
|
46
62
|
|
47
|
-
|
63
|
+
it { should be_rejected }
|
64
|
+
end
|
48
65
|
end
|
49
66
|
end
|
50
|
-
end
|
51
67
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
68
|
+
describe 'an echo request', :type => :integration do
|
69
|
+
after :each do
|
70
|
+
Elementary.flush_middleware
|
71
|
+
end
|
56
72
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
73
|
+
describe 'rpc' do
|
74
|
+
describe '#echo' do
|
75
|
+
let(:request) { Elementary::Rspec::String.new(:data => 'rspec') }
|
76
|
+
subject(:response) { connection.rpc.echo(request) }
|
61
77
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
78
|
+
before :each do
|
79
|
+
Elementary.use Elementary::Middleware::Dummy, :rspec => true
|
80
|
+
expect_any_instance_of(Elementary::Middleware::Dummy).to \
|
81
|
+
receive(:call).and_call_original
|
82
|
+
end
|
67
83
|
|
68
|
-
|
69
|
-
|
70
|
-
|
84
|
+
it 'should have a value containing the echoed string' do
|
85
|
+
puts "Sending req #{Time.now.to_f}"
|
86
|
+
expect(response).to be_instance_of Elementary::Future
|
71
87
|
|
72
|
-
|
73
|
-
|
74
|
-
|
88
|
+
puts "Waiting for future #{Time.now.to_f}"
|
89
|
+
value = response.value # Wait on the future
|
90
|
+
puts "Future responded: #{Time.now.to_f}"
|
75
91
|
|
76
|
-
|
77
|
-
|
92
|
+
expect(response).not_to be_rejected
|
93
|
+
expect(value.data).to eql('rspec')
|
94
|
+
end
|
78
95
|
end
|
79
96
|
end
|
80
97
|
end
|
data/spec/transport/http_spec.rb
CHANGED
@@ -3,7 +3,8 @@ require 'elementary/transport/http'
|
|
3
3
|
|
4
4
|
describe Elementary::Transport::HTTP do
|
5
5
|
let(:hosts) { [] }
|
6
|
-
let(:
|
6
|
+
let(:opts) { {} }
|
7
|
+
let(:http) { described_class.new(hosts, opts) }
|
7
8
|
|
8
9
|
describe '#host_url' do
|
9
10
|
subject(:host_url) { http.send(:host_url) }
|
@@ -56,5 +57,18 @@ describe Elementary::Transport::HTTP do
|
|
56
57
|
# Object identity!
|
57
58
|
expect(first).to be second
|
58
59
|
end
|
60
|
+
|
61
|
+
context 'with options passed to the initializer' do
|
62
|
+
let(:opts) do
|
63
|
+
{
|
64
|
+
:request => {:timeout => 3, :open_timeout => 1},
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should pass options to Faraday.new' do
|
69
|
+
expect(Faraday).to receive(:new).with(hash_including(opts)).and_call_original
|
70
|
+
expect(client).to be_instance_of Faraday::Connection
|
71
|
+
end
|
72
|
+
end
|
59
73
|
end
|
60
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elementary-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R. Tyler Croy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|