elementary-rpc 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +58 -1
- data/lib/elementary/connection.rb +1 -1
- data/lib/elementary/middleware/raise_on_status.rb +89 -0
- data/lib/elementary/transport/http.rb +2 -12
- data/lib/elementary/version.rb +1 -1
- data/spec/connection_spec.rb +31 -19
- data/spec/elementary_client_using_anti_pattern_spec.rb +27 -0
- data/spec/sample_elementary_client_spec.rb +97 -0
- data/spec/support/clients/base_elementary_client.rb +31 -0
- data/spec/support/clients/elementary_client_using_anti_pattern.rb +13 -0
- data/spec/support/clients/sample_elementary_client.rb +12 -0
- data/spec/support/proto/simpleservice.proto +2 -0
- data/spec/support/simpleservice.pb.rb +2 -0
- data/spec/support/simpleservice.rb +9 -0
- metadata +50 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bcc7e0abcf56202698d9b852c208a0fe8e5bf24
|
4
|
+
data.tar.gz: a7c0bcba0eee1e4a21bde6c30a9fa05fb6b68200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16397a5bece8062d1de4189cdb8355e8379aca6bdf6d2b4c6fbf799700cb5758fb452b3b241cbbe59256b60f3c4202115cb696f4555bc2d26cec49705db07cdb
|
7
|
+
data.tar.gz: 976eccc0b54ad4f07f6a607b05ef173f0fdb53bda76427c61e31d21dc835cea5da2ddd842358d47e206554267ad763f2f6c5542207d52c4be2c0af7475b7d493
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -46,8 +46,12 @@ Elementary.use(Elementary::Middleware::Statsd, :client => Statsd.instance)
|
|
46
46
|
|
47
47
|
# Create our Connection object that knows about our Protobuf service
|
48
48
|
# definition
|
49
|
-
|
49
|
+
def connection
|
50
|
+
return @connection if @connection
|
50
51
|
|
52
|
+
@connection = Elementary::Connection.new(Echoserv::Simple,
|
53
|
+
:hosts => hosts)
|
54
|
+
end
|
51
55
|
# Create a Protobuf message to send over RPC
|
52
56
|
msg = Echoserv::String.new(:data => str)
|
53
57
|
|
@@ -91,4 +95,57 @@ TODO: Write usage instructions here
|
|
91
95
|
|
92
96
|
### Testing
|
93
97
|
|
98
|
+
Install ha-proxy for your OS
|
99
|
+
For Mac OSX, good reference source is http://nepalonrails.tumblr.com/post/9674428224/setup-haproxy-for-development-environment-on-mac
|
100
|
+
Sample ha-proxy config
|
101
|
+
|
102
|
+
cat /etc/haproxy.conf
|
103
|
+
global
|
104
|
+
maxconn 4096
|
105
|
+
pidfile ~/tmp/haproxy-queue.pid
|
106
|
+
log /tmp/haproxy/log local0
|
107
|
+
log /tmp/haproxy/log local1 notice
|
108
|
+
|
109
|
+
defaults
|
110
|
+
log global
|
111
|
+
mode http
|
112
|
+
timeout connect 300000
|
113
|
+
timeout client 300000
|
114
|
+
timeout server 300000
|
115
|
+
maxconn 2000
|
116
|
+
option redispatch
|
117
|
+
retries 3
|
118
|
+
option httpclose
|
119
|
+
option httplog
|
120
|
+
option forwardfor
|
121
|
+
option httpchk HEAD / HTTP/1.0
|
122
|
+
|
123
|
+
frontend http-farm-1
|
124
|
+
bind :8080
|
125
|
+
default_backend app1latest
|
126
|
+
|
127
|
+
frontend http-farm-2
|
128
|
+
bind :8070
|
129
|
+
default_backend app2latest
|
130
|
+
|
131
|
+
backend app1latest
|
132
|
+
balance roundrobin
|
133
|
+
server localhost_8000 localhost:8000
|
134
|
+
|
135
|
+
backend app2latest
|
136
|
+
balance roundrobin
|
137
|
+
|
138
|
+
listen haproxyapp_admin:9100 127.0.0.1:9100
|
139
|
+
mode http
|
140
|
+
stats uri /
|
141
|
+
|
142
|
+
Start ha-proxy listener
|
143
|
+
haproxy -f /etc/haproxy.conf
|
144
|
+
|
145
|
+
Start the server hosting the rpc as below:
|
94
146
|
`bundle exec rpc_server start ./spec/support/simpleservice.rb -p 8000 --http`
|
147
|
+
|
148
|
+
Run the tests
|
149
|
+
`bundle exec rspec spec`
|
150
|
+
|
151
|
+
|
@@ -17,7 +17,7 @@ module Elementary
|
|
17
17
|
# @param [Hash] opts
|
18
18
|
# @options opts [Symbol] :transport Defaults to :http, must map to a class
|
19
19
|
# in the +Elementary::Transport+ module
|
20
|
-
# @
|
20
|
+
# @options opts [Array] :hosts An array of {:host => 'localhost', :port =>
|
21
21
|
# 8080} hashes to instruct the connection
|
22
22
|
# @option opts [Hash] :transport_options A +Hash+ of request options that
|
23
23
|
# will be passed down to the transport layer. This will depend on what
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Elementary
|
4
|
+
module Middleware
|
5
|
+
class HttpStatusError < StandardError; end
|
6
|
+
##
|
7
|
+
# Raise an exception for certain HTTP response status codes
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# Faraday.new do |conn|
|
12
|
+
# conn.request :raise_on_status
|
13
|
+
# conn.adapter ...
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# The above example will raise an HttpStatusError if the response
|
17
|
+
# contains a code in the range 300 through 600.
|
18
|
+
#
|
19
|
+
# You can also pair this with the retry middleware to attempt
|
20
|
+
# to recover from intermittent failures...
|
21
|
+
#
|
22
|
+
# Faraday.new do |conn|
|
23
|
+
# conn.request :retry, max: 2, interval: 0.05,
|
24
|
+
# interval_randomness: 0.5, backoff_factor: 2
|
25
|
+
# exceptions: [Faraday::TimeoutError, SecurityEvents::HttpStatusError]
|
26
|
+
# conn.request :raise_on_status
|
27
|
+
# conn.adapter ...
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# This example will do the same as the first, but the exception
|
31
|
+
# will be caught by the retry middleware and the request will be
|
32
|
+
# executed up to two more times before raising.
|
33
|
+
# NOTE: Middleware order matters here!
|
34
|
+
#
|
35
|
+
class RaiseOnStatus < Faraday::Middleware
|
36
|
+
|
37
|
+
DEFAULT_STATUS_ARRAY = [300..600]
|
38
|
+
ERROR_HEADER_MSG = 'x-protobuf-error'
|
39
|
+
ERROR_HEADER_CODE = 'x-protobuf-error-reason'
|
40
|
+
|
41
|
+
dependency do
|
42
|
+
require 'set'
|
43
|
+
end
|
44
|
+
|
45
|
+
# Public: Initialize middleware
|
46
|
+
def initialize(app)
|
47
|
+
super(app)
|
48
|
+
status_array ||= DEFAULT_STATUS_ARRAY
|
49
|
+
@status_set = status_option_array_to_set(status_array)
|
50
|
+
end
|
51
|
+
|
52
|
+
def call(request_env)
|
53
|
+
begin
|
54
|
+
@app.call(request_env).on_complete do |response_env|
|
55
|
+
status = response_env[:status]
|
56
|
+
if @status_set.include? status
|
57
|
+
error_msg = response_env[:response_headers][ERROR_HEADER_MSG]
|
58
|
+
error_code = response_env[:response_headers][ERROR_HEADER_CODE]
|
59
|
+
if error_msg
|
60
|
+
raise Elementary::Errors::RPCFailure, "Error #{error_code}: #{error_msg}"
|
61
|
+
else
|
62
|
+
method = response_env.method.to_s.upcase
|
63
|
+
url = response_env.url.to_s
|
64
|
+
raise HttpStatusError, "#{method} #{url} returned an HTTP response status of #{status}, so an exception was raised."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
rescue Faraday::ClientError => e
|
69
|
+
raise HttpStatusError, "#{e.message}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# Private: Construct a set of status codes.
|
76
|
+
#
|
77
|
+
# Accepts an array of Numeric and Enumerable objects which are added or merged to form a set.
|
78
|
+
def status_option_array_to_set(status_array)
|
79
|
+
set = Set.new
|
80
|
+
status_array.each do |item|
|
81
|
+
set.add item if item.is_a? Numeric
|
82
|
+
set.merge item if item.is_a? Enumerable
|
83
|
+
end
|
84
|
+
set
|
85
|
+
end
|
86
|
+
end
|
87
|
+
Faraday::Request.register_middleware :raise_on_status => lambda { RaiseOnStatus }
|
88
|
+
end
|
89
|
+
end
|
@@ -2,15 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'cgi'
|
3
3
|
require 'faraday'
|
4
4
|
require 'socket'
|
5
|
-
|
6
5
|
require 'elementary/errors'
|
7
6
|
require 'elementary/future'
|
8
7
|
|
9
8
|
module Elementary
|
10
9
|
module Transport
|
11
10
|
class HTTP
|
12
|
-
ERROR_HEADER_MSG = 'x-protobuf-error'
|
13
|
-
ERROR_HEADER_CODE = 'x-protobuf-error-reason'
|
14
11
|
|
15
12
|
# Create a HTTP transport object for sending protobuf objects to the
|
16
13
|
# service host names enumerated in +hosts+
|
@@ -24,6 +21,7 @@ module Elementary
|
|
24
21
|
end
|
25
22
|
|
26
23
|
def call(service, rpc_method, *params)
|
24
|
+
|
27
25
|
begin
|
28
26
|
response = client.post do |h|
|
29
27
|
path = "#{CGI.escape(service.name)}/#{rpc_method.method}"
|
@@ -31,16 +29,8 @@ module Elementary
|
|
31
29
|
h.body = params[0].encode
|
32
30
|
end
|
33
31
|
|
34
|
-
error_msg = response.headers[ERROR_HEADER_MSG]
|
35
|
-
error_code = response.headers[ERROR_HEADER_CODE]
|
36
|
-
|
37
|
-
if error_msg
|
38
|
-
raise Elementary::Errors::RPCFailure, "Error #{error_code}: #{error_msg}"
|
39
|
-
end
|
40
|
-
|
41
32
|
return rpc_method[:response_type].decode(response.body)
|
42
33
|
rescue StandardError => e
|
43
|
-
#puts "EXCEPTION #{e.inspect}"
|
44
34
|
raise
|
45
35
|
end
|
46
36
|
end
|
@@ -60,10 +50,10 @@ module Elementary
|
|
60
50
|
|
61
51
|
faraday_options = @options.merge({:url => host_url})
|
62
52
|
@client = Faraday.new(faraday_options) do |f|
|
53
|
+
f.request :raise_on_status
|
63
54
|
f.response :logger
|
64
55
|
f.adapter :net_http_persistent
|
65
56
|
end
|
66
|
-
|
67
57
|
return @client
|
68
58
|
end
|
69
59
|
end
|
data/lib/elementary/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -81,7 +81,6 @@ describe Elementary::Connection do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
84
|
describe 'an error request', :type => :integration do
|
86
85
|
describe 'rpc' do
|
87
86
|
describe '#error' do
|
@@ -105,26 +104,39 @@ describe Elementary::Connection do
|
|
105
104
|
describe 'rpc' do
|
106
105
|
describe '#echo' do
|
107
106
|
let(:request) { Elementary::Rspec::String.new(:data => 'rspec') }
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
107
|
+
context 'with http connection failure due to haproxy resolving service to wrong host or port' do
|
108
|
+
let(:opts) { { 'hosts' => [{'host' => 'localhost', 'port' => '8090'}] } }
|
109
|
+
subject(:response) { connection.rpc.echo(request) }
|
110
|
+
|
111
|
+
before :each do
|
112
|
+
response.value
|
113
|
+
end
|
114
|
+
|
115
|
+
it { should be_rejected }
|
116
|
+
it { should be_instance_of Elementary::Future }
|
117
|
+
it 'should have a connection refused reason' do
|
118
|
+
expect(response.reason).not_to be_nil
|
119
|
+
expect(response.reason.to_s).to eq("connection refused: localhost:8090")
|
120
|
+
end
|
114
121
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
context 'with http connection success' do
|
123
|
+
let(:opts) { { 'hosts' => [{'host' => 'localhost', 'port' => '8000'}] } }
|
124
|
+
subject(:response) { connection.rpc.echo(request) }
|
125
|
+
|
126
|
+
before :each do
|
127
|
+
Elementary.use Elementary::Middleware::Dummy, :rspec => true
|
128
|
+
expect_any_instance_of(Elementary::Middleware::Dummy).to \
|
129
|
+
receive(:call).and_call_original
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should have a value containing the echoed string' do
|
133
|
+
expect(response).to be_instance_of Elementary::Future
|
134
|
+
value = response.value # Wait on the future
|
135
|
+
expect(response).not_to be_rejected
|
136
|
+
expect(value.data).to eql('rspec')
|
137
|
+
end
|
126
138
|
end
|
127
|
-
|
139
|
+
end
|
128
140
|
end
|
129
141
|
end
|
130
142
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/clients/base_elementary_client'
|
3
|
+
require 'support/clients/elementary_client_using_anti_pattern'
|
4
|
+
|
5
|
+
def sendAndVerify(msg)
|
6
|
+
response = client.invoke_echo_service(Elementary::Rspec::String.new(:data => msg))
|
7
|
+
expect(response).to be_rejected
|
8
|
+
expect(response.reason.class).to be Elementary::Middleware::HttpStatusError
|
9
|
+
expect(response.reason.message).to include("connection refused: localhost:8090")
|
10
|
+
end
|
11
|
+
|
12
|
+
# This test requires that no process be listening at localhost:8090
|
13
|
+
describe ElementaryClientUsingAntiPattern, "http connection returning error code 503", :type => :integration do
|
14
|
+
subject (:client) {ElementaryClientUsingAntiPattern.new()}
|
15
|
+
describe "#initialize" do
|
16
|
+
it "creates a connection" do
|
17
|
+
expect(client.connection).not_to be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe "#invoke_service" do
|
21
|
+
context 'with http connection returning error connection refused' do
|
22
|
+
it "invokes echo service" do
|
23
|
+
sendAndVerify('rspec1')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/clients/base_elementary_client'
|
3
|
+
require 'support/clients/sample_elementary_client'
|
4
|
+
|
5
|
+
def send_and_verify_http_error_503(msg)
|
6
|
+
response = client.invoke_error_service(Elementary::Rspec::String.new(:data => msg))
|
7
|
+
expect(response).to be_rejected
|
8
|
+
expect(response.reason.class).to be Elementary::Middleware::HttpStatusError
|
9
|
+
expect(response.reason.message).to include("returned an HTTP response status of 503, so an exception was raised.")
|
10
|
+
end
|
11
|
+
|
12
|
+
def send_and_verify_http_error_500(msg)
|
13
|
+
response = client.invoke_error_service(Elementary::Rspec::String.new(:data => msg))
|
14
|
+
expect(response).to be_rejected
|
15
|
+
expect(response.reason.class).to be Elementary::Errors::RPCFailure
|
16
|
+
expect(response.reason.message).to include("sample failure")
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_and_verify_http_error_400(msg)
|
20
|
+
response = client.invoke_bad_request_data_service(Elementary::Rspec::String.new(:data => msg))
|
21
|
+
expect(response).to be_rejected
|
22
|
+
expect(response.reason.class).to be Elementary::Errors::RPCFailure
|
23
|
+
expect(response.reason.message).to include("sample bad request data failure")
|
24
|
+
end
|
25
|
+
|
26
|
+
def send_and_verify_http_error_404(msg)
|
27
|
+
response = client.invoke_service_not_found_service(Elementary::Rspec::String.new(:data => msg))
|
28
|
+
expect(response).to be_rejected
|
29
|
+
expect(response.reason.class).to be Elementary::Errors::RPCFailure
|
30
|
+
expect(response.reason.message).to include("sample service not found failure")
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_and_verify_connection_refused(msg)
|
34
|
+
response = client.invoke_error_service(Elementary::Rspec::String.new(:data => msg))
|
35
|
+
expect(response).to be_rejected
|
36
|
+
expect(response.reason.class).to be Elementary::Middleware::HttpStatusError
|
37
|
+
expect(response.reason.message).to include("connection refused: localhost:8090")
|
38
|
+
end
|
39
|
+
|
40
|
+
# This test requires ha-proxy to be listening at localhost:8080, but no real rpc to be available
|
41
|
+
describe SampleElementaryClient, "http connection returning error code 503", :type => :integration do
|
42
|
+
subject (:client) {SampleElementaryClient.new(8070)}
|
43
|
+
describe "#initialize" do
|
44
|
+
it "creates a connection" do
|
45
|
+
expect(client.connection).not_to be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
describe "#invoke_error_service" do
|
49
|
+
context 'with http connection returning error code 503' do
|
50
|
+
it "invokes error service" do
|
51
|
+
send_and_verify_http_error_503('rspec1')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# This test requires that no process be listening at localhost:8090
|
58
|
+
describe SampleElementaryClient, "http connection returning connection refused error", :type => :integration do
|
59
|
+
subject (:client) {SampleElementaryClient.new(8090)}
|
60
|
+
describe "#initialize" do
|
61
|
+
it "creates a connection" do
|
62
|
+
expect(client.connection).not_to be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "#invoke_error_service" do
|
66
|
+
context 'with http connection failed' do
|
67
|
+
it "invokes error service" do
|
68
|
+
send_and_verify_connection_refused('rspec1')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# These tests requires ha-proxy to be listening at localhost:8080 routing requests to online rpc server
|
75
|
+
describe SampleElementaryClient, "rpc requests returning non-connection related errors", :type => :integration do
|
76
|
+
subject (:client) {SampleElementaryClient.new(8080)}
|
77
|
+
describe "#initialize" do
|
78
|
+
it "creates a connection" do
|
79
|
+
expect(client.connection).not_to be_nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
describe "#invoke_bad_request_data_service", "handles http error 400" do
|
83
|
+
it "invokes bad request data service" do
|
84
|
+
send_and_verify_http_error_400('rspec1')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
describe "#invoke_service_not_found_service", "handles http error 404" do
|
88
|
+
it "invokes service not found service" do
|
89
|
+
send_and_verify_http_error_404('rspec1')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
describe "#invoke_service_returning_failure", "handles http error 500" do
|
93
|
+
it "invokes service returning failure" do
|
94
|
+
send_and_verify_http_error_500('rspec1')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'elementary'
|
2
|
+
|
3
|
+
class BaseElementaryClient
|
4
|
+
attr_accessor :connection
|
5
|
+
|
6
|
+
def invoke_error_service(request)
|
7
|
+
result = connection.rpc.error(request)
|
8
|
+
return handle(result)
|
9
|
+
end
|
10
|
+
|
11
|
+
def invoke_bad_request_data_service(request)
|
12
|
+
result = connection.rpc.bad_request_data_method(request)
|
13
|
+
return handle(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def invoke_service_not_found_service(request)
|
17
|
+
result = connection.rpc.service_not_found_method(request)
|
18
|
+
return handle(result)
|
19
|
+
end
|
20
|
+
|
21
|
+
def invoke_echo_service(request)
|
22
|
+
result = connection.rpc.echo(request)
|
23
|
+
return handle(result)
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle(result)
|
27
|
+
result.value
|
28
|
+
return result
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'elementary'
|
2
|
+
|
3
|
+
class ElementaryClientUsingAntiPattern < BaseElementaryClient
|
4
|
+
# This class demonstrates an anti-pattern of creating connection
|
5
|
+
# at initialization only. Although it works mostly, this pattern should not be used,
|
6
|
+
# since the connection should be re-established any time the connection object becomes nil.
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@connection = Elementary::Connection.new(Elementary::Rspec::Simple,
|
10
|
+
:hosts => [{'host' => 'localhost', 'port' => '8090'}])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'elementary'
|
2
|
+
|
3
|
+
class SampleElementaryClient < BaseElementaryClient
|
4
|
+
def initialize(port)
|
5
|
+
@port = port
|
6
|
+
end
|
7
|
+
def connection
|
8
|
+
return @connection if @connection
|
9
|
+
@connection = Elementary::Connection.new(Elementary::Rspec::Simple,
|
10
|
+
:hosts => [{'host' => 'localhost', 'port' => @port}])
|
11
|
+
end
|
12
|
+
end
|
@@ -28,6 +28,8 @@ module Elementary
|
|
28
28
|
class Simple < ::Protobuf::Rpc::Service
|
29
29
|
rpc :echo, ::Elementary::Rspec::String, ::Elementary::Rspec::String
|
30
30
|
rpc :error, ::Elementary::Rspec::String, ::Elementary::Rspec::String
|
31
|
+
rpc :bad_request_data_method, ::Elementary::Rspec::String, ::Elementary::Rspec::String
|
32
|
+
rpc :service_not_found_method, ::Elementary::Rspec::String, ::Elementary::Rspec::String
|
31
33
|
end
|
32
34
|
|
33
35
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require './spec/support/simpleservice.pb'
|
2
|
+
require 'protobuf/rpc/error'
|
2
3
|
|
3
4
|
module Elementary
|
4
5
|
module Rspec
|
@@ -13,6 +14,14 @@ module Elementary
|
|
13
14
|
def error
|
14
15
|
rpc_failed 'sample failure'
|
15
16
|
end
|
17
|
+
|
18
|
+
def bad_request_data_method
|
19
|
+
fail ::Protobuf::Rpc::BadRequestData, 'sample bad request data failure'
|
20
|
+
end
|
21
|
+
|
22
|
+
def service_not_found_method
|
23
|
+
fail ::Protobuf::Rpc::ServiceNotFound, 'sample service not found failure'
|
24
|
+
end
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elementary-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R. Tyler Croy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- -
|
16
|
+
- - ~>
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '1.6'
|
20
|
-
|
19
|
+
name: bundler
|
21
20
|
prerelease: false
|
21
|
+
type: :development
|
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
|
-
name: rake
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
|
-
- -
|
30
|
+
- - '>='
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0'
|
34
|
-
|
33
|
+
name: rake
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
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
|
-
name: concurrent-ruby
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
|
-
- -
|
44
|
+
- - ~>
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: 0.7.0
|
48
|
-
|
47
|
+
name: concurrent-ruby
|
49
48
|
prerelease: false
|
49
|
+
type: :runtime
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.7.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: faraday
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
|
-
- -
|
58
|
+
- - ~>
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: 0.9.0
|
62
|
-
|
61
|
+
name: faraday
|
63
62
|
prerelease: false
|
63
|
+
type: :runtime
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.9.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: net-http-persistent
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
72
71
|
requirements:
|
73
|
-
- -
|
72
|
+
- - ~>
|
74
73
|
- !ruby/object:Gem::Version
|
75
74
|
version: 2.9.4
|
76
|
-
|
75
|
+
name: net-http-persistent
|
77
76
|
prerelease: false
|
77
|
+
type: :runtime
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.9.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: lookout-statsd
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
86
85
|
requirements:
|
87
|
-
- -
|
86
|
+
- - ~>
|
88
87
|
- !ruby/object:Gem::Version
|
89
88
|
version: 0.9.0
|
90
|
-
|
89
|
+
name: lookout-statsd
|
91
90
|
prerelease: false
|
91
|
+
type: :runtime
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.9.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: hashie
|
99
98
|
requirement: !ruby/object:Gem::Requirement
|
100
99
|
requirements:
|
101
|
-
- -
|
100
|
+
- - '>='
|
102
101
|
- !ruby/object:Gem::Version
|
103
102
|
version: '0'
|
104
|
-
|
103
|
+
name: hashie
|
105
104
|
prerelease: false
|
105
|
+
type: :runtime
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: BLANK
|
@@ -115,8 +115,8 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
-
|
119
|
-
-
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
120
120
|
- Gemfile
|
121
121
|
- LICENSE.txt
|
122
122
|
- README.md
|
@@ -129,16 +129,22 @@ files:
|
|
129
129
|
- lib/elementary/future.rb
|
130
130
|
- lib/elementary/middleware.rb
|
131
131
|
- lib/elementary/middleware/dummy.rb
|
132
|
+
- lib/elementary/middleware/raise_on_status.rb
|
132
133
|
- lib/elementary/middleware/statsd.rb
|
133
134
|
- lib/elementary/transport.rb
|
134
135
|
- lib/elementary/transport/http.rb
|
135
136
|
- lib/elementary/version.rb
|
136
137
|
- spec/connection_spec.rb
|
138
|
+
- spec/elementary_client_using_anti_pattern_spec.rb
|
137
139
|
- spec/elementary_spec.rb
|
138
140
|
- spec/executor_spec.rb
|
139
141
|
- spec/future_spec.rb
|
140
142
|
- spec/middleware/statsd_spec.rb
|
143
|
+
- spec/sample_elementary_client_spec.rb
|
141
144
|
- spec/spec_helper.rb
|
145
|
+
- spec/support/clients/base_elementary_client.rb
|
146
|
+
- spec/support/clients/elementary_client_using_anti_pattern.rb
|
147
|
+
- spec/support/clients/sample_elementary_client.rb
|
142
148
|
- spec/support/proto/simpleservice.proto
|
143
149
|
- spec/support/simpleservice.pb.rb
|
144
150
|
- spec/support/simpleservice.rb
|
@@ -147,33 +153,38 @@ homepage: ''
|
|
147
153
|
licenses:
|
148
154
|
- MIT
|
149
155
|
metadata: {}
|
150
|
-
post_install_message:
|
156
|
+
post_install_message:
|
151
157
|
rdoc_options: []
|
152
158
|
require_paths:
|
153
159
|
- lib
|
154
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
155
161
|
requirements:
|
156
|
-
- -
|
162
|
+
- - '>='
|
157
163
|
- !ruby/object:Gem::Version
|
158
164
|
version: '0'
|
159
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
166
|
requirements:
|
161
|
-
- -
|
167
|
+
- - '>='
|
162
168
|
- !ruby/object:Gem::Version
|
163
169
|
version: '0'
|
164
170
|
requirements: []
|
165
|
-
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
167
|
-
signing_key:
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.4.5
|
173
|
+
signing_key:
|
168
174
|
specification_version: 4
|
169
175
|
summary: Gem supporting Protobuf RPC in a simple way
|
170
176
|
test_files:
|
171
177
|
- spec/connection_spec.rb
|
178
|
+
- spec/elementary_client_using_anti_pattern_spec.rb
|
172
179
|
- spec/elementary_spec.rb
|
173
180
|
- spec/executor_spec.rb
|
174
181
|
- spec/future_spec.rb
|
175
182
|
- spec/middleware/statsd_spec.rb
|
183
|
+
- spec/sample_elementary_client_spec.rb
|
176
184
|
- spec/spec_helper.rb
|
185
|
+
- spec/support/clients/base_elementary_client.rb
|
186
|
+
- spec/support/clients/elementary_client_using_anti_pattern.rb
|
187
|
+
- spec/support/clients/sample_elementary_client.rb
|
177
188
|
- spec/support/proto/simpleservice.proto
|
178
189
|
- spec/support/simpleservice.pb.rb
|
179
190
|
- spec/support/simpleservice.rb
|