elementary-rpc 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f92f4aa5b2489be4f30f3bd8f1c36a005f59b554
4
- data.tar.gz: f876e99e9f8851fdb23802492f7f66428e0ab38e
3
+ metadata.gz: 69b9b5d2909967aae631ba36ee3209ada7a5f139
4
+ data.tar.gz: ee1e219ebba8f88da2da2d9141cd26166c97e497
5
5
  SHA512:
6
- metadata.gz: 5d3994a1a15f0313ab25ab9ff820a29076de9a88c852df1a7e4c1a1bb768e28359d1c6ad7bb7609581bab8b0cacb03d8f079492c33c4fc5692f6f29ef3d1e492
7
- data.tar.gz: fe24f7fc72437bf9bbd54fd394ee4448b44582449b8483af0fe3af0a00cd8bb8c4bd02273aa2ec857ca8bd7bbd616d69755542de82b9265cb139ef4d6f51fba4
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
- def initialize(hosts)
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
- @client = Faraday.new(:url => host_url) do |f|
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
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Elementary
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -21,60 +21,77 @@ describe Elementary::Connection do
21
21
  end
22
22
  end
23
23
 
24
- let(:connection) do
25
- described_class.new(Elementary::Rspec::Simple)
26
- end
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
- describe '#select_transport' do
29
- subject(:transport) { connection.select_transport }
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
- context 'by default' do
32
- it { should be_instance_of Elementary::Transport::HTTP }
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
- describe 'an error request', :type => :integration do
38
- describe 'rpc' do
39
- describe '#error' do
40
- subject(:response) { connection.rpc.error(request) }
41
- let(:request) { Elementary::Rspec::String.new(:data => 'rspec') }
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
- before :each do
44
- response.value
45
- end
59
+ before :each do
60
+ response.value
61
+ end
46
62
 
47
- it { should be_rejected }
63
+ it { should be_rejected }
64
+ end
48
65
  end
49
66
  end
50
- end
51
67
 
52
- describe 'an echo request', :type => :integration do
53
- after :each do
54
- Elementary.flush_middleware
55
- end
68
+ describe 'an echo request', :type => :integration do
69
+ after :each do
70
+ Elementary.flush_middleware
71
+ end
56
72
 
57
- describe 'rpc' do
58
- describe '#echo' do
59
- let(:request) { Elementary::Rspec::String.new(:data => 'rspec') }
60
- subject(:response) { connection.rpc.echo(request) }
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
- before :each do
63
- Elementary.use Elementary::Middleware::Dummy, :rspec => true
64
- expect_any_instance_of(Elementary::Middleware::Dummy).to \
65
- receive(:call).and_call_original
66
- end
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
- it 'should have a value containing the echoed string' do
69
- puts "Sending req #{Time.now.to_f}"
70
- expect(response).to be_instance_of Elementary::Future
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
- puts "Waiting for future #{Time.now.to_f}"
73
- value = response.value # Wait on the future
74
- puts "Future responded: #{Time.now.to_f}"
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
- expect(response).not_to be_rejected
77
- expect(value.data).to eql('rspec')
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
@@ -3,7 +3,8 @@ require 'elementary/transport/http'
3
3
 
4
4
  describe Elementary::Transport::HTTP do
5
5
  let(:hosts) { [] }
6
- let(:http) { described_class.new(hosts) }
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.0.0
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-06-30 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler