right_agent 0.5.1 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/lib/right_agent.rb +3 -13
  2. data/lib/right_agent/actors/agent_manager.rb +78 -4
  3. data/lib/right_agent/agent.rb +81 -4
  4. data/lib/right_agent/agent_config.rb +17 -1
  5. data/lib/right_agent/agent_tags_manager.rb +2 -2
  6. data/lib/right_agent/broker_client.rb +32 -34
  7. data/lib/right_agent/command/agent_manager_commands.rb +16 -0
  8. data/lib/right_agent/command/command_constants.rb +0 -9
  9. data/lib/right_agent/dispatcher.rb +6 -3
  10. data/lib/right_agent/ha_broker_client.rb +63 -14
  11. data/lib/right_agent/log.rb +1 -1
  12. data/lib/right_agent/minimal.rb +43 -0
  13. data/lib/right_agent/monkey_patches/amqp_patch.rb +91 -182
  14. data/lib/right_agent/packets.rb +10 -5
  15. data/lib/right_agent/platform.rb +8 -0
  16. data/lib/right_agent/platform/darwin.rb +14 -0
  17. data/lib/right_agent/platform/linux.rb +23 -0
  18. data/lib/right_agent/platform/windows.rb +31 -0
  19. data/lib/right_agent/scripts/agent_controller.rb +16 -8
  20. data/lib/right_agent/scripts/agent_deployer.rb +6 -0
  21. data/lib/right_agent/scripts/log_level_manager.rb +4 -5
  22. data/lib/right_agent/scripts/stats_manager.rb +9 -1
  23. data/lib/right_agent/sender.rb +623 -371
  24. data/lib/right_agent/stats_helper.rb +15 -1
  25. data/lib/right_agent/tracer.rb +1 -1
  26. data/right_agent.gemspec +14 -15
  27. data/spec/agent_config_spec.rb +9 -0
  28. data/spec/agent_spec.rb +154 -18
  29. data/spec/broker_client_spec.rb +171 -170
  30. data/spec/dispatcher_spec.rb +24 -8
  31. data/spec/ha_broker_client_spec.rb +55 -33
  32. data/spec/monkey_patches/amqp_patch_spec.rb +12 -0
  33. data/spec/packets_spec.rb +2 -0
  34. data/spec/sender_spec.rb +140 -69
  35. data/spec/stats_helper_spec.rb +5 -0
  36. metadata +54 -53
@@ -515,6 +515,7 @@ module RightScale
515
515
  sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "last reset", time_at(stats["last reset time"])) +
516
516
  sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "service up", elapsed(stats["service uptime"]))
517
517
  str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "machine up", elapsed(stats["machine uptime"])) if stats.has_key?("machine uptime")
518
+ str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "memory KB", stats["memory"]) if stats.has_key?("memory")
518
519
  str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "version", stats["version"].to_i) if stats.has_key?("version")
519
520
  str += brokers_str(stats["brokers"], name_width) if stats.has_key?("brokers")
520
521
  stats.to_a.sort.each { |k, v| str += sub_stats_str(k[0..-7], v, name_width) if k.to_s =~ /stats$/ }
@@ -537,6 +538,7 @@ module RightScale
537
538
  # "exceptions"(Hash|nil):: Exceptions raised per category, or nil if none
538
539
  # "total"(Integer):: Total exceptions for this category
539
540
  # "recent"(Array):: Most recent as a hash of "count", "type", "message", "when", and "where"
541
+ # "heartbeat"(Integer|nil):: Number of seconds between AMQP heartbeats, or nil if heartbeat disabled
540
542
  # "returns"(Hash|nil):: Message return activity stats with keys "total", "percent", "last", and "rate"
541
543
  # with percentage breakdown per request type, or nil if none
542
544
  # name_width(Integer):: Fixed width for left-justified name display
@@ -571,6 +573,13 @@ module RightScale
571
573
  exceptions_str(brokers["exceptions"], sub_value_indent) + "\n"
572
574
  end
573
575
  str += value_indent
576
+ str += sprintf("%-#{sub_name_width}s#{SEPARATOR}", "heartbeat")
577
+ str += if [nil, 0].include?(brokers["heartbeat"])
578
+ "none\n"
579
+ else
580
+ "#{brokers["heartbeat"]} sec\n"
581
+ end
582
+ str += value_indent
574
583
  str += sprintf("%-#{sub_name_width}s#{SEPARATOR}", "returns")
575
584
  str += if brokers["returns"].nil? || brokers["returns"].empty?
576
585
  "none\n"
@@ -652,6 +661,11 @@ module RightScale
652
661
  str += ", last: #{last_activity_str(value['last'], single_item = true)}" if value["last"]
653
662
  str += ", rate: #{enough_precision(value['rate'])}/sec" if value["rate"]
654
663
  str += ", duration: #{enough_precision(value['duration'])} sec" if value["duration"]
664
+ value.each do |name, data|
665
+ unless ["total", "percent", "last", "rate", "duration"].include?(name)
666
+ str += ", #{name}: #{data.is_a?(String) ? data : data.inspect}"
667
+ end
668
+ end
655
669
  str
656
670
  end
657
671
 
@@ -728,4 +742,4 @@ module RightScale
728
742
 
729
743
  end # StatsHelper
730
744
 
731
- end # RightScale
745
+ end # RightScale
@@ -33,7 +33,7 @@ module RightScale
33
33
 
34
34
  class Tracer
35
35
 
36
- NON_TRACEABLE_CLASSES = [ 'Kernel', 'Module', 'Object' , 'SyslogLogger', 'RightSupport::SystemLogger' ] +
36
+ NON_TRACEABLE_CLASSES = [ 'Kernel', 'Module', 'Object' , 'SyslogLogger', 'RightSupport::Log::SystemLogger' ] +
37
37
  [ 'RightScale::Tracer', 'RightScale::Multiplexer' ] +
38
38
  [ 'RightScale::Log', 'RightScale::Log::Formatter' ]
39
39
 
@@ -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.5.1'
27
+ spec.version = '0.5.10'
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'
@@ -36,22 +36,21 @@ Gem::Specification.new do |spec|
36
36
  spec.required_ruby_version = '>= 1.8.7'
37
37
  spec.require_path = 'lib'
38
38
 
39
- spec.add_dependency('right_support')
40
- spec.add_dependency('amqp', "0.6.7")
41
- spec.add_dependency('json', [">= 1.4.4", "<= 1.4.6"])
42
- spec.add_dependency('eventmachine', "~> 0.12.10")
43
- spec.add_dependency('right_popen', "~> 1.0.11")
44
- spec.add_dependency('msgpack', "0.4.4")
39
+ spec.add_dependency('right_support', '~> 1.0')
40
+ spec.add_dependency('amqp', '0.7.1')
41
+ spec.add_dependency('json', ['~> 1.4'])
42
+ spec.add_dependency('eventmachine', '~> 0.12.10')
43
+ spec.add_dependency('right_popen', '~> 1.0.11')
44
+ spec.add_dependency('msgpack', '0.4.4')
45
45
 
46
46
  spec.description = <<-EOF
47
- RightAgent provides a foundation for running an agent on a server to interface
48
- in a secure fashion with other agents in the RightScale system. A RightAgent
49
- uses RabbitMQ as the message bus and the RightScale mapper as the routing node.
50
- Servers running a RightAgent establish a queue on startup for receiving packets
51
- routed to it via the mapper. The packets are structured to invoke services in
52
- the agent represented by actors and methods. The RightAgent may respond to these
53
- requests with a result packet that the mapper then routes to the originator.
54
- Similarly a RightAgent can also make requests of other RightAgents in the
47
+ RightAgent provides a foundation for running an agent on a server to interface
48
+ in a secure fashion with other agents in the RightScale system. A RightAgent
49
+ uses RabbitMQ as the message bus and the RightScale mapper as the routing node.
50
+ Servers running a RightAgent establish a queue on startup for receiving packets
51
+ routed to it via the mapper. The packets are structured to invoke services in
52
+ the agent represented by actors and methods. The RightAgent may respond to these
53
+ requests with a result packet that the mapper then routes to the originator.
55
54
  EOF
56
55
 
57
56
  candidates = Dir.glob("{lib,spec}/**/*") +
@@ -63,6 +63,7 @@ describe RightScale::AgentConfig do
63
63
  @agent_options2 = {
64
64
  :identity => @agent_id2,
65
65
  :root_dir => @root_dir2,
66
+ :pid_dir => @pid_dir
66
67
  }
67
68
  FileUtils.mkdir_p(@cfg_agent2_dir = File.join(@cfg_dir, 'agent_2'))
68
69
  FileUtils.touch([@cfg_agent2 = File.join(@cfg_agent2_dir, 'config.yml')])
@@ -223,4 +224,12 @@ describe RightScale::AgentConfig do
223
224
  @agent_config.agent_options("no_agent").should == {}
224
225
  end
225
226
 
227
+ it 'should return the name of agents that are running' do
228
+ flexmock(Process).should_receive(:getpgid).with(@pid).and_return(123)
229
+ @agent_config.cfg_dir = @cfg_dir
230
+ @agent_config.cfg_agents.should =~ ['agent_1', 'agent_2']
231
+ @agent_config.running_agents.should =~ ['agent_1']
232
+ @agent_config.running_agents(/core/).should =~ []
233
+ end
234
+
226
235
  end
@@ -37,7 +37,8 @@ describe RightScale::Agent do
37
37
  describe "Default Option" do
38
38
 
39
39
  before(:all) do
40
- flexmock(RightScale::Log).should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
40
+ @log = flexmock(RightScale::Log)
41
+ @log.should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
41
42
  flexmock(EM).should_receive(:next_tick).and_yield
42
43
  flexmock(EM).should_receive(:add_timer).and_yield
43
44
  @timer = flexmock("timer")
@@ -101,6 +102,11 @@ describe RightScale::Agent do
101
102
  @agent.options[:root_dir].should == Dir.pwd
102
103
  end
103
104
 
105
+ it "for heartbeat is 60" do
106
+ @agent.options.should include(:heartbeat)
107
+ @agent.options[:heartbeat].should == 60
108
+ end
109
+
104
110
  end
105
111
 
106
112
  describe "Options from config.yml" do
@@ -120,7 +126,8 @@ describe RightScale::Agent do
120
126
  describe "Passed in Options" do
121
127
 
122
128
  before(:each) do
123
- flexmock(RightScale::Log).should_receive(:error).never.by_default
129
+ @log = flexmock(RightScale::Log)
130
+ @log.should_receive(:error).never.by_default
124
131
  flexmock(EM).should_receive(:next_tick).and_yield
125
132
  flexmock(EM).should_receive(:add_timer).and_yield
126
133
  @timer = flexmock("timer")
@@ -204,6 +211,12 @@ describe RightScale::Agent do
204
211
  @agent.options[:ping_time].should == 5
205
212
  end
206
213
 
214
+ it "for heartbeat should override default (60)" do
215
+ @agent = RightScale::Agent.new(:heartbeat => 45, :identity => @identity)
216
+ @agent.options.should include(:heartbeat)
217
+ @agent.options[:heartbeat].should == 45
218
+ end
219
+
207
220
  it "for root_dir should override default (#{File.dirname(__FILE__)})" do
208
221
  root_dir = File.normalize_path(File.join(File.dirname(__FILE__), '..', '..'))
209
222
  @agent = RightScale::Agent.new(:root_dir => root_dir, :identity => @identity)
@@ -234,7 +247,8 @@ describe RightScale::Agent do
234
247
  describe "" do
235
248
 
236
249
  before(:each) do
237
- flexmock(RightScale::Log).should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
250
+ @log = flexmock(RightScale::Log)
251
+ @log.should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
238
252
  flexmock(EM).should_receive(:next_tick).and_yield
239
253
  flexmock(EM).should_receive(:add_timer).and_yield
240
254
  @timer = flexmock("timer")
@@ -244,14 +258,16 @@ describe RightScale::Agent do
244
258
  flexmock(EM::PeriodicTimer).should_receive(:new).and_return(@periodic_timer)
245
259
  @periodic_timer.should_receive(:cancel).by_default
246
260
  @broker_id = "rs-broker-123-1"
247
- @broker_ids = ["rs-broker-123-1", "rs-broker-123-2"]
261
+ @broker_id2 = "rs-broker-123-2"
262
+ @broker_ids = [@broker_id, @broker_id2]
248
263
  @broker = flexmock("broker", :subscribe => @broker_ids, :publish => @broker_ids.first(1), :prefetch => true,
249
264
  :all => @broker_ids, :connected => @broker_ids.first(1), :failed => @broker_ids.last(1),
250
265
  :unusable => @broker_ids.last(1), :close_one => true, :non_delivery => true,
251
- :stats => "", :identity_parts => ["123", 2, 1, 1, nil], :status => "status",
252
- :hosts => ["123"], :ports => [1, 2], :get => true, :alias_ => "b1",
253
- :aliases => ["b1"]).by_default
254
- @broker.should_receive(:connection_status).and_yield(:connected)
266
+ :stats => "", :status => "status", :hosts => ["123"], :ports => [1, 2], :get => true,
267
+ :alias_ => "b1", :aliases => ["b1"]).by_default
268
+ @broker.should_receive(:connection_status).and_yield(:connected).by_default
269
+ @broker.should_receive(:identity_parts).with(@broker_id).and_return(["123", 1, 0, 0, nil])
270
+ @broker.should_receive(:identity_parts).with(@broker_id2).and_return(["123", 2, 1, 1, nil])
255
271
  flexmock(RightScale::HABrokerClient).should_receive(:new).and_return(@broker)
256
272
  flexmock(RightScale::PidFile).should_receive(:new).
257
273
  and_return(flexmock("pid file", :check=>true, :write=>true, :remove=>true))
@@ -321,7 +337,7 @@ describe RightScale::Agent do
321
337
  @agent.run
322
338
  @broker.should_receive(:connect).with("123", 2, 1, 1, nil, false, Proc).and_yield(@broker_ids.last).once
323
339
  @broker.should_receive(:connection_status).and_yield(:failed)
324
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker/).once
340
+ @log.should_receive(:error).with(/Failed to connect to broker/).once
325
341
  flexmock(@agent).should_receive(:update_configuration).never
326
342
  @agent.connect("123", 2, 1, 1)
327
343
  end
@@ -361,7 +377,7 @@ describe RightScale::Agent do
361
377
  @broker.should_receive(:remove).never
362
378
  @broker.should_receive(:close_one).never
363
379
  flexmock(@agent).should_receive(:update_configuration).never
364
- flexmock(RightScale::Log).should_receive(:error).with(/Not disconnecting.*last connected broker/).once
380
+ @log.should_receive(:error).with(/Not disconnecting.*last connected broker/).once
365
381
  @agent.disconnect("123", 1)
366
382
  end
367
383
  end
@@ -421,6 +437,126 @@ describe RightScale::Agent do
421
437
 
422
438
  end
423
439
 
440
+ describe "Tuning heartbeat" do
441
+
442
+ it "should tune heartbeat for all broker connections" do
443
+ run_in_em do
444
+ @log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker/).twice
445
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
446
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
447
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
448
+ @agent.run
449
+ @broker.should_receive(:heartbeat=).with(45).once
450
+ @broker.should_receive(:connect).with("123", 1, 0, 0, nil, true, Proc).and_yield(@broker_id).once
451
+ @broker.should_receive(:connect).with("123", 2, 1, 1, nil, true, Proc).and_yield(@broker_id2).once
452
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).once
453
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
454
+ @agent.tune_heartbeat(45).should be_nil
455
+ end
456
+ end
457
+
458
+ it "should tune heartbeat for all broker connections as deferred task" do
459
+ run_in_em do
460
+ @log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker/).twice
461
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
462
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
463
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
464
+ @agent.run
465
+ @broker.should_receive(:heartbeat=).with(45).once
466
+ @broker.should_receive(:connect).with("123", 1, 0, 0, nil, true, Proc).and_yield(@broker_id).once
467
+ @broker.should_receive(:connect).with("123", 2, 1, 1, nil, true, Proc).and_yield(@broker_id2).once
468
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).once
469
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
470
+ flexmock(@agent).should_receive(:finish_setup)
471
+ @agent.defer_task { @agent.tune_heartbeat(45).should be_nil }
472
+ @agent.__send__(:check_status)
473
+ @agent.instance_variable_get(:@deferred_tasks).should == []
474
+ end
475
+ end
476
+
477
+ it "should disable heartbeat for all broker connections" do
478
+ run_in_em do
479
+ @log.should_receive(:info).with(/Disabled heartbeat for broker/).twice
480
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
481
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
482
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 0).and_return(true).once
483
+ @agent.run
484
+ @broker.should_receive(:heartbeat=).with(0).once
485
+ @broker.should_receive(:connect).with("123", 1, 0, 0, nil, true, Proc).and_yield(@broker_id).once
486
+ @broker.should_receive(:connect).with("123", 2, 1, 1, nil, true, Proc).and_yield(@broker_id2).once
487
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).once
488
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
489
+ @agent.tune_heartbeat(0).should be_nil
490
+ end
491
+ end
492
+
493
+ it "should log error if any broker connect attempts fail" do
494
+ run_in_em do
495
+ @log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker #{@broker_id2}/).once
496
+ @log.should_receive(:error).with("Failed to reconnect to broker #{@broker_id} to tune heartbeat", Exception, :trace).once
497
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
498
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
499
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
500
+ @agent.run
501
+ @broker.should_receive(:heartbeat=).with(45).once
502
+ @broker.should_receive(:connect).with("123", 1, 0, 0, nil, true, Proc).and_raise(Exception).once
503
+ @broker.should_receive(:connect).with("123", 2, 1, 1, nil, true, Proc).and_yield(@broker_id2).once
504
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).never
505
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
506
+ @agent.tune_heartbeat(45).should == "Failed to tune heartbeat for brokers [\"#{@broker_id}\"]"
507
+ end
508
+ end
509
+
510
+ it "should log error if any brokers do not connect" do
511
+ run_in_em do
512
+ @log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker #{@broker_id2}/).once
513
+ @log.should_receive(:error).with(/Failed to reconnect to broker #{@broker_id} to tune heartbeat, status/).once
514
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
515
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
516
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
517
+ @agent.run
518
+ @broker.should_receive(:heartbeat=).with(45).once
519
+ @broker.should_receive(:connect).with("123", 1, 0, 0, nil, true, Proc).and_yield(@broker_id).once
520
+ @broker.should_receive(:connect).with("123", 2, 1, 1, nil, true, Proc).and_yield(@broker_id2).once
521
+ @broker.should_receive(:connection_status).with({:one_off => 60, :brokers => [@broker_id]}, Proc).and_yield(:failed)
522
+ @broker.should_receive(:connection_status).with({:one_off => 60, :brokers => [@broker_id2]}, Proc).and_yield(:connected)
523
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).never
524
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
525
+ @agent.tune_heartbeat(45).should be_nil
526
+ end
527
+ end
528
+
529
+ it "should log error if any broker queue setup fails" do
530
+ run_in_em do
531
+ @log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker #{@broker_id2}/).once
532
+ @log.should_receive(:error).with(/Failed to setup queues for broker #{@broker_id} when tuning heartbeat/, Exception, :trace).once
533
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
534
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
535
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
536
+ @agent.run
537
+ @broker.should_receive(:heartbeat=).with(45).once
538
+ @broker.should_receive(:connect).with("123", 1, 0, 0, nil, true, Proc).and_yield(@broker_id).once
539
+ @broker.should_receive(:connect).with("123", 2, 1, 1, nil, true, Proc).and_yield(@broker_id2).once
540
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).and_raise(Exception)
541
+ flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
542
+ @agent.tune_heartbeat(45).should be_nil
543
+ end
544
+ end
545
+
546
+ it "should log error if an exception is raised" do
547
+ run_in_em do
548
+ @log.should_receive(:error).with(/Failed tuning broker connection heartbeat/, Exception, :trace).once
549
+ @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
550
+ flexmock(@agent).should_receive(:load_actors).and_return(true)
551
+ flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_raise(Exception).once
552
+ @agent.run
553
+ @broker.should_receive(:heartbeat=).with(45).once
554
+ @agent.tune_heartbeat(45).should =~ /Failed tuning broker connection heartbeat/
555
+ end
556
+ end
557
+
558
+ end
559
+
424
560
  describe "Terminating" do
425
561
 
426
562
  it "should close unusable broker connections at start of termination" do
@@ -477,8 +613,8 @@ describe RightScale::Agent do
477
613
  @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
478
614
  flexmock(@agent).should_receive(:load_actors).and_return(true)
479
615
  @agent.run
480
- flexmock(RightScale::Log).should_receive(:info).with(/Agent rs-instance-123-1 terminating/).once
481
- flexmock(RightScale::Log).should_receive(:info).with(/Termination waiting 9 seconds for/).once
616
+ @log.should_receive(:info).with(/Agent rs-instance-123-1 terminating/).once
617
+ @log.should_receive(:info).with(/Termination waiting 9 seconds for/).once
482
618
  @agent.terminate
483
619
  end
484
620
  end
@@ -492,8 +628,8 @@ describe RightScale::Agent do
492
628
  @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
493
629
  flexmock(@agent).should_receive(:load_actors).and_return(true)
494
630
  @agent.run
495
- flexmock(RightScale::Log).should_receive(:info).with(/Agent rs-instance-123-1 terminating/).once
496
- flexmock(RightScale::Log).should_receive(:info).with(/Termination waiting/).never
631
+ @log.should_receive(:info).with(/Agent rs-instance-123-1 terminating/).once
632
+ @log.should_receive(:info).with(/Termination waiting/).never
497
633
  @agent.terminate
498
634
  end
499
635
  end
@@ -508,10 +644,10 @@ describe RightScale::Agent do
508
644
  @agent = RightScale::Agent.new(:user => "me", :identity => @identity)
509
645
  flexmock(@agent).should_receive(:load_actors).and_return(true)
510
646
  @agent.run
511
- flexmock(RightScale::Log).should_receive(:info).with(/Agent rs-instance-123-1 terminating/).once
512
- flexmock(RightScale::Log).should_receive(:info).with(/Termination waiting/).once
513
- flexmock(RightScale::Log).should_receive(:info).with(/Continuing with termination/).once
514
- flexmock(RightScale::Log).should_receive(:info).with(/The following 1 request/).once
647
+ @log.should_receive(:info).with(/Agent rs-instance-123-1 terminating/).once
648
+ @log.should_receive(:info).with(/Termination waiting/).once
649
+ @log.should_receive(:info).with(/Continuing with termination/).once
650
+ @log.should_receive(:info).with(/The following 1 request/).once
515
651
  @agent.terminate
516
652
  end
517
653
  end
@@ -27,17 +27,18 @@ describe RightScale::BrokerClient do
27
27
  include FlexMock::ArgumentTypes
28
28
 
29
29
  before(:each) do
30
- flexmock(RightScale::Log).should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
31
- flexmock(RightScale::Log).should_receive(:warning).by_default.and_return { |m| raise RightScale::Log.format(*m) }
32
- flexmock(RightScale::Log).should_receive(:info).by_default
30
+ @log = flexmock(RightScale::Log)
31
+ @log.should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
32
+ @log.should_receive(:warning).by_default.and_return { |m| raise RightScale::Log.format(*m) }
33
+ @log.should_receive(:info).by_default
33
34
  @serializer = flexmock("serializer")
34
35
  @exceptions = flexmock("exception_stats")
35
36
  @exceptions.should_receive(:track).never.by_default
36
37
  @connection = flexmock("connection")
37
38
  @connection.should_receive(:connection_status).by_default
38
39
  flexmock(AMQP).should_receive(:connect).and_return(@connection).by_default
39
- @mq = flexmock("mq")
40
- @mq.should_receive(:connection).and_return(@connection).by_default
40
+ @channel = flexmock("AMQP connection channel")
41
+ @channel.should_receive(:connection).and_return(@connection).by_default
41
42
  @identity = "rs-broker-localhost-5672"
42
43
  @address = {:host => "localhost", :port => 5672, :index => 0}
43
44
  @options = {}
@@ -48,8 +49,8 @@ describe RightScale::BrokerClient do
48
49
  before(:each) do
49
50
  @amqp = flexmock(AMQP)
50
51
  @amqp.should_receive(:connect).and_return(@connection).by_default
51
- @mq.should_receive(:prefetch).never.by_default
52
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
52
+ @channel.should_receive(:prefetch).never.by_default
53
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
53
54
  @island = flexmock("island", :id => 2, :broker_hosts => "local_host").by_default
54
55
  end
55
56
 
@@ -110,16 +111,16 @@ describe RightScale::BrokerClient do
110
111
  end
111
112
 
112
113
  it "should log an info message when it creates an AMQP connection" do
113
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting to broker/).once
114
+ @log.should_receive(:info).with(/Connecting to broker/).once
114
115
  RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
115
116
  end
116
117
 
117
118
  it "should log an error and set status to :failed if it fails to create an AMQP connection" do
118
119
  @exceptions.should_receive(:track).once
119
120
  @connection.should_receive(:close).once
120
- flexmock(RightScale::Log).should_receive(:info).once
121
- flexmock(RightScale::Log).should_receive(:error).with(/Failed connecting/, Exception, :trace).once
122
- flexmock(MQ).should_receive(:new).with(@connection).and_raise(Exception)
121
+ @log.should_receive(:info).once
122
+ @log.should_receive(:error).with(/Failed connecting/, Exception, :trace).once
123
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_raise(Exception)
123
124
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
124
125
  broker.summary.should == {:alias => "b0", :identity => @identity, :status => :failed,
125
126
  :disconnects => 0, :failures => 1, :retries => 0}
@@ -131,7 +132,7 @@ describe RightScale::BrokerClient do
131
132
  end
132
133
 
133
134
  it "should set broker prefetch value if specified" do
134
- @mq.should_receive(:prefetch).with(1).once
135
+ @channel.should_receive(:prefetch).with(1).once
135
136
  RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, {:prefetch => 1})
136
137
  end
137
138
 
@@ -149,17 +150,17 @@ describe RightScale::BrokerClient do
149
150
  @bind = flexmock("bind")
150
151
  @queue = flexmock("queue")
151
152
  @queue.should_receive(:bind).and_return(@bind).by_default
152
- @mq.should_receive(:queue).and_return(@queue).by_default
153
- @mq.should_receive(:direct).and_return(@direct).by_default
154
- @mq.should_receive(:fanout).and_return(@fanout).by_default
155
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
153
+ @channel.should_receive(:queue).and_return(@queue).by_default
154
+ @channel.should_receive(:direct).and_return(@direct).by_default
155
+ @channel.should_receive(:fanout).and_return(@fanout).by_default
156
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
156
157
  end
157
158
 
158
159
  it "should subscribe queue to exchange" do
159
160
  @queue.should_receive(:bind).and_return(@bind).once
160
161
  @bind.should_receive(:subscribe).once
161
162
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
162
- broker.__send__(:update_status, :ready)
163
+ broker.__send__(:update_status, :connected)
163
164
  broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) {|_, _|}
164
165
  end
165
166
 
@@ -167,7 +168,7 @@ describe RightScale::BrokerClient do
167
168
  @queue.should_receive(:bind).and_return(@bind).twice
168
169
  @bind.should_receive(:subscribe).once
169
170
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
170
- broker.__send__(:update_status, :ready)
171
+ broker.__send__(:update_status, :connected)
171
172
  options = {:exchange2 => {:type => :fanout, :name => "exchange2", :options => {:durable => true}}}
172
173
  broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}, options) {|_, _|}
173
174
  end
@@ -181,7 +182,7 @@ describe RightScale::BrokerClient do
181
182
  it "should subscribe queue to empty exchange if no exchange specified" do
182
183
  @queue.should_receive(:subscribe).once
183
184
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
184
- broker.__send__(:update_status, :ready)
185
+ broker.__send__(:update_status, :connected)
185
186
  broker.subscribe({:name => "queue"}) {|b, p| p.should == nil}
186
187
  end
187
188
 
@@ -215,7 +216,7 @@ describe RightScale::BrokerClient do
215
216
  @info.should_receive(:ack).once
216
217
  @bind.should_receive(:subscribe).and_yield(@info, @message).once
217
218
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
218
- broker.__send__(:update_status, :ready)
219
+ broker.__send__(:update_status, :connected)
219
220
  result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
220
221
  :ack => true, RightScale::Request => true) {|b, p| p.should == @packet}
221
222
  result.should be_true
@@ -230,64 +231,64 @@ describe RightScale::BrokerClient do
230
231
  end
231
232
 
232
233
  it "should receive message causing it to be unserialized and logged" do
233
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
234
- flexmock(RightScale::Log).should_receive(:info).with(/Subscribing/).once
235
- flexmock(RightScale::Log).should_receive(:info).with(/RECV/).once
234
+ @log.should_receive(:info).with(/Connecting/).once
235
+ @log.should_receive(:info).with(/Subscribing/).once
236
+ @log.should_receive(:info).with(/RECV/).once
236
237
  @serializer.should_receive(:load).with(@message).and_return(@packet).once
237
238
  @bind.should_receive(:subscribe).and_yield(@message).once
238
239
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
239
- broker.__send__(:update_status, :ready)
240
+ broker.__send__(:update_status, :connected)
240
241
  broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
241
242
  RightScale::Request => nil) {|b, p| p.class.should == RightScale::Request}
242
243
  end
243
244
 
244
245
  it "should receive message and log exception if subscribe block fails" do
245
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
246
- flexmock(RightScale::Log).should_receive(:info).with(/Subscribing/).once
247
- flexmock(RightScale::Log).should_receive(:error).with(/Failed executing block/, Exception, :trace).once
246
+ @log.should_receive(:info).with(/Connecting/).once
247
+ @log.should_receive(:info).with(/Subscribing/).once
248
+ @log.should_receive(:error).with(/Failed executing block/, Exception, :trace).once
248
249
  @exceptions.should_receive(:track).once
249
250
  @serializer.should_receive(:load).with(@message).and_return(@packet).once
250
251
  @bind.should_receive(:subscribe).and_yield(@message).once
251
252
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
252
- broker.__send__(:update_status, :ready)
253
+ broker.__send__(:update_status, :connected)
253
254
  result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
254
255
  RightScale::Request => nil) {|b, p| raise Exception}
255
256
  result.should be_false
256
257
  end
257
258
 
258
259
  it "should ignore 'nil' message when using ack" do
259
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
260
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
261
- flexmock(RightScale::Log).should_receive(:info).with(/Subscribing/).once
262
- flexmock(RightScale::Log).should_receive(:debug).with(/nil message ignored/).once
260
+ @log.should_receive(:level).and_return(:debug)
261
+ @log.should_receive(:info).with(/Connecting/).once
262
+ @log.should_receive(:info).with(/Subscribing/).once
263
+ @log.should_receive(:debug).with(/nil message ignored/).once
263
264
  @bind.should_receive(:subscribe).and_yield(@info, "nil").once
264
265
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
265
- broker.__send__(:update_status, :ready)
266
+ broker.__send__(:update_status, :connected)
266
267
  called = 0
267
268
  broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}, :ack => true) { |b, m| called += 1 }
268
269
  called.should == 0
269
270
  end
270
271
 
271
272
  it "should ignore 'nil' message when not using ack" do
272
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
273
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
274
- flexmock(RightScale::Log).should_receive(:info).with(/Subscribing/).once
275
- flexmock(RightScale::Log).should_receive(:debug).with(/nil message ignored/).once
273
+ @log.should_receive(:level).and_return(:debug)
274
+ @log.should_receive(:info).with(/Connecting/).once
275
+ @log.should_receive(:info).with(/Subscribing/).once
276
+ @log.should_receive(:debug).with(/nil message ignored/).once
276
277
  @bind.should_receive(:subscribe).and_yield("nil").once
277
278
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
278
- broker.__send__(:update_status, :ready)
279
+ broker.__send__(:update_status, :connected)
279
280
  called = 0
280
281
  broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) { |b, m| called += 1 }
281
282
  called.should == 0
282
283
  end
283
284
 
284
285
  it "should not unserialize the message if requested" do
285
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
286
- flexmock(RightScale::Log).should_receive(:info).with(/Subscribing/).once
287
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV/).never
286
+ @log.should_receive(:info).with(/Connecting/).once
287
+ @log.should_receive(:info).with(/Subscribing/).once
288
+ @log.should_receive(:info).with(/^RECV/).never
288
289
  @bind.should_receive(:subscribe).and_yield(@message).once
289
290
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
290
- broker.__send__(:update_status, :ready)
291
+ broker.__send__(:update_status, :connected)
291
292
  broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}, :no_unserialize => true) do |b, m|
292
293
  b.should == "rs-broker-localhost-5672"
293
294
  m.should == @message
@@ -295,13 +296,13 @@ describe RightScale::BrokerClient do
295
296
  end
296
297
 
297
298
  it "should log an error if a subscribe fails" do
298
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
299
- flexmock(RightScale::Log).should_receive(:info).with(/RECV/).never
300
- flexmock(RightScale::Log).should_receive(:error).with(/Failed subscribing/, Exception, :trace).once
299
+ @log.should_receive(:info).with(/Connecting/).once
300
+ @log.should_receive(:info).with(/RECV/).never
301
+ @log.should_receive(:error).with(/Failed subscribing/, Exception, :trace).once
301
302
  @exceptions.should_receive(:track).once
302
303
  @bind.should_receive(:subscribe).and_raise(Exception)
303
304
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
304
- broker.__send__(:update_status, :ready)
305
+ broker.__send__(:update_status, :connected)
305
306
  result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) {|b, p|}
306
307
  result.should be_false
307
308
  end
@@ -317,74 +318,74 @@ describe RightScale::BrokerClient do
317
318
  end
318
319
 
319
320
  it "should unserialize the message, log it, and return it" do
320
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
321
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV/).once
321
+ @log.should_receive(:info).with(/Connecting/).once
322
+ @log.should_receive(:info).with(/^RECV/).once
322
323
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
323
324
  broker.__send__(:receive, "queue", @message, RightScale::Request => nil).should == @packet
324
325
  end
325
326
 
326
327
  it "should log a warning if the message is not of the right type and return nil" do
327
- flexmock(RightScale::Log).should_receive(:warning).with(/Received invalid.*packet type/).once
328
+ @log.should_receive(:warning).with(/Received invalid.*packet type/).once
328
329
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
329
330
  broker.__send__(:receive, "queue", @message).should be_nil
330
331
  end
331
332
 
332
333
  it "should show the category in the warning message if specified" do
333
- flexmock(RightScale::Log).should_receive(:warning).with(/Received invalid xxxx packet type/).once
334
+ @log.should_receive(:warning).with(/Received invalid xxxx packet type/).once
334
335
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
335
336
  broker.__send__(:receive, "queue", @message, RightScale::Result => nil, :category => "xxxx")
336
337
  end
337
338
 
338
339
  it "should display broker alias in the log" do
339
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
340
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV b0 /).once
340
+ @log.should_receive(:info).with(/Connecting/).once
341
+ @log.should_receive(:info).with(/^RECV b0 /).once
341
342
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
342
343
  broker.__send__(:receive, "queue", @message, RightScale::Request => nil)
343
344
  end
344
345
 
345
346
  it "should filter the packet display for :info level" do
346
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
347
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV.*TO YOU/).once
348
- flexmock(RightScale::Log).should_receive(:debug).with(/^RECV.*TO YOU/).never
347
+ @log.should_receive(:info).with(/Connecting/).once
348
+ @log.should_receive(:info).with(/^RECV.*TO YOU/).once
349
+ @log.should_receive(:debug).with(/^RECV.*TO YOU/).never
349
350
  @packet.should_receive(:to_s).with([:to], :recv_version).and_return("TO YOU").once
350
351
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
351
352
  broker.__send__(:receive, "queue", @message, RightScale::Request => [:to])
352
353
  end
353
354
 
354
355
  it "should not filter the packet display for :debug level" do
355
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
356
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
357
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV.*ALL/).never
358
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV.*ALL/).once
356
+ @log.should_receive(:level).and_return(:debug)
357
+ @log.should_receive(:info).with(/Connecting/).once
358
+ @log.should_receive(:info).with(/^RECV.*ALL/).never
359
+ @log.should_receive(:info).with(/^RECV.*ALL/).once
359
360
  @packet.should_receive(:to_s).with(nil, :recv_version).and_return("ALL").once
360
361
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
361
362
  broker.__send__(:receive, "queue", @message, RightScale::Request => [:to])
362
363
  end
363
364
 
364
365
  it "should display additional data in log" do
365
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
366
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV.*More data/).once
366
+ @log.should_receive(:info).with(/Connecting/).once
367
+ @log.should_receive(:info).with(/^RECV.*More data/).once
367
368
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
368
369
  broker.__send__(:receive, "queue", @message, RightScale::Request => nil, :log_data => "More data")
369
370
  end
370
371
 
371
372
  it "should not log a message if requested not to" do
372
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
373
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV/).never
373
+ @log.should_receive(:info).with(/Connecting/).once
374
+ @log.should_receive(:info).with(/^RECV/).never
374
375
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
375
376
  broker.__send__(:receive, "queue", @message, RightScale::Request => nil, :no_log => true)
376
377
  end
377
378
 
378
379
  it "should not log a message if requested not to unless debug level" do
379
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
380
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
381
- flexmock(RightScale::Log).should_receive(:info).with(/^RECV/).once
380
+ @log.should_receive(:level).and_return(:debug)
381
+ @log.should_receive(:info).with(/Connecting/).once
382
+ @log.should_receive(:info).with(/^RECV/).once
382
383
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
383
384
  broker.__send__(:receive, "queue", @message, RightScale::Request => nil, :no_log => true)
384
385
  end
385
386
 
386
387
  it "should log an error if exception prevents normal logging and should then return nil" do
387
- flexmock(RightScale::Log).should_receive(:error).with(/Failed receiving from queue/, Exception, :trace).once
388
+ @log.should_receive(:error).with(/Failed receiving from queue/, Exception, :trace).once
388
389
  @serializer.should_receive(:load).with(@message).and_raise(Exception).once
389
390
  @exceptions.should_receive(:track).once
390
391
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
@@ -392,7 +393,7 @@ describe RightScale::BrokerClient do
392
393
  end
393
394
 
394
395
  it "should make callback when there is a receive failure" do
395
- flexmock(RightScale::Log).should_receive(:error).with(/Failed receiving from queue/, Exception, :trace).once
396
+ @log.should_receive(:error).with(/Failed receiving from queue/, Exception, :trace).once
396
397
  @serializer.should_receive(:load).with(@message).and_raise(Exception).once
397
398
  @exceptions.should_receive(:track).once
398
399
  called = 0
@@ -404,8 +405,8 @@ describe RightScale::BrokerClient do
404
405
  end
405
406
 
406
407
  it "should display RE-RECV if the message being received is a retry" do
407
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
408
- flexmock(RightScale::Log).should_receive(:info).with(/^RE-RECV/).once
408
+ @log.should_receive(:info).with(/Connecting/).once
409
+ @log.should_receive(:info).with(/^RE-RECV/).once
409
410
  @packet.should_receive(:tries).and_return(["try1"]).once
410
411
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
411
412
  broker.__send__(:receive, "queue", @message, RightScale::Request => nil).should == @packet
@@ -419,9 +420,9 @@ describe RightScale::BrokerClient do
419
420
  @direct = flexmock("direct")
420
421
  @bind = flexmock("bind", :subscribe => true)
421
422
  @queue = flexmock("queue", :bind => @bind, :name => "queue1")
422
- @mq.should_receive(:queue).and_return(@queue).by_default
423
- @mq.should_receive(:direct).and_return(@direct).by_default
424
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
423
+ @channel.should_receive(:queue).and_return(@queue).by_default
424
+ @channel.should_receive(:direct).and_return(@direct).by_default
425
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
425
426
  end
426
427
 
427
428
  it "should unsubscribe a queue by name" do
@@ -456,7 +457,7 @@ describe RightScale::BrokerClient do
456
457
  end
457
458
 
458
459
  it "should log an error if unsubscribe raises an exception and activate block if provided" do
459
- flexmock(RightScale::Log).should_receive(:error).with(/Failed unsubscribing/, Exception, :trace).once
460
+ @log.should_receive(:error).with(/Failed unsubscribing/, Exception, :trace).once
460
461
  @queue.should_receive(:unsubscribe).and_raise(Exception).once
461
462
  @exceptions.should_receive(:track).once
462
463
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
@@ -471,34 +472,34 @@ describe RightScale::BrokerClient do
471
472
  context "when declaring" do
472
473
 
473
474
  before(:each) do
474
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
475
- @mq.should_receive(:queues).and_return({}).by_default
476
- @mq.should_receive(:exchanges).and_return({}).by_default
475
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
476
+ @channel.should_receive(:queues).and_return({}).by_default
477
+ @channel.should_receive(:exchanges).and_return({}).by_default
477
478
  end
478
479
 
479
480
  it "should declare exchange and return true" do
480
- @mq.should_receive(:exchange).once
481
+ @channel.should_receive(:exchange).once
481
482
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
482
483
  broker.declare(:exchange, "x", :durable => true).should be_true
483
484
  end
484
485
 
485
486
  it "should delete the exchange or queue from the AMQP cache before declaring" do
486
- @mq.should_receive(:queue).once
487
+ @channel.should_receive(:queue).once
487
488
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
488
- flexmock(broker).should_receive(:delete_from_cache).with(:queue, "queue").once
489
+ flexmock(broker).should_receive(:delete_amqp_resources).with(:queue, "queue").once
489
490
  broker.declare(:queue, "queue", :durable => true).should be_true
490
491
  end
491
492
 
492
493
  it "should log declaration" do
493
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
494
- flexmock(RightScale::Log).should_receive(:info).with(/Declaring/).once
495
- @mq.should_receive(:queue).once
494
+ @log.should_receive(:info).with(/Connecting/).once
495
+ @log.should_receive(:info).with(/Declaring/).once
496
+ @channel.should_receive(:queue).once
496
497
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
497
498
  broker.declare(:queue, "q").should be_true
498
499
  end
499
500
 
500
501
  it "should return false if client not usable" do
501
- @mq.should_receive(:exchange).never
502
+ @channel.should_receive(:exchange).never
502
503
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
503
504
  broker.__send__(:update_status, :disconnected)
504
505
  broker.declare(:exchange, "x", :durable => true).should be_false
@@ -506,11 +507,11 @@ describe RightScale::BrokerClient do
506
507
  end
507
508
 
508
509
  it "should log an error if the declare fails and return false" do
509
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
510
- flexmock(RightScale::Log).should_receive(:info).with(/Declaring/).once
511
- flexmock(RightScale::Log).should_receive(:error).with(/Failed declaring/, Exception, :trace).once
510
+ @log.should_receive(:info).with(/Connecting/).once
511
+ @log.should_receive(:info).with(/Declaring/).once
512
+ @log.should_receive(:error).with(/Failed declaring/, Exception, :trace).once
512
513
  @exceptions.should_receive(:track).once
513
- @mq.should_receive(:queue).and_raise(Exception).once
514
+ @channel.should_receive(:queue).and_raise(Exception).once
514
515
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
515
516
  broker.declare(:queue, "q").should be_false
516
517
  end
@@ -523,30 +524,30 @@ describe RightScale::BrokerClient do
523
524
  @message = flexmock("message")
524
525
  @packet = flexmock("packet", :class => RightScale::Request, :to_s => true, :version => [12, 12]).by_default
525
526
  @direct = flexmock("direct")
526
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
527
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
527
528
  end
528
529
 
529
530
  it "should serialize message, publish it, and return true" do
530
- @mq.should_receive(:direct).with("exchange", :durable => true).and_return(@direct).once
531
+ @channel.should_receive(:direct).with("exchange", :durable => true).and_return(@direct).once
531
532
  @direct.should_receive(:publish).with(@message, :persistent => true).once
532
533
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
533
- broker.__send__(:update_status, :ready)
534
+ broker.__send__(:update_status, :connected)
534
535
  broker.publish({:type => :direct, :name => "exchange", :options => {:durable => true}},
535
536
  @packet, @message, :persistent => true).should be_true
536
537
  end
537
538
 
538
539
  it "should delete the exchange or queue from the AMQP cache if :declare specified" do
539
- @mq.should_receive(:direct).with("exchange", {:declare => true}).and_return(@direct)
540
+ @channel.should_receive(:direct).with("exchange", {:declare => true}).and_return(@direct)
540
541
  @direct.should_receive(:publish).with(@message, {})
541
542
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
542
- broker.__send__(:update_status, :ready)
543
+ broker.__send__(:update_status, :connected)
543
544
  exchange = {:type => :direct, :name => "exchange", :options => {:declare => true}}
544
- flexmock(broker).should_receive(:delete_from_cache).with(:direct, "exchange").once
545
+ flexmock(broker).should_receive(:delete_amqp_resources).with(:direct, "exchange").once
545
546
  broker.publish(exchange, @packet, @message).should be_true
546
547
  end
547
548
 
548
549
  it "should return false if client not connected" do
549
- @mq.should_receive(:direct).never
550
+ @channel.should_receive(:direct).never
550
551
  @direct.should_receive(:publish).with(@message, :persistent => true).never
551
552
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
552
553
  broker.publish({:type => :direct, :name => "exchange", :options => {:durable => true}},
@@ -554,111 +555,111 @@ describe RightScale::BrokerClient do
554
555
  end
555
556
 
556
557
  it "should log an error if the publish fails" do
557
- flexmock(RightScale::Log).should_receive(:error).with(/Failed publishing/, Exception, :trace).once
558
+ @log.should_receive(:error).with(/Failed publishing/, Exception, :trace).once
558
559
  @exceptions.should_receive(:track).once
559
- @mq.should_receive(:direct).and_raise(Exception)
560
+ @channel.should_receive(:direct).and_raise(Exception)
560
561
  @direct.should_receive(:publish).with(@message, {}).never
561
562
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
562
- broker.__send__(:update_status, :ready)
563
+ broker.__send__(:update_status, :connected)
563
564
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_false
564
565
  end
565
566
 
566
567
  it "should log that message is being sent with info about which broker used" do
567
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
568
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND b0/).once
569
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
568
+ @log.should_receive(:info).with(/Connecting/).once
569
+ @log.should_receive(:info).with(/^SEND b0/).once
570
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
570
571
  @direct.should_receive(:publish).with(@message, {}).once
571
572
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
572
- broker.__send__(:update_status, :ready)
573
+ broker.__send__(:update_status, :connected)
573
574
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
574
575
  end
575
576
 
576
577
  it "should log broker choices for :debug level" do
577
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
578
- flexmock(RightScale::Log).should_receive(:debug).with(/... publish options/).once
579
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
580
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND b0/).once
581
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
578
+ @log.should_receive(:level).and_return(:debug)
579
+ @log.should_receive(:debug).with(/... publish options/).once
580
+ @log.should_receive(:info).with(/Connecting/).once
581
+ @log.should_receive(:info).with(/^SEND b0/).once
582
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
582
583
  @direct.should_receive(:publish).with(@message, {}).once
583
584
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
584
- broker.__send__(:update_status, :ready)
585
+ broker.__send__(:update_status, :connected)
585
586
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
586
587
  end
587
588
 
588
589
  it "should not log a message if requested not to" do
589
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
590
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND/).never
591
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
590
+ @log.should_receive(:info).with(/Connecting/).once
591
+ @log.should_receive(:info).with(/^SEND/).never
592
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
592
593
  @direct.should_receive(:publish).with(@message, :no_log => true).once
593
594
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
594
- broker.__send__(:update_status, :ready)
595
+ broker.__send__(:update_status, :connected)
595
596
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :no_log => true).should be_true
596
597
  end
597
598
 
598
599
  it "should not log a message if requested not to unless debug level" do
599
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
600
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
601
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND/).once
602
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
600
+ @log.should_receive(:level).and_return(:debug)
601
+ @log.should_receive(:info).with(/Connecting/).once
602
+ @log.should_receive(:info).with(/^SEND/).once
603
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
603
604
  @direct.should_receive(:publish).with(@message, :no_log => true).once
604
605
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
605
- broker.__send__(:update_status, :ready)
606
+ broker.__send__(:update_status, :connected)
606
607
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :no_log => true).should be_true
607
608
  end
608
609
 
609
610
  it "should display broker alias in the log" do
610
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
611
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND b0 /).once
612
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
611
+ @log.should_receive(:info).with(/Connecting/).once
612
+ @log.should_receive(:info).with(/^SEND b0 /).once
613
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
613
614
  @direct.should_receive(:publish).with(@message, {}).once
614
615
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
615
- broker.__send__(:update_status, :ready)
616
+ broker.__send__(:update_status, :connected)
616
617
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
617
618
  end
618
619
 
619
620
  it "should filter the packet display for :info level" do
620
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
621
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND.*TO YOU/).once
622
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND.*TO YOU/).never
621
+ @log.should_receive(:info).with(/Connecting/).once
622
+ @log.should_receive(:info).with(/^SEND.*TO YOU/).once
623
+ @log.should_receive(:info).with(/^SEND.*TO YOU/).never
623
624
  @packet.should_receive(:to_s).with([:to], :send_version).and_return("TO YOU").once
624
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
625
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
625
626
  @direct.should_receive(:publish).with(@message, :log_filter => [:to]).once
626
627
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
627
- broker.__send__(:update_status, :ready)
628
+ broker.__send__(:update_status, :connected)
628
629
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :log_filter => [:to]).should be_true
629
630
  end
630
631
 
631
632
  it "should not filter the packet display for :debug level" do
632
- flexmock(RightScale::Log).should_receive(:level).and_return(:debug)
633
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
634
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND.*ALL/).never
635
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND.*ALL/).once
633
+ @log.should_receive(:level).and_return(:debug)
634
+ @log.should_receive(:info).with(/Connecting/).once
635
+ @log.should_receive(:info).with(/^SEND.*ALL/).never
636
+ @log.should_receive(:info).with(/^SEND.*ALL/).once
636
637
  @packet.should_receive(:to_s).with(nil, :send_version).and_return("ALL").once
637
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
638
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
638
639
  @direct.should_receive(:publish).with(@message, :log_filter => [:to]).once
639
640
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
640
- broker.__send__(:update_status, :ready)
641
+ broker.__send__(:update_status, :connected)
641
642
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :log_filter => [:to]).should be_true
642
643
  end
643
644
 
644
645
  it "should display additional data in log" do
645
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
646
- flexmock(RightScale::Log).should_receive(:info).with(/^SEND.*More data/).once
647
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
646
+ @log.should_receive(:info).with(/Connecting/).once
647
+ @log.should_receive(:info).with(/^SEND.*More data/).once
648
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
648
649
  @direct.should_receive(:publish).with(@message, :log_data => "More data").once
649
650
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
650
- broker.__send__(:update_status, :ready)
651
+ broker.__send__(:update_status, :connected)
651
652
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message, :log_data => "More data").should be_true
652
653
  end
653
654
 
654
655
  it "should display RE-SEND if the message being sent is a retry" do
655
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
656
- flexmock(RightScale::Log).should_receive(:info).with(/^RE-SEND/).once
656
+ @log.should_receive(:info).with(/Connecting/).once
657
+ @log.should_receive(:info).with(/^RE-SEND/).once
657
658
  @packet = flexmock("packet", :class => RightScale::Request, :to_s => true, :tries => ["try1"], :version => [12, 12])
658
- @mq.should_receive(:direct).with("exchange", {}).and_return(@direct).once
659
+ @channel.should_receive(:direct).with("exchange", {}).and_return(@direct).once
659
660
  @direct.should_receive(:publish).with(@message, {}).once
660
661
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
661
- broker.__send__(:update_status, :ready)
662
+ broker.__send__(:update_status, :connected)
662
663
  broker.publish({:type => :direct, :name => "exchange"}, @packet, @message).should be_true
663
664
  end
664
665
 
@@ -686,8 +687,8 @@ describe RightScale::BrokerClient do
686
687
  end
687
688
 
688
689
  it "should invoke block and log the return" do
689
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting to broker/).once
690
- flexmock(RightScale::Log).should_receive(:debug).with(/RETURN b0/).once
690
+ @log.should_receive(:info).with(/Connecting to broker/).once
691
+ @log.should_receive(:debug).with(/RETURN b0/).once
691
692
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
692
693
  called = 0
693
694
  broker.return_message do |to, reason, message|
@@ -696,7 +697,7 @@ describe RightScale::BrokerClient do
696
697
  reason.should == "NO_CONSUMERS"
697
698
  message.should == @message
698
699
  end
699
- broker.instance_variable_get(:@mq).on_return_message.call(@info, @message)
700
+ broker.instance_variable_get(:@channel).on_return_message.call(@info, @message)
700
701
  called.should == 1
701
702
  end
702
703
 
@@ -710,12 +711,12 @@ describe RightScale::BrokerClient do
710
711
  message.should == @message
711
712
  end
712
713
  @info.should_receive(:exchange).and_return("")
713
- broker.instance_variable_get(:@mq).on_return_message.call(@info, @message)
714
+ broker.instance_variable_get(:@channel).on_return_message.call(@info, @message)
714
715
  called.should == 1
715
716
  end
716
717
 
717
718
  it "should log an error if there is a failure while processing the return" do
718
- flexmock(RightScale::Log).should_receive(:error).with(/Failed return/, Exception, :trace).once
719
+ @log.should_receive(:error).with(/Failed return/, Exception, :trace).once
719
720
  @exceptions.should_receive(:track).once
720
721
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
721
722
  called = 0
@@ -723,7 +724,7 @@ describe RightScale::BrokerClient do
723
724
  called += 1
724
725
  raise Exception
725
726
  end
726
- broker.instance_variable_get(:@mq).on_return_message.call(@info, @message)
727
+ broker.instance_variable_get(:@channel).on_return_message.call(@info, @message)
727
728
  called.should == 1
728
729
  end
729
730
 
@@ -735,9 +736,9 @@ describe RightScale::BrokerClient do
735
736
  @direct = flexmock("direct")
736
737
  @bind = flexmock("bind", :subscribe => true)
737
738
  @queue = flexmock("queue", :bind => @bind, :name => "queue1")
738
- @mq.should_receive(:queue).and_return(@queue).by_default
739
- @mq.should_receive(:direct).and_return(@direct).by_default
740
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
739
+ @channel.should_receive(:queue).and_return(@queue).by_default
740
+ @channel.should_receive(:direct).and_return(@direct).by_default
741
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
741
742
  end
742
743
 
743
744
  it "should delete the named queue and return true" do
@@ -760,7 +761,7 @@ describe RightScale::BrokerClient do
760
761
  end
761
762
 
762
763
  it "should log an error and return false if the delete fails" do
763
- flexmock(RightScale::Log).should_receive(:error).with(/Failed deleting queue/, Exception, :trace).once
764
+ @log.should_receive(:error).with(/Failed deleting queue/, Exception, :trace).once
764
765
  @exceptions.should_receive(:track).once
765
766
  @queue.should_receive(:delete).and_raise(Exception)
766
767
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
@@ -776,17 +777,17 @@ describe RightScale::BrokerClient do
776
777
  include RightScale::StatsHelper
777
778
 
778
779
  before(:each) do
779
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
780
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
780
781
  end
781
782
 
782
783
  it "should distinguish whether the client is usable based on whether connecting or connected" do
783
784
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
784
785
  broker.usable?.should be_true
785
- broker.__send__(:update_status, :ready)
786
+ broker.__send__(:update_status, :connected)
786
787
  broker.usable?.should be_true
787
788
  broker.__send__(:update_status, :disconnected)
788
789
  broker.usable?.should be_false
789
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker b0/).once
790
+ @log.should_receive(:error).with(/Failed to connect to broker b0/).once
790
791
  broker.__send__(:update_status, :failed)
791
792
  broker.usable?.should be_false
792
793
  end
@@ -794,11 +795,11 @@ describe RightScale::BrokerClient do
794
795
  it "should distinguish whether the client is connected" do
795
796
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
796
797
  broker.connected?.should be_false
797
- broker.__send__(:update_status, :ready)
798
+ broker.__send__(:update_status, :connected)
798
799
  broker.connected?.should be_true
799
800
  broker.__send__(:update_status, :disconnected)
800
801
  broker.connected?.should be_false
801
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker b0/).once
802
+ @log.should_receive(:error).with(/Failed to connect to broker b0/).once
802
803
  broker.__send__(:update_status, :failed)
803
804
  broker.connected?.should be_false
804
805
  end
@@ -806,11 +807,11 @@ describe RightScale::BrokerClient do
806
807
  it "should distinguish whether the client has failed" do
807
808
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
808
809
  broker.failed?.should be_false
809
- broker.__send__(:update_status, :ready)
810
+ broker.__send__(:update_status, :connected)
810
811
  broker.failed?.should be_false
811
812
  broker.__send__(:update_status, :disconnected)
812
813
  broker.failed?.should be_false
813
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker b0/).once
814
+ @log.should_receive(:error).with(/Failed to connect to broker b0/).once
814
815
  broker.__send__(:update_status, :failed)
815
816
  broker.failed?.should be_true
816
817
  end
@@ -819,10 +820,10 @@ describe RightScale::BrokerClient do
819
820
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
820
821
  broker.summary.should == {:alias => "b0", :identity => @identity, :status => :connecting,
821
822
  :disconnects => 0, :failures => 0, :retries => 0}
822
- broker.__send__(:update_status, :ready)
823
+ broker.__send__(:update_status, :connected)
823
824
  broker.summary.should == {:alias => "b0", :identity => @identity, :status => :connected,
824
825
  :disconnects => 0, :failures => 0, :retries => 0}
825
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker/).once
826
+ @log.should_receive(:error).with(/Failed to connect to broker/).once
826
827
  broker.__send__(:update_status, :failed)
827
828
  broker.summary.should == {:alias => "b0", :identity => @identity, :status => :failed,
828
829
  :disconnects => 0, :failures => 1, :retries => 0}
@@ -833,11 +834,11 @@ describe RightScale::BrokerClient do
833
834
  broker.stats.should == {"alias" => "b0", "identity" => "rs-broker-localhost-5672",
834
835
  "status" => "connecting", "disconnects" => nil, "disconnect last" => nil,
835
836
  "failures" => nil, "failure last" => nil, "retries" => nil}
836
- broker.__send__(:update_status, :ready)
837
+ broker.__send__(:update_status, :connected)
837
838
  broker.stats.should == {"alias" => "b0", "identity" => "rs-broker-localhost-5672",
838
839
  "status" => "connected", "disconnects" => nil, "disconnect last" => nil,
839
840
  "failures" => nil, "failure last" => nil, "retries" => nil}
840
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker/).once
841
+ @log.should_receive(:error).with(/Failed to connect to broker/).once
841
842
  broker.__send__(:update_status, :failed)
842
843
  broker.stats.should == {"alias" => "b0", "identity" => "rs-broker-localhost-5672",
843
844
  "status" => "failed", "disconnects" => nil, "disconnect last" => nil,
@@ -851,7 +852,7 @@ describe RightScale::BrokerClient do
851
852
  callback = lambda { |b, c| called += 1; b.should == broker; c.should == connected_before }
852
853
  options = {:update_status_callback => callback}
853
854
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, options)
854
- broker.__send__(:update_status, :ready)
855
+ broker.__send__(:update_status, :connected)
855
856
  broker.last_failed.should be_false
856
857
  called.should == 1
857
858
  connected_before = true
@@ -862,7 +863,7 @@ describe RightScale::BrokerClient do
862
863
  broker.__send__(:update_status, :disconnected)
863
864
  broker.disconnects.total.should == 1
864
865
  called.should == 2
865
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker b0/).once
866
+ @log.should_receive(:error).with(/Failed to connect to broker b0/).once
866
867
  connected_before = false
867
868
  broker.__send__(:update_status, :failed)
868
869
  broker.last_failed.should be_true
@@ -874,7 +875,7 @@ describe RightScale::BrokerClient do
874
875
  context "when closing" do
875
876
 
876
877
  before(:each) do
877
- flexmock(MQ).should_receive(:new).with(@connection).and_return(@mq).by_default
878
+ flexmock(AMQP::Channel).should_receive(:new).with(@connection).and_return(@channel).by_default
878
879
  end
879
880
 
880
881
  it "should close broker connection and send status update" do
@@ -900,16 +901,16 @@ describe RightScale::BrokerClient do
900
901
  end
901
902
 
902
903
  it "should log that closing connection" do
903
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
904
- flexmock(RightScale::Log).should_receive(:info).with(/Closed connection to broker b0/).once
904
+ @log.should_receive(:info).with(/Connecting/).once
905
+ @log.should_receive(:info).with(/Closed connection to broker b0/).once
905
906
  @connection.should_receive(:close).and_yield.once
906
907
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
907
908
  broker.close
908
909
  end
909
910
 
910
911
  it "should not log if requested not to" do
911
- flexmock(RightScale::Log).should_receive(:info).with(/Connecting/).once
912
- flexmock(RightScale::Log).should_receive(:info).with(/Closed connection to broker b0/).never
912
+ @log.should_receive(:info).with(/Connecting/).once
913
+ @log.should_receive(:info).with(/Closed connection to broker b0/).never
913
914
  @connection.should_receive(:close).and_yield.once
914
915
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
915
916
  broker.close(propagate = true, normal = true, log = false)
@@ -938,7 +939,7 @@ describe RightScale::BrokerClient do
938
939
  end
939
940
 
940
941
  it "should change failed status to closed" do
941
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to connect to broker/).once
942
+ @log.should_receive(:error).with(/Failed to connect to broker/).once
942
943
  @connection.should_receive(:close).never
943
944
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)
944
945
  broker.__send__(:update_status, :failed)
@@ -948,7 +949,7 @@ describe RightScale::BrokerClient do
948
949
  end
949
950
 
950
951
  it "should log an error if closing connection fails but still set status to :closed" do
951
- flexmock(RightScale::Log).should_receive(:error).with(/Failed to close broker b0/, Exception, :trace).once
952
+ @log.should_receive(:error).with(/Failed to close broker b0/, Exception, :trace).once
952
953
  @exceptions.should_receive(:track).once
953
954
  @connection.should_receive(:close).and_raise(Exception)
954
955
  broker = RightScale::BrokerClient.new(@identity, @address, @serializer, @exceptions, @options)