right_agent 2.0.8 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right_agent.rb +1 -2
- data/lib/right_agent/actors/agent_manager.rb +3 -3
- data/lib/right_agent/agent.rb +14 -4
- data/lib/right_agent/clients.rb +10 -0
- data/lib/right_agent/clients/balanced_http_client.rb +210 -122
- data/lib/right_agent/clients/base_retry_client.rb +25 -6
- data/lib/right_agent/clients/blocking_client.rb +155 -0
- data/lib/right_agent/clients/non_blocking_client.rb +198 -0
- data/lib/right_agent/clients/right_http_client.rb +2 -2
- data/lib/right_agent/clients/router_client.rb +205 -80
- data/lib/right_agent/connectivity_checker.rb +1 -1
- data/lib/right_agent/eventmachine_spawn.rb +70 -0
- data/lib/right_agent/exceptions.rb +4 -20
- data/lib/right_agent/http_exceptions.rb +87 -0
- data/lib/right_agent/minimal.rb +1 -0
- data/lib/right_agent/retryable_request.rb +1 -1
- data/lib/right_agent/scripts/agent_controller.rb +12 -6
- data/lib/right_agent/scripts/agent_deployer.rb +6 -0
- data/lib/right_agent/sender.rb +31 -6
- data/right_agent.gemspec +2 -2
- data/spec/agent_spec.rb +9 -6
- data/spec/clients/balanced_http_client_spec.rb +349 -244
- data/spec/clients/base_retry_client_spec.rb +31 -15
- data/spec/clients/blocking_client_spec.rb +265 -0
- data/spec/clients/non_blocking_client_spec.rb +387 -0
- data/spec/clients/router_client_spec.rb +390 -171
- data/spec/http_exceptions_spec.rb +106 -0
- data/spec/retryable_request_spec.rb +13 -13
- data/spec/sender_spec.rb +48 -22
- data/spec/spec_helper.rb +0 -26
- metadata +10 -3
@@ -0,0 +1,106 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2013 RightScale, Inc, All Rights Reserved Worldwide.
|
3
|
+
#
|
4
|
+
# THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
|
5
|
+
# AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
|
6
|
+
# reproduction, modification, or disclosure of this program is
|
7
|
+
# strictly prohibited. Any use of this program by an authorized
|
8
|
+
# licensee is strictly subject to the terms and conditions,
|
9
|
+
# including confidentiality obligations, set forth in the applicable
|
10
|
+
# License Agreement between RightScale.com, Inc. and
|
11
|
+
# the licensee.
|
12
|
+
#++
|
13
|
+
|
14
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'right_agent', 'http_exceptions'))
|
16
|
+
|
17
|
+
describe RightScale::HttpException do
|
18
|
+
|
19
|
+
class HttpTest < RightScale::HttpException; end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@exception = HttpTest.new(999, "failed")
|
23
|
+
end
|
24
|
+
|
25
|
+
context :initialize do
|
26
|
+
it "stores HTTP code and body" do
|
27
|
+
@exception.http_code.should == 999
|
28
|
+
@exception.http_body.should == "failed"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "allows generic description to be set" do
|
32
|
+
@exception.message = "Test"
|
33
|
+
@exception.to_s.should == "Test: failed"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context :inspect do
|
38
|
+
it "displays generic description and detailed message" do
|
39
|
+
@exception.inspect.should == "HttpTest: failed"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context :to_s do
|
44
|
+
it "inspects the exception" do
|
45
|
+
@exception.inspect.should == "HttpTest: failed"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context :message do
|
50
|
+
it "returns generic description" do
|
51
|
+
@exception.message = "Test"
|
52
|
+
@exception.message.should == "Test"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "defaults to class name" do
|
56
|
+
@exception.message.should == "HttpTest"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end # RightScale::HttpException
|
61
|
+
|
62
|
+
describe RightScale::HttpExceptions do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
@header = {:location => "here"}
|
66
|
+
end
|
67
|
+
|
68
|
+
it "initializes list of standard HTTP exceptions" do
|
69
|
+
RightScale::HttpExceptions::HTTP_EXCEPTIONS_MAP.size.should > 50
|
70
|
+
RightScale::HttpExceptions::HTTP_EXCEPTIONS_MAP[400].should == RightScale::HttpExceptions::BadRequest
|
71
|
+
end
|
72
|
+
|
73
|
+
context :create do
|
74
|
+
it "creates instance of standard exception" do
|
75
|
+
e = RightScale::HttpExceptions.create(500, "failed")
|
76
|
+
e.class.should == RightScale::HttpExceptions::InternalServerError
|
77
|
+
e.response.headers.should == {}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "creates exception whose message is the generic description" do
|
81
|
+
e = RightScale::HttpExceptions.create(500, "failed")
|
82
|
+
e.message.should == "500 Internal Server Error"
|
83
|
+
e.inspect.should == "500 Internal Server Error: failed"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "creates RequestFailed exception if the HTTP code is not recognized" do
|
87
|
+
e = RightScale::HttpExceptions.create(999, "failed")
|
88
|
+
e.class.should == RightScale::HttpExceptions::RequestFailed
|
89
|
+
e.message.should == "HTTP status code 999"
|
90
|
+
e.inspect.should == "HTTP status code 999: failed"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "puts header into a Response and stores in exception" do
|
94
|
+
e = RightScale::HttpExceptions.create(500, "failed", @header)
|
95
|
+
e.response.headers.should == {:location => "here"}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context :convert do
|
100
|
+
it "converts RestClient exception to HttpException" do
|
101
|
+
bad_request = RestClient::Exceptions::EXCEPTIONS_MAP[400].new(nil, 400)
|
102
|
+
RightScale::HttpExceptions.convert(bad_request).should be_a RightScale::HttpExceptions::BadRequest
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end # RightScale::HttpExceptions
|
@@ -102,8 +102,8 @@ describe RightScale::RetryableRequest do
|
|
102
102
|
request = RightScale::RetryableRequest.new('type', 'payload', :retry_on_error => true)
|
103
103
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
104
104
|
and_yield(RightScale::OperationResult.error('test')).once
|
105
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
106
105
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
106
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
107
107
|
request.run
|
108
108
|
end
|
109
109
|
|
@@ -114,8 +114,8 @@ describe RightScale::RetryableRequest do
|
|
114
114
|
end
|
115
115
|
flexmock(request).should_receive(:fail).never
|
116
116
|
flexmock(request).should_receive(:succeed).once
|
117
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
118
117
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
118
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
119
119
|
request.run
|
120
120
|
end
|
121
121
|
|
@@ -124,8 +124,8 @@ describe RightScale::RetryableRequest do
|
|
124
124
|
flexmock(RightScale::Log).should_receive(:info).with("Request type canceled (enough already)").once
|
125
125
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
126
126
|
and_yield(RightScale::OperationResult.cancel('enough already')).once
|
127
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
128
127
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
128
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
129
129
|
request.run
|
130
130
|
end
|
131
131
|
end
|
@@ -141,8 +141,8 @@ describe RightScale::RetryableRequest do
|
|
141
141
|
flexmock(RightScale::Log).should_receive(:info).with("Request non-delivery (test) for type").once
|
142
142
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
143
143
|
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
144
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
145
144
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
145
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
146
146
|
request.run
|
147
147
|
end
|
148
148
|
|
@@ -152,8 +152,8 @@ describe RightScale::RetryableRequest do
|
|
152
152
|
flexmock(RightScale::Log).should_receive(:info).with("Request type failed (test) and should be retried").once
|
153
153
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
154
154
|
and_yield(RightScale::OperationResult.retry('test')).once
|
155
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
156
155
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
156
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
157
157
|
request.run
|
158
158
|
end
|
159
159
|
|
@@ -163,8 +163,8 @@ describe RightScale::RetryableRequest do
|
|
163
163
|
flexmock(RightScale::Log).should_receive(:info).with("Request type failed (RightScale not ready) and should be retried").once
|
164
164
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
165
165
|
and_yield(RightScale::OperationResult.retry).once
|
166
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
167
166
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
167
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
168
168
|
request.run
|
169
169
|
end
|
170
170
|
|
@@ -174,8 +174,8 @@ describe RightScale::RetryableRequest do
|
|
174
174
|
and_yield(RightScale::OperationResult.success('test')).once
|
175
175
|
flexmock(request).should_receive(:fail).once
|
176
176
|
flexmock(request).should_receive(:succeed).never
|
177
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
178
177
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
178
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
179
179
|
request.cancel('test')
|
180
180
|
request.run
|
181
181
|
end
|
@@ -185,8 +185,8 @@ describe RightScale::RetryableRequest do
|
|
185
185
|
flexmock(RightScale::Log).should_receive(:info).with("Request type canceled (enough already)").once
|
186
186
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
187
187
|
and_yield(RightScale::OperationResult.cancel('enough already')).once
|
188
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
189
188
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
189
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
190
190
|
request.run
|
191
191
|
end
|
192
192
|
end
|
@@ -197,8 +197,8 @@ describe RightScale::RetryableRequest do
|
|
197
197
|
request = RightScale::RetryableRequest.new('type', 'payload', :retry_delay => retry_delay)
|
198
198
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
199
199
|
and_yield(RightScale::OperationResult.retry('test')).once
|
200
|
-
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).once
|
201
200
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
201
|
+
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).once
|
202
202
|
flexmock(EM).should_receive(:next_tick).never
|
203
203
|
request.run
|
204
204
|
end
|
@@ -208,8 +208,8 @@ describe RightScale::RetryableRequest do
|
|
208
208
|
request = RightScale::RetryableRequest.new('type', 'payload', :retry_delay => retry_delay)
|
209
209
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
210
210
|
and_yield(RightScale::OperationResult.retry('test')).once
|
211
|
-
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).never
|
212
211
|
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
212
|
+
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).never
|
213
213
|
flexmock(EM).should_receive(:next_tick).once
|
214
214
|
request.run
|
215
215
|
end
|
@@ -224,9 +224,9 @@ describe RightScale::RetryableRequest do
|
|
224
224
|
:retry_delay_count => retry_delay_count)
|
225
225
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
226
226
|
and_yield(RightScale::OperationResult.retry('test')).twice
|
227
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
227
228
|
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).and_yield.once
|
228
229
|
flexmock(EM).should_receive(:add_timer).with(retry_delay * backoff_factor, Proc).once
|
229
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
230
230
|
flexmock(EM).should_receive(:next_tick).never
|
231
231
|
request.run
|
232
232
|
end
|
@@ -241,10 +241,10 @@ describe RightScale::RetryableRequest do
|
|
241
241
|
:max_retry_delay => max_retry_delay)
|
242
242
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
243
243
|
and_yield(RightScale::OperationResult.retry('test')).times(4)
|
244
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
244
245
|
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).and_yield.twice
|
245
246
|
flexmock(EM).should_receive(:add_timer).with(retry_delay * backoff_factor, Proc).and_yield.once
|
246
247
|
flexmock(EM).should_receive(:add_timer).with(max_retry_delay, Proc).once
|
247
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
248
248
|
flexmock(EM).should_receive(:next_tick).never
|
249
249
|
request.run
|
250
250
|
request.instance_variable_get(:@retry_delay_count).should == retry_delay_count / 2
|
@@ -262,10 +262,10 @@ describe RightScale::RetryableRequest do
|
|
262
262
|
:max_retry_delay => max_retry_delay)
|
263
263
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, Proc).
|
264
264
|
and_yield(RightScale::OperationResult.retry('test')).times(3)
|
265
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
265
266
|
flexmock(EM).should_receive(:add_timer).with(retry_delay, Proc).and_yield.once
|
266
267
|
flexmock(EM).should_receive(:add_timer).with(retry_delay * backoff_factor, Proc).and_yield.once
|
267
268
|
flexmock(EM).should_receive(:add_timer).with(max_retry_delay, Proc).once
|
268
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_TIMEOUT, Proc).once
|
269
269
|
flexmock(EM).should_receive(:next_tick).never
|
270
270
|
request.run
|
271
271
|
end
|
data/spec/sender_spec.rb
CHANGED
@@ -671,9 +671,47 @@ describe RightScale::Sender do
|
|
671
671
|
@sender.send(:http_send, :send_push, @target, @packet, @received_at, @callback).should be_true
|
672
672
|
end
|
673
673
|
|
674
|
+
context "when :async_response enabled" do
|
675
|
+
before(:each) do
|
676
|
+
@sender = create_sender(:http, :async_response => true)
|
677
|
+
flexmock(EM).should_receive(:next_tick).and_yield.once
|
678
|
+
end
|
679
|
+
|
680
|
+
it "sends in next_tick if :async_response option set" do
|
681
|
+
@packet = @sender.build_packet(:send_push, @type, @payload, @target, @token, @callback)
|
682
|
+
@client.should_receive(:push).with(@type, @payload, @target, @token).and_return(nil).once
|
683
|
+
@sender.send(:http_send, :send_push, @target, @packet, @received_at, @callback).should be_true
|
684
|
+
end
|
685
|
+
|
686
|
+
it "logs unexpected exception" do
|
687
|
+
flexmock(@sender).should_receive(:handle_response).and_raise(RuntimeError).once
|
688
|
+
@log.should_receive(:error).with(/Failed sending or handling response/, RuntimeError, :trace).once
|
689
|
+
@packet = @sender.build_packet(:send_request, @type, @payload, @target, @token, @callback)
|
690
|
+
@client.should_receive(:request).with(@type, @payload, @target, @token).and_return("result").once
|
691
|
+
@sender.send(:http_send, :send_request, @target, @packet, @received_at, @callback).should be_true
|
692
|
+
end
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
696
|
+
context :http_send_once do
|
697
|
+
before(:each) do
|
698
|
+
@received_at = Time.now
|
699
|
+
flexmock(Time).should_receive(:now).and_return(@received_at)
|
700
|
+
flexmock(RightSupport::Data::UUID).should_receive(:generate).and_return(@token).by_default
|
701
|
+
@packet = @sender.build_packet(:send_request, @type, @payload, @target, @token, @callback)
|
702
|
+
@response = nil
|
703
|
+
@callback = lambda { |response| @response = response }
|
704
|
+
end
|
705
|
+
|
706
|
+
it "sends request using configured client" do
|
707
|
+
@packet = @sender.build_packet(:send_push, @type, @payload, @target, @token, @callback)
|
708
|
+
@client.should_receive(:push).with(@type, @payload, @target, @token).and_return(nil).once
|
709
|
+
@sender.send(:http_send_once, :send_push, @target, @packet, @received_at, @callback).should be_true
|
710
|
+
end
|
711
|
+
|
674
712
|
it "responds with success result containing response" do
|
675
713
|
@client.should_receive(:request).with(@type, @payload, @target, @token).and_return("result").once
|
676
|
-
@sender.send(:
|
714
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
677
715
|
@response.token.should == @token
|
678
716
|
@response.results.success?.should be_true
|
679
717
|
@response.results.content.should == "result"
|
@@ -683,19 +721,7 @@ describe RightScale::Sender do
|
|
683
721
|
|
684
722
|
it "responds with success result when response is nil" do
|
685
723
|
@client.should_receive(:request).with(@type, @payload, @target, @token).and_return(nil).once
|
686
|
-
@sender.send(:
|
687
|
-
@response.token.should == @token
|
688
|
-
@response.results.success?.should be_true
|
689
|
-
@response.results.content.should be_nil
|
690
|
-
@response.from.should == @target
|
691
|
-
@response.received_at.should == @received_at.to_f
|
692
|
-
end
|
693
|
-
|
694
|
-
it "responds asynchronously if requested" do
|
695
|
-
@sender = create_sender(:http, :async_response => true)
|
696
|
-
flexmock(EM).should_receive(:next_tick).and_yield.once
|
697
|
-
@client.should_receive(:request).with(@type, @payload, @target, @token).and_return(nil).once
|
698
|
-
@sender.send(:http_send, :send_request, @target, @packet, @received_at, @callback).should be_true
|
724
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
699
725
|
@response.token.should == @token
|
700
726
|
@response.results.success?.should be_true
|
701
727
|
@response.results.content.should be_nil
|
@@ -713,12 +739,12 @@ describe RightScale::Sender do
|
|
713
739
|
flexmock(@sender.offline_handler).should_receive(:queue_request).with(:send_request, @type,
|
714
740
|
@payload, @target, @callback).once
|
715
741
|
flexmock(@sender).should_receive(:handle_response).never
|
716
|
-
@sender.send(:
|
742
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
717
743
|
end
|
718
744
|
|
719
745
|
it "responds with retry result if not queueing" do
|
720
746
|
@client.should_receive(:request).and_raise(RightScale::Exceptions::ConnectivityFailure, "Server not responding").once
|
721
|
-
@sender.send(:
|
747
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
722
748
|
@response.results.retry?.should be_true
|
723
749
|
@response.results.content.should == "Server not responding"
|
724
750
|
end
|
@@ -726,14 +752,14 @@ describe RightScale::Sender do
|
|
726
752
|
|
727
753
|
it "responds with retry result if retryable error" do
|
728
754
|
@client.should_receive(:request).and_raise(RightScale::Exceptions::RetryableError, "try again").once
|
729
|
-
@sender.send(:
|
755
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
730
756
|
@response.results.retry?.should be_true
|
731
757
|
@response.results.content.should == "try again"
|
732
758
|
end
|
733
759
|
|
734
760
|
it "responds with error result if internal error" do
|
735
761
|
@client.should_receive(:request).and_raise(RightScale::Exceptions::InternalServerError.new("unprocessable", "Router")).once
|
736
|
-
@sender.send(:
|
762
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
737
763
|
@response.results.error?.should be_true
|
738
764
|
@response.results.content.should == "Router internal error"
|
739
765
|
end
|
@@ -741,12 +767,12 @@ describe RightScale::Sender do
|
|
741
767
|
it "does not respond to request if terminating" do
|
742
768
|
@client.should_receive(:request).and_raise(RightScale::Exceptions::Terminating, "going down").once
|
743
769
|
flexmock(@sender).should_receive(:handle_response).never
|
744
|
-
@sender.send(:
|
770
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
745
771
|
end
|
746
772
|
|
747
773
|
it "responds with error result if HTTP error" do
|
748
|
-
@client.should_receive(:request).and_raise(
|
749
|
-
@sender.send(:
|
774
|
+
@client.should_receive(:request).and_raise(RightScale::HttpExceptions.create(400, "bad data")).once
|
775
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
750
776
|
@response.results.error?.should be_true
|
751
777
|
@response.results.content.should == "400 Bad Request: bad data"
|
752
778
|
end
|
@@ -754,7 +780,7 @@ describe RightScale::Sender do
|
|
754
780
|
it "responds with error result if unexpected error" do
|
755
781
|
@log.should_receive(:error).with(/Failed to send/, StandardError, :trace).once
|
756
782
|
@client.should_receive(:request).and_raise(StandardError, "unexpected").once
|
757
|
-
@sender.send(:
|
783
|
+
@sender.send(:http_send_once, :send_request, @target, @packet, @received_at, @callback).should be_true
|
758
784
|
@response.results.error?.should be_true
|
759
785
|
@response.results.content.should == "Agent agent internal error"
|
760
786
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -75,32 +75,6 @@ module RightScale
|
|
75
75
|
|
76
76
|
end
|
77
77
|
|
78
|
-
# Mock RestClient exceptions since cannot create directly without a
|
79
|
-
# RestClient::Response, but need RestClient interface for error reporting
|
80
|
-
class RestExceptionMock < RestClient::Exception
|
81
|
-
class Response
|
82
|
-
attr_reader :headers
|
83
|
-
|
84
|
-
def initialize(headers)
|
85
|
-
@headers = headers || {}
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
attr_accessor :message
|
90
|
-
attr_reader :http_code, :http_body, :response
|
91
|
-
|
92
|
-
def initialize(http_code, http_body = nil, response_headers = nil)
|
93
|
-
@message = "#{http_code} #{RestClient::STATUSES[http_code]}"
|
94
|
-
@http_code = http_code
|
95
|
-
@http_body = http_body
|
96
|
-
@response = Response.new(response_headers)
|
97
|
-
end
|
98
|
-
|
99
|
-
def inspect
|
100
|
-
"#{@message}: #{@http_body}"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
78
|
# Functions for setting version per ProtocolVersionMixin
|
105
79
|
def version_cannot_put_version_in_packet; RightScale::Packet::DEFAULT_VERSION end
|
106
80
|
def version_can_put_version_in_packet; 12 end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-
|
15
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: right_support
|
@@ -223,6 +223,8 @@ files:
|
|
223
223
|
- lib/right_agent/clients/auth_client.rb
|
224
224
|
- lib/right_agent/clients/balanced_http_client.rb
|
225
225
|
- lib/right_agent/clients/base_retry_client.rb
|
226
|
+
- lib/right_agent/clients/blocking_client.rb
|
227
|
+
- lib/right_agent/clients/non_blocking_client.rb
|
226
228
|
- lib/right_agent/clients/right_http_client.rb
|
227
229
|
- lib/right_agent/clients/router_client.rb
|
228
230
|
- lib/right_agent/command.rb
|
@@ -259,8 +261,10 @@ files:
|
|
259
261
|
- lib/right_agent/dispatched_cache.rb
|
260
262
|
- lib/right_agent/dispatcher.rb
|
261
263
|
- lib/right_agent/enrollment_result.rb
|
264
|
+
- lib/right_agent/eventmachine_spawn.rb
|
262
265
|
- lib/right_agent/exceptions.rb
|
263
266
|
- lib/right_agent/history.rb
|
267
|
+
- lib/right_agent/http_exceptions.rb
|
264
268
|
- lib/right_agent/log.rb
|
265
269
|
- lib/right_agent/minimal.rb
|
266
270
|
- lib/right_agent/monkey_patches.rb
|
@@ -328,6 +332,8 @@ files:
|
|
328
332
|
- spec/clients/auth_client_spec.rb
|
329
333
|
- spec/clients/balanced_http_client_spec.rb
|
330
334
|
- spec/clients/base_retry_client_spec.rb
|
335
|
+
- spec/clients/blocking_client_spec.rb
|
336
|
+
- spec/clients/non_blocking_client_spec.rb
|
331
337
|
- spec/clients/router_client_spec.rb
|
332
338
|
- spec/clients/spec_helper.rb
|
333
339
|
- spec/command/agent_manager_commands_spec.rb
|
@@ -348,6 +354,7 @@ files:
|
|
348
354
|
- spec/dispatcher_spec.rb
|
349
355
|
- spec/enrollment_result_spec.rb
|
350
356
|
- spec/history_spec.rb
|
357
|
+
- spec/http_exceptions_spec.rb
|
351
358
|
- spec/log_spec.rb
|
352
359
|
- spec/monkey_patches/eventmachine_spec.rb
|
353
360
|
- spec/multiplexer_spec.rb
|
@@ -405,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
405
412
|
version: '0'
|
406
413
|
segments:
|
407
414
|
- 0
|
408
|
-
hash: -
|
415
|
+
hash: -514675308971748709
|
409
416
|
requirements: []
|
410
417
|
rubyforge_project:
|
411
418
|
rubygems_version: 1.8.26
|