right_agent 0.6.3 → 0.6.6
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.
- data/lib/right_agent.rb +1 -0
- data/lib/right_agent/agent_tags_manager.rb +1 -1
- data/lib/right_agent/broker_client.rb +6 -1
- data/lib/right_agent/core_payload_types.rb +1 -0
- data/lib/right_agent/core_payload_types/dev_repositories.rb +11 -1
- data/lib/right_agent/core_payload_types/dev_repository.rb +76 -0
- data/lib/right_agent/log.rb +2 -1
- data/lib/right_agent/monkey_patches/amqp_patch.rb +181 -102
- data/lib/right_agent/platform/linux.rb +134 -2
- data/lib/right_agent/sender.rb +7 -3
- data/right_agent.gemspec +2 -2
- data/spec/broker_client_spec.rb +37 -37
- data/spec/core_payload_types/dev_repositories_spec.rb +5 -5
- data/spec/core_payload_types/dev_repository_spec.rb +33 -0
- data/spec/monkey_patches/amqp_patch_spec.rb +0 -12
- data/spec/platform/linux_volume_manager_spec.rb +180 -0
- data/spec/sender_spec.rb +95 -0
- metadata +39 -36
@@ -180,10 +180,142 @@ module RightScale
|
|
180
180
|
|
181
181
|
# Provides utilities for managing volumes (disks).
|
182
182
|
class VolumeManager
|
183
|
+
|
184
|
+
class ParserError < Exception; end
|
185
|
+
class VolumeError < Exception; end
|
186
|
+
|
183
187
|
def initialize
|
184
|
-
|
188
|
+
|
185
189
|
end
|
186
|
-
|
190
|
+
|
191
|
+
# Gets a list of currently visible volumes in the form:
|
192
|
+
# [{:device, :label, :uuid, :type, :filesystem}]
|
193
|
+
#
|
194
|
+
# === Parameters
|
195
|
+
# conditions(Hash):: hash of conditions to match, or nil (default)
|
196
|
+
#
|
197
|
+
# === Return
|
198
|
+
# result(Array):: array of volume hashes, or an empty array
|
199
|
+
#
|
200
|
+
# === Raise
|
201
|
+
# VolumeError:: on failure to execute `blkid` to obtain raw output
|
202
|
+
# ParserError:: on failure to parse volume list
|
203
|
+
def volumes(conditions = nil)
|
204
|
+
exit_code, blkid_resp = blocking_popen('blkid')
|
205
|
+
raise VolumeError.new("Failed to list volumes exit code = #{exit_code}\nblkid\n#{blkid_resp}") unless exit_code == 0
|
206
|
+
return parse_volumes(blkid_resp, conditions)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Parses raw output from `blkid` into a hash of volumes
|
210
|
+
#
|
211
|
+
# The hash will contain the device name with a key of :device, and each key value pair
|
212
|
+
# for the device. In order to keep parity with the Windows VolumeManager.parse_volumes
|
213
|
+
# method, the :type key will be duplicated as :filesystem
|
214
|
+
#
|
215
|
+
# Example of raw output from `blkid`
|
216
|
+
#
|
217
|
+
# /dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
|
218
|
+
# /dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
|
219
|
+
# /dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
|
220
|
+
# /dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
|
221
|
+
#
|
222
|
+
# === Parameters
|
223
|
+
# output_text(String):: raw output from `blkid`
|
224
|
+
# conditions(Hash):: hash of conditions to match, or nil (default)
|
225
|
+
#
|
226
|
+
# === Return
|
227
|
+
# result(Array):: array of volume hashes, or an empty array
|
228
|
+
#
|
229
|
+
# === Raise
|
230
|
+
# ParserError:: on failure to parse volume list
|
231
|
+
def parse_volumes(output_text, conditions = nil)
|
232
|
+
results = []
|
233
|
+
output_text.each do |line|
|
234
|
+
volume = {}
|
235
|
+
line_regex = /^([\/a-z0-9]+):(.*)/
|
236
|
+
volmatch = line_regex.match(line)
|
237
|
+
raise ParserError.new("Failed to parse volume info from #{line.inspect} using #{line_regex.inspect}") unless volmatch
|
238
|
+
volume[:device] = volmatch[1]
|
239
|
+
volmatch[2].split(' ').each do |pair|
|
240
|
+
pair_regex = /([a-zA-Z_\-]+)=(.*)/
|
241
|
+
match = pair_regex.match(pair)
|
242
|
+
raise ParserError.new("Failed to parse volume info from #{pair} using #{pair_regex.inspect}") unless match
|
243
|
+
volume[:"#{match[1].downcase}"] = match[2].gsub('"', '')
|
244
|
+
# Make this as much like the windows output as possible
|
245
|
+
if match[1] == "TYPE"
|
246
|
+
volume[:filesystem] = match[2].gsub('"', '')
|
247
|
+
end
|
248
|
+
end
|
249
|
+
if conditions
|
250
|
+
matched = true
|
251
|
+
conditions.each do |key,value|
|
252
|
+
|
253
|
+
unless volume[key] == value
|
254
|
+
matched = false
|
255
|
+
break
|
256
|
+
end
|
257
|
+
end
|
258
|
+
results << volume if matched
|
259
|
+
else
|
260
|
+
results << volume
|
261
|
+
end
|
262
|
+
end
|
263
|
+
results
|
264
|
+
end
|
265
|
+
|
266
|
+
# Mounts a volume (returned by VolumeManager.volumes) to the mountpoint specified.
|
267
|
+
#
|
268
|
+
# === Parameters
|
269
|
+
# volume(Hash):: the volume hash returned by VolumeManager.volumes
|
270
|
+
# mountpoint(String):: the exact path where the device will be mounted ex: /mnt
|
271
|
+
#
|
272
|
+
# === Return
|
273
|
+
# always true
|
274
|
+
#
|
275
|
+
# === Raise
|
276
|
+
# ArgumentError:: on invalid parameters
|
277
|
+
# VolumeError:: on a failure to mount the device
|
278
|
+
def mount_volume(volume, mountpoint)
|
279
|
+
raise ArgumentError.new("Invalid volume = #{volume.inspect}") unless volume.is_a?(Hash) && volume[:device]
|
280
|
+
exit_code, mount_list_output = blocking_popen('mount')
|
281
|
+
raise VolumeError.new("Failed interrogation of current mounts; Exit Status: #{exit_code}\nError: #{mount_list_output}") unless exit_code == 0
|
282
|
+
|
283
|
+
device_match = /^#{volume[:device]} on (.+?)\s/.match(mount_list_output)
|
284
|
+
mountpoint_from_device_match = device_match ? device_match[1] : mountpoint
|
285
|
+
unless (mountpoint_from_device_match && mountpoint_from_device_match == mountpoint)
|
286
|
+
raise VolumeError.new("Attempted to mount volume \"#{volume[:device]}\" at \"#{mountpoint}\" but it was already mounted at #{mountpoint_from_device_match}")
|
287
|
+
end
|
288
|
+
|
289
|
+
mountpoint_match = /^(.+?) on #{mountpoint}/.match(mount_list_output)
|
290
|
+
device_from_mountpoint_match = mountpoint_match ? mountpoint_match[1] : volume[:device]
|
291
|
+
unless (device_from_mountpoint_match && device_from_mountpoint_match == volume[:device])
|
292
|
+
raise VolumeError.new("Attempted to mount volume \"#{volume[:device]}\" at \"#{mountpoint}\" but \"#{device_from_mountpoint_match}\" was already mounted there.")
|
293
|
+
end
|
294
|
+
|
295
|
+
# The volume is already mounted at the correct mountpoint
|
296
|
+
return true if /^#{volume[:device]} on #{mountpoint}/.match(mount_list_output)
|
297
|
+
|
298
|
+
# TODO: Maybe validate that the mountpoint is valid *nix path?
|
299
|
+
exit_code, mount_output = blocking_popen("mount -t #{volume[:filesystem].strip} #{volume[:device]} #{mountpoint}")
|
300
|
+
raise VolumeError.new("Failed to mount volume to \"#{mountpoint}\" with device \"#{volume[:device]}\"; Exit Status: #{exit_code}\nError: #{mount_output}") unless exit_code == 0
|
301
|
+
return true
|
302
|
+
end
|
303
|
+
|
304
|
+
# Runs the specified command synchronously using IO.popen
|
305
|
+
#
|
306
|
+
# === Parameters
|
307
|
+
# command(String):: system command to be executed
|
308
|
+
#
|
309
|
+
# === Return
|
310
|
+
# result(Array):: tuple of [exit_code, output_text]
|
311
|
+
def blocking_popen(command)
|
312
|
+
output_text = ""
|
313
|
+
IO.popen(command) do |io|
|
314
|
+
output_text = io.read
|
315
|
+
end
|
316
|
+
return $?.exitstatus, output_text
|
317
|
+
end
|
318
|
+
end # VolumeManager
|
187
319
|
|
188
320
|
class Shell
|
189
321
|
|
data/lib/right_agent/sender.rb
CHANGED
@@ -202,8 +202,12 @@ module RightScale
|
|
202
202
|
# true:: Always return true
|
203
203
|
def start
|
204
204
|
if @state == :initializing
|
205
|
-
@
|
206
|
-
|
205
|
+
if @mode == :offline
|
206
|
+
@state = :running
|
207
|
+
else
|
208
|
+
@state = :flushing
|
209
|
+
flush
|
210
|
+
end
|
207
211
|
@mode = :online if @mode == :initializing
|
208
212
|
end
|
209
213
|
true
|
@@ -243,7 +247,7 @@ module RightScale
|
|
243
247
|
Log.info("[offline] Disconnect from broker detected, entering offline mode")
|
244
248
|
Log.info("[offline] Messages will be queued in memory until connection to broker is re-established")
|
245
249
|
@offline_stats.update
|
246
|
-
@queue ||= [] #
|
250
|
+
@queue ||= [] # Ensure queue is valid without losing any messages when going offline
|
247
251
|
@mode = :offline
|
248
252
|
start_timer
|
249
253
|
end
|
data/right_agent.gemspec
CHANGED
@@ -24,7 +24,7 @@ require 'rubygems'
|
|
24
24
|
|
25
25
|
Gem::Specification.new do |spec|
|
26
26
|
spec.name = 'right_agent'
|
27
|
-
spec.version = '0.6.
|
27
|
+
spec.version = '0.6.6'
|
28
28
|
spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro']
|
29
29
|
spec.email = 'lee@rightscale.com'
|
30
30
|
spec.homepage = 'https://github.com/rightscale/right_agent'
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.require_path = 'lib'
|
38
38
|
|
39
39
|
spec.add_dependency('right_support', '~> 1.0')
|
40
|
-
spec.add_dependency('amqp', '0.7
|
40
|
+
spec.add_dependency('amqp', '0.6.7')
|
41
41
|
spec.add_dependency('json', ['~> 1.4'])
|
42
42
|
spec.add_dependency('eventmachine', '~> 0.12.10')
|
43
43
|
spec.add_dependency('right_popen', '~> 1.0.11')
|
data/spec/broker_client_spec.rb
CHANGED
@@ -50,7 +50,7 @@ describe RightScale::BrokerClient do
|
|
50
50
|
@amqp = flexmock(AMQP)
|
51
51
|
@amqp.should_receive(:connect).and_return(@connection).by_default
|
52
52
|
@channel.should_receive(:prefetch).never.by_default
|
53
|
-
flexmock(
|
53
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
54
54
|
@island = flexmock("island", :id => 2, :broker_hosts => "local_host").by_default
|
55
55
|
end
|
56
56
|
|
@@ -120,7 +120,7 @@ describe RightScale::BrokerClient do
|
|
120
120
|
@connection.should_receive(:close).once
|
121
121
|
@log.should_receive(:info).once
|
122
122
|
@log.should_receive(:error).with(/Failed connecting/, Exception, :trace).once
|
123
|
-
flexmock(
|
123
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_raise(Exception)
|
124
124
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
125
125
|
broker.summary.should == {:alias => "b0", :identity => @identity, :status => :failed,
|
126
126
|
:disconnects => 0, :failures => 1, :retries => 0}
|
@@ -153,14 +153,14 @@ describe RightScale::BrokerClient do
|
|
153
153
|
@channel.should_receive(:queue).and_return(@queue).by_default
|
154
154
|
@channel.should_receive(:direct).and_return(@direct).by_default
|
155
155
|
@channel.should_receive(:fanout).and_return(@fanout).by_default
|
156
|
-
flexmock(
|
156
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should subscribe queue to exchange" do
|
160
160
|
@queue.should_receive(:bind).and_return(@bind).once
|
161
161
|
@bind.should_receive(:subscribe).once
|
162
162
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
163
|
-
broker.__send__(:update_status, :
|
163
|
+
broker.__send__(:update_status, :ready)
|
164
164
|
broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) {|_, _|}
|
165
165
|
end
|
166
166
|
|
@@ -168,7 +168,7 @@ describe RightScale::BrokerClient do
|
|
168
168
|
@queue.should_receive(:bind).and_return(@bind).twice
|
169
169
|
@bind.should_receive(:subscribe).once
|
170
170
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
171
|
-
broker.__send__(:update_status, :
|
171
|
+
broker.__send__(:update_status, :ready)
|
172
172
|
options = {:exchange2 => {:type => :fanout, :name => "exchange2", :options => {:durable => true}}}
|
173
173
|
broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}, options) {|_, _|}
|
174
174
|
end
|
@@ -182,7 +182,7 @@ describe RightScale::BrokerClient do
|
|
182
182
|
it "should subscribe queue to empty exchange if no exchange specified" do
|
183
183
|
@queue.should_receive(:subscribe).once
|
184
184
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
185
|
-
broker.__send__(:update_status, :
|
185
|
+
broker.__send__(:update_status, :ready)
|
186
186
|
broker.subscribe({:name => "queue"}) {|b, p| p.should == nil}
|
187
187
|
end
|
188
188
|
|
@@ -216,7 +216,7 @@ describe RightScale::BrokerClient do
|
|
216
216
|
@info.should_receive(:ack).once
|
217
217
|
@bind.should_receive(:subscribe).and_yield(@info, @message).once
|
218
218
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
219
|
-
broker.__send__(:update_status, :
|
219
|
+
broker.__send__(:update_status, :ready)
|
220
220
|
result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
|
221
221
|
:ack => true, RightScale::Request => true) {|b, p| p.should == @packet}
|
222
222
|
result.should be_true
|
@@ -237,7 +237,7 @@ describe RightScale::BrokerClient do
|
|
237
237
|
@serializer.should_receive(:load).with(@message).and_return(@packet).once
|
238
238
|
@bind.should_receive(:subscribe).and_yield(@message).once
|
239
239
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
240
|
-
broker.__send__(:update_status, :
|
240
|
+
broker.__send__(:update_status, :ready)
|
241
241
|
broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
|
242
242
|
RightScale::Request => nil) {|b, p| p.class.should == RightScale::Request}
|
243
243
|
end
|
@@ -250,7 +250,7 @@ describe RightScale::BrokerClient do
|
|
250
250
|
@serializer.should_receive(:load).with(@message).and_return(@packet).once
|
251
251
|
@bind.should_receive(:subscribe).and_yield(@message).once
|
252
252
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
253
|
-
broker.__send__(:update_status, :
|
253
|
+
broker.__send__(:update_status, :ready)
|
254
254
|
result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
|
255
255
|
RightScale::Request => nil) {|b, p| raise Exception}
|
256
256
|
result.should be_false
|
@@ -263,7 +263,7 @@ describe RightScale::BrokerClient do
|
|
263
263
|
@log.should_receive(:debug).with(/nil message ignored/).once
|
264
264
|
@bind.should_receive(:subscribe).and_yield(@info, "nil").once
|
265
265
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
266
|
-
broker.__send__(:update_status, :
|
266
|
+
broker.__send__(:update_status, :ready)
|
267
267
|
called = 0
|
268
268
|
broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}, :ack => true) { |b, m| called += 1 }
|
269
269
|
called.should == 0
|
@@ -276,7 +276,7 @@ describe RightScale::BrokerClient do
|
|
276
276
|
@log.should_receive(:debug).with(/nil message ignored/).once
|
277
277
|
@bind.should_receive(:subscribe).and_yield("nil").once
|
278
278
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
279
|
-
broker.__send__(:update_status, :
|
279
|
+
broker.__send__(:update_status, :ready)
|
280
280
|
called = 0
|
281
281
|
broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) { |b, m| called += 1 }
|
282
282
|
called.should == 0
|
@@ -288,7 +288,7 @@ describe RightScale::BrokerClient do
|
|
288
288
|
@log.should_receive(:info).with(/^RECV/).never
|
289
289
|
@bind.should_receive(:subscribe).and_yield(@message).once
|
290
290
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
291
|
-
broker.__send__(:update_status, :
|
291
|
+
broker.__send__(:update_status, :ready)
|
292
292
|
broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}, :no_unserialize => true) do |b, m|
|
293
293
|
b.should == "rs-broker-localhost-5672"
|
294
294
|
m.should == @message
|
@@ -302,7 +302,7 @@ describe RightScale::BrokerClient do
|
|
302
302
|
@exceptions.should_receive(:track).once
|
303
303
|
@bind.should_receive(:subscribe).and_raise(Exception)
|
304
304
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
305
|
-
broker.__send__(:update_status, :
|
305
|
+
broker.__send__(:update_status, :ready)
|
306
306
|
result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) {|b, p|}
|
307
307
|
result.should be_false
|
308
308
|
end
|
@@ -422,7 +422,7 @@ describe RightScale::BrokerClient do
|
|
422
422
|
@queue = flexmock("queue", :bind => @bind, :name => "queue1")
|
423
423
|
@channel.should_receive(:queue).and_return(@queue).by_default
|
424
424
|
@channel.should_receive(:direct).and_return(@direct).by_default
|
425
|
-
flexmock(
|
425
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
426
426
|
end
|
427
427
|
|
428
428
|
it "should unsubscribe a queue by name" do
|
@@ -472,7 +472,7 @@ describe RightScale::BrokerClient do
|
|
472
472
|
context "when declaring" do
|
473
473
|
|
474
474
|
before(:each) do
|
475
|
-
flexmock(
|
475
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
476
476
|
@channel.should_receive(:queues).and_return({}).by_default
|
477
477
|
@channel.should_receive(:exchanges).and_return({}).by_default
|
478
478
|
end
|
@@ -524,14 +524,14 @@ describe RightScale::BrokerClient do
|
|
524
524
|
@message = flexmock("message")
|
525
525
|
@packet = flexmock("packet", :class => RightScale::Request, :to_s => true, :version => [12, 12]).by_default
|
526
526
|
@direct = flexmock("direct")
|
527
|
-
flexmock(
|
527
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
528
528
|
end
|
529
529
|
|
530
530
|
it "should serialize message, publish it, and return true" do
|
531
531
|
@channel.should_receive(:direct).with("exchange", :durable => true).and_return(@direct).once
|
532
532
|
@direct.should_receive(:publish).with(@message, :persistent => true).once
|
533
533
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
534
|
-
broker.__send__(:update_status, :
|
534
|
+
broker.__send__(:update_status, :ready)
|
535
535
|
broker.publish({:type => :direct, :name => "exchange", :options => {:durable => true}},
|
536
536
|
@packet, @message, :persistent => true).should be_true
|
537
537
|
end
|
@@ -540,7 +540,7 @@ describe RightScale::BrokerClient do
|
|
540
540
|
@channel.should_receive(:direct).with("exchange", {:declare => true}).and_return(@direct)
|
541
541
|
@direct.should_receive(:publish).with(@message, {})
|
542
542
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
543
|
-
broker.__send__(:update_status, :
|
543
|
+
broker.__send__(:update_status, :ready)
|
544
544
|
exchange = {:type => :direct, :name => "exchange", :options => {:declare => true}}
|
545
545
|
flexmock(broker).should_receive(:delete_amqp_resources).with(:direct, "exchange").once
|
546
546
|
broker.publish(exchange, @packet, @message).should be_true
|
@@ -560,7 +560,7 @@ describe RightScale::BrokerClient do
|
|
560
560
|
@channel.should_receive(:direct).and_raise(Exception)
|
561
561
|
@direct.should_receive(:publish).with(@message, {}).never
|
562
562
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
563
|
-
broker.__send__(:update_status, :
|
563
|
+
broker.__send__(:update_status, :ready)
|
564
564
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_false
|
565
565
|
end
|
566
566
|
|
@@ -570,7 +570,7 @@ describe RightScale::BrokerClient do
|
|
570
570
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
571
571
|
@direct.should_receive(:publish).with(@message, {}).once
|
572
572
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
573
|
-
broker.__send__(:update_status, :
|
573
|
+
broker.__send__(:update_status, :ready)
|
574
574
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
|
575
575
|
end
|
576
576
|
|
@@ -582,7 +582,7 @@ describe RightScale::BrokerClient do
|
|
582
582
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
583
583
|
@direct.should_receive(:publish).with(@message, {}).once
|
584
584
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
585
|
-
broker.__send__(:update_status, :
|
585
|
+
broker.__send__(:update_status, :ready)
|
586
586
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
|
587
587
|
end
|
588
588
|
|
@@ -592,7 +592,7 @@ describe RightScale::BrokerClient do
|
|
592
592
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
593
593
|
@direct.should_receive(:publish).with(@message, :no_log => true).once
|
594
594
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
595
|
-
broker.__send__(:update_status, :
|
595
|
+
broker.__send__(:update_status, :ready)
|
596
596
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :no_log => true).should be_true
|
597
597
|
end
|
598
598
|
|
@@ -603,7 +603,7 @@ describe RightScale::BrokerClient do
|
|
603
603
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
604
604
|
@direct.should_receive(:publish).with(@message, :no_log => true).once
|
605
605
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
606
|
-
broker.__send__(:update_status, :
|
606
|
+
broker.__send__(:update_status, :ready)
|
607
607
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :no_log => true).should be_true
|
608
608
|
end
|
609
609
|
|
@@ -613,7 +613,7 @@ describe RightScale::BrokerClient do
|
|
613
613
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
614
614
|
@direct.should_receive(:publish).with(@message, {}).once
|
615
615
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
616
|
-
broker.__send__(:update_status, :
|
616
|
+
broker.__send__(:update_status, :ready)
|
617
617
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
|
618
618
|
end
|
619
619
|
|
@@ -625,7 +625,7 @@ describe RightScale::BrokerClient do
|
|
625
625
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
626
626
|
@direct.should_receive(:publish).with(@message, :log_filter => [:to]).once
|
627
627
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
628
|
-
broker.__send__(:update_status, :
|
628
|
+
broker.__send__(:update_status, :ready)
|
629
629
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :log_filter => [:to]).should be_true
|
630
630
|
end
|
631
631
|
|
@@ -638,7 +638,7 @@ describe RightScale::BrokerClient do
|
|
638
638
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
639
639
|
@direct.should_receive(:publish).with(@message, :log_filter => [:to]).once
|
640
640
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
641
|
-
broker.__send__(:update_status, :
|
641
|
+
broker.__send__(:update_status, :ready)
|
642
642
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :log_filter => [:to]).should be_true
|
643
643
|
end
|
644
644
|
|
@@ -648,7 +648,7 @@ describe RightScale::BrokerClient do
|
|
648
648
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
649
649
|
@direct.should_receive(:publish).with(@message, :log_data => "More data").once
|
650
650
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
651
|
-
broker.__send__(:update_status, :
|
651
|
+
broker.__send__(:update_status, :ready)
|
652
652
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :log_data => "More data").should be_true
|
653
653
|
end
|
654
654
|
|
@@ -659,7 +659,7 @@ describe RightScale::BrokerClient do
|
|
659
659
|
@channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
|
660
660
|
@direct.should_receive(:publish).with(@message, {}).once
|
661
661
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
662
|
-
broker.__send__(:update_status, :
|
662
|
+
broker.__send__(:update_status, :ready)
|
663
663
|
broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
|
664
664
|
end
|
665
665
|
|
@@ -738,7 +738,7 @@ describe RightScale::BrokerClient do
|
|
738
738
|
@queue = flexmock("queue", :bind => @bind, :name => "queue1")
|
739
739
|
@channel.should_receive(:queue).and_return(@queue).by_default
|
740
740
|
@channel.should_receive(:direct).and_return(@direct).by_default
|
741
|
-
flexmock(
|
741
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
742
742
|
end
|
743
743
|
|
744
744
|
it "should delete the named queue and return true" do
|
@@ -777,13 +777,13 @@ describe RightScale::BrokerClient do
|
|
777
777
|
include RightScale::StatsHelper
|
778
778
|
|
779
779
|
before(:each) do
|
780
|
-
flexmock(
|
780
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
781
781
|
end
|
782
782
|
|
783
783
|
it "should distinguish whether the client is usable based on whether connecting or connected" do
|
784
784
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
785
785
|
broker.usable?.should be_true
|
786
|
-
broker.__send__(:update_status, :
|
786
|
+
broker.__send__(:update_status, :ready)
|
787
787
|
broker.usable?.should be_true
|
788
788
|
broker.__send__(:update_status, :disconnected)
|
789
789
|
broker.usable?.should be_false
|
@@ -795,7 +795,7 @@ describe RightScale::BrokerClient do
|
|
795
795
|
it "should distinguish whether the client is connected" do
|
796
796
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
797
797
|
broker.connected?.should be_false
|
798
|
-
broker.__send__(:update_status, :
|
798
|
+
broker.__send__(:update_status, :ready)
|
799
799
|
broker.connected?.should be_true
|
800
800
|
broker.__send__(:update_status, :disconnected)
|
801
801
|
broker.connected?.should be_false
|
@@ -807,7 +807,7 @@ describe RightScale::BrokerClient do
|
|
807
807
|
it "should distinguish whether the client has failed" do
|
808
808
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
809
809
|
broker.failed?.should be_false
|
810
|
-
broker.__send__(:update_status, :
|
810
|
+
broker.__send__(:update_status, :ready)
|
811
811
|
broker.failed?.should be_false
|
812
812
|
broker.__send__(:update_status, :disconnected)
|
813
813
|
broker.failed?.should be_false
|
@@ -820,7 +820,7 @@ describe RightScale::BrokerClient do
|
|
820
820
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
|
821
821
|
broker.summary.should == {:alias => "b0", :identity => @identity, :status => :connecting,
|
822
822
|
:disconnects => 0, :failures => 0, :retries => 0}
|
823
|
-
broker.__send__(:update_status, :
|
823
|
+
broker.__send__(:update_status, :ready)
|
824
824
|
broker.summary.should == {:alias => "b0", :identity => @identity, :status => :connected,
|
825
825
|
:disconnects => 0, :failures => 0, :retries => 0}
|
826
826
|
@log.should_receive(:error).with(/Failed to connect to broker/).once
|
@@ -834,7 +834,7 @@ describe RightScale::BrokerClient do
|
|
834
834
|
broker.stats.should == {"alias" => "b0", "identity" => "rs-broker-localhost-5672",
|
835
835
|
"status" => "connecting", "disconnects" => nil, "disconnect last" => nil,
|
836
836
|
"failures" => nil, "failure last" => nil, "retries" => nil}
|
837
|
-
broker.__send__(:update_status, :
|
837
|
+
broker.__send__(:update_status, :ready)
|
838
838
|
broker.stats.should == {"alias" => "b0", "identity" => "rs-broker-localhost-5672",
|
839
839
|
"status" => "connected", "disconnects" => nil, "disconnect last" => nil,
|
840
840
|
"failures" => nil, "failure last" => nil, "retries" => nil}
|
@@ -852,7 +852,7 @@ describe RightScale::BrokerClient do
|
|
852
852
|
callback = lambda { |b, c| called += 1; b.should == broker; c.should == connected_before }
|
853
853
|
options = {:update_status_callback => callback}
|
854
854
|
broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, options)
|
855
|
-
broker.__send__(:update_status, :
|
855
|
+
broker.__send__(:update_status, :ready)
|
856
856
|
broker.last_failed.should be_false
|
857
857
|
called.should == 1
|
858
858
|
connected_before = true
|
@@ -875,7 +875,7 @@ describe RightScale::BrokerClient do
|
|
875
875
|
context "when closing" do
|
876
876
|
|
877
877
|
before(:each) do
|
878
|
-
flexmock(
|
878
|
+
flexmock(MQ).should_receive(:new).with(@connection).and_return(@channel).by_default
|
879
879
|
end
|
880
880
|
|
881
881
|
it "should close broker connection and send status update" do
|