right_amqp 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ documentation.
20
20
  Also use the built-in issues tracker (https://github.com/rightscale/right_amqp/issues)
21
21
  to report issues.
22
22
 
23
- Maintained by the RightScale Teal Team
23
+ Maintained by the RightScale Cornsilk Team
24
24
 
25
25
  == Interface
26
26
 
@@ -252,14 +252,14 @@ module RightAMQP
252
252
  if exchange
253
253
  x = @channel.__send__(exchange[:type], exchange[:name], exchange_options)
254
254
  binding = q.bind(x, options[:key] ? {:key => options[:key]} : {})
255
- if exchange2 = options[:exchange2]
255
+ if (exchange2 = options[:exchange2])
256
256
  q.bind(@channel.__send__(exchange2[:type], exchange2[:name], exchange2[:options] || {}))
257
257
  end
258
258
  q = binding
259
259
  end
260
260
  q.subscribe(options[:ack] ? {:ack => true} : {}) do |header, message|
261
261
  begin
262
- if pool = (options[:fiber_pool] || @options[:fiber_pool])
262
+ if (pool = (options[:fiber_pool] || @options[:fiber_pool]))
263
263
  pool.spawn { receive(queue[:name], header, message, options, &block) }
264
264
  else
265
265
  receive(queue[:name], header, message, options, &block)
@@ -269,7 +269,7 @@ module RightAMQP
269
269
  logger.exception("Failed setting up to receive message from queue #{queue.inspect} " +
270
270
  "on broker #{@alias}", e, :trace)
271
271
  @exception_stats.track("receive", e)
272
- @non_delivery_stats.update("receive failure")
272
+ update_non_delivery_stats("receive failure", e)
273
273
  end
274
274
  end
275
275
  rescue StandardError => e
@@ -412,11 +412,11 @@ module RightAMQP
412
412
  rescue StandardError => e
413
413
  logger.exception("Failed publishing to exchange #{exchange.inspect} on broker #{@alias}", e, :trace)
414
414
  @exception_stats.track("publish", e)
415
- @non_delivery_stats.update("publish failure")
415
+ update_non_delivery_stats("publish failure", e)
416
416
  false
417
417
  end
418
418
  end
419
-
419
+ 3
420
420
  # Delete queue
421
421
  #
422
422
  # === Parameters
@@ -649,7 +649,7 @@ module RightAMQP
649
649
  # This happens as part of connecting an instance agent to a broker prior to version 13
650
650
  header.ack if options[:ack]
651
651
  logger.debug("RECV #{@alias} nil message ignored")
652
- elsif packet = unserialize(queue, message, options)
652
+ elsif (packet = unserialize(queue, message, options))
653
653
  execute_callback(block, @identity, packet, header)
654
654
  elsif options[:ack]
655
655
  # Need to ack empty packet since no callback is being made
@@ -660,7 +660,7 @@ module RightAMQP
660
660
  header.ack if options[:ack]
661
661
  logger.exception("Failed receiving message from queue #{queue.inspect} on broker #{@alias}", e, :trace)
662
662
  @exception_stats.track("receive", e)
663
- @non_delivery_stats.update("receive failure")
663
+ update_non_delivery_stats("receive failure", e)
664
664
  end
665
665
  end
666
666
 
@@ -697,11 +697,15 @@ module RightAMQP
697
697
  end
698
698
  rescue StandardError => e
699
699
  # TODO Taking advantage of Serializer knowledge here even though out of scope
700
- trace = e.class.name =~ /SerializationError/ ? :caller : :trace
700
+ trace, track = case e.class.name.sub(/^.*::/, "")
701
+ when "SerializationError" then [:caller, e.to_s !~ /MissingCertificate|MissingPrivateKey|InvalidSignature/]
702
+ when "ConnectivityFailure" then [:caller, false]
703
+ else [:trace, true]
704
+ end
701
705
  logger.exception("Failed unserializing message from queue #{queue.inspect} on broker #{@alias}", e, trace)
702
- @exception_stats.track("receive", e) if e.to_s !~ /MissingCertificate/
706
+ @exception_stats.track("receive", e) if track
703
707
  @options[:exception_on_receive_callback].call(message, e) if @options[:exception_on_receive_callback]
704
- @non_delivery_stats.update("receive failure")
708
+ update_non_delivery_stats("receive failure", e)
705
709
  nil
706
710
  end
707
711
  end
@@ -732,6 +736,19 @@ module RightAMQP
732
736
  true
733
737
  end
734
738
 
739
+ # Update non-delivery stats
740
+ #
741
+ # @param [String] type of non-delivery
742
+ # @param [Exception] exception associated with non-delivery
743
+ #
744
+ # @return [TrueClass] always true
745
+ def update_non_delivery_stats(type, exception)
746
+ update = type
747
+ update << " - #{exception.class.name.sub(/^.*::/, "")}"
748
+ @non_delivery_stats.update(update)
749
+ true
750
+ end
751
+
735
752
  # Handle message returned by broker because it could not deliver it
736
753
  #
737
754
  # === Parameters
data/right_amqp.gemspec CHANGED
@@ -24,8 +24,8 @@ require 'rubygems'
24
24
 
25
25
  Gem::Specification.new do |spec|
26
26
  spec.name = 'right_amqp'
27
- spec.version = '0.8.4'
28
- spec.date = '2014-07-03'
27
+ spec.version = '0.8.5'
28
+ spec.date = '2014-10-02'
29
29
  spec.authors = ['Lee Kirchhoff']
30
30
  spec.email = 'lee@rightscale.com'
31
31
  spec.homepage = 'https://github.com/rightscale/right_amqp'
@@ -26,6 +26,13 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'r
26
26
  class RequestMock; end
27
27
  class ResultMock; end
28
28
 
29
+ module RightScale
30
+ class SerializationError < StandardError; end
31
+ class Exceptions
32
+ class ConnectivityFailure < StandardError; end
33
+ end
34
+ end
35
+
29
36
  describe RightAMQP::BrokerClient do
30
37
 
31
38
  include FlexMock::ArgumentTypes
@@ -34,7 +41,7 @@ describe RightAMQP::BrokerClient do
34
41
  before(:each) do
35
42
  setup_logger
36
43
  @message = "message"
37
- @packet = flexmock("packet", :class => RequestMock, :to_s => true, :version => [12, 12]).by_default
44
+ @packet = flexmock("packet", :class => RequestMock, :to_s => "packet", :version => [12, 12]).by_default
38
45
  @serializer = flexmock("serializer")
39
46
  @serializer.should_receive(:dump).and_return(@message).by_default
40
47
  @serializer.should_receive(:load).with(@message).and_return(@packet).by_default
@@ -262,25 +269,27 @@ describe RightAMQP::BrokerClient do
262
269
  it "should receive message and log exception if subscribe block fails and then ack if option set" do
263
270
  @logger.should_receive(:info).with(/Connecting/).once
264
271
  @logger.should_receive(:info).with(/Subscribing/).once
272
+ @logger.should_receive(:info).with(/RECV/).once
265
273
  @logger.should_receive(:error).with(/Failed receiving message/).once
266
274
  @exceptions.should_receive(:track).once
267
- @non_deliveries.should_receive(:update).once
275
+ @non_deliveries.should_receive(:update).with("receive failure - RuntimeError").once
268
276
  @serializer.should_receive(:load).with(@message).and_return(@packet).once
269
277
  @header.should_receive(:ack).once
270
278
  @bind.should_receive(:subscribe).and_yield(@header, @message).once
271
279
  broker = RightAMQP::BrokerClient.new(@identity, @address, @serializer, @exceptions, @non_deliveries, @options)
272
280
  broker.__send__(:update_status, :ready)
273
281
  result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"},
274
- :ack => true, RequestMock => nil) {|b, p| raise Exception}
275
- result.should be_false
282
+ :ack => true, RequestMock => nil) {|b, p| raise RuntimeError}
283
+ result.should be_true
276
284
  end
277
285
 
278
286
  it "should log an error if a subscribe fails" do
279
287
  @logger.should_receive(:info).with(/Connecting/).once
288
+ @logger.should_receive(:info).with(/Subscribing/).once
280
289
  @logger.should_receive(:info).with(/RECV/).never
281
290
  @logger.should_receive(:error).with(/Failed subscribing/).once
282
291
  @exceptions.should_receive(:track).once
283
- @bind.should_receive(:subscribe).and_raise(Exception)
292
+ @bind.should_receive(:subscribe).and_raise(StandardError)
284
293
  broker = RightAMQP::BrokerClient.new(@identity, @address, @serializer, @exceptions, @non_deliveries, @options)
285
294
  broker.__send__(:update_status, :ready)
286
295
  result = broker.subscribe({:name => "queue"}, {:type => :direct, :name => "exchange"}) {|_, _|}
@@ -441,7 +450,7 @@ describe RightAMQP::BrokerClient do
441
450
  broker.__send__(:unserialize, "queue", @message, RequestMock => nil, :no_log => true)
442
451
  end
443
452
 
444
- it "should log an error if exception prevents normal logging and should then return nil" do
453
+ it "should log an error if exception prevents unserialization and should then return nil" do
445
454
  @logger.should_receive(:error).with(/Failed unserializing message from queue/).once
446
455
  @serializer.should_receive(:load).with(@message).and_raise(StandardError).once
447
456
  @exceptions.should_receive(:track).once
@@ -450,6 +459,39 @@ describe RightAMQP::BrokerClient do
450
459
  broker.__send__(:unserialize, "queue", @message).should be_nil
451
460
  end
452
461
 
462
+ it "should use lesser trace level for SerializationError exception" do
463
+ @serializer.should_receive(:load).with(@message).and_raise(RightScale::SerializationError, "failed").once
464
+ @exceptions.should_receive(:track).once
465
+ @non_deliveries.should_receive(:update).once
466
+ broker = RightAMQP::BrokerClient.new(@identity, @address, @serializer, @exceptions, @non_deliveries, @options)
467
+ logger = flexmock(broker.logger)
468
+ logger.should_receive(:exception).with(/Failed unserializing message from queue/, RightScale::SerializationError, :caller).once
469
+ broker.__send__(:unserialize, "queue", @message).should be_nil
470
+ end
471
+
472
+ it "should use lesser trace level for ConnectivityFailure exception and not track" do
473
+ @serializer.should_receive(:load).with(@message).and_raise(RightScale::Exceptions::ConnectivityFailure, "failed").once
474
+ @exceptions.should_receive(:track).never
475
+ @non_deliveries.should_receive(:update).once
476
+ broker = RightAMQP::BrokerClient.new(@identity, @address, @serializer, @exceptions, @non_deliveries, @options)
477
+ logger = flexmock(broker.logger)
478
+ logger.should_receive(:exception).with(/Failed unserializing message from queue/, RightScale::Exceptions::ConnectivityFailure, :caller).once
479
+ broker.__send__(:unserialize, "queue", @message).should be_nil
480
+ end
481
+
482
+ ["MissingCertificate", "MissingPrivateKey", "InvalidSignature"].each do |name|
483
+ it "should not track SerializationError containing #{name} exceptions" do
484
+ e = RightScale::SerializationError.new(name)
485
+ @serializer.should_receive(:load).with(@message).and_raise(e).once
486
+ @exceptions.should_receive(:track).never
487
+ @non_deliveries.should_receive(:update).once
488
+ broker = RightAMQP::BrokerClient.new(@identity, @address, @serializer, @exceptions, @non_deliveries, @options)
489
+ logger = flexmock(broker.logger)
490
+ logger.should_receive(:exception).with(/Failed unserializing message from queue/, e, :caller).once
491
+ broker.__send__(:unserialize, "queue", @message).should be_nil
492
+ end
493
+ end
494
+
453
495
  it "should make callback when there is a receive failure" do
454
496
  @logger.should_receive(:error).with(/Failed unserializing message from queue/).once
455
497
  @serializer.should_receive(:load).with(@message).and_raise(StandardError).once
@@ -834,7 +876,7 @@ describe RightAMQP::BrokerClient do
834
876
  @logger.should_receive(:debug).with("RETURN b0 for exchange because NO_CONSUMERS")
835
877
  @logger.should_receive(:error).with(/Failed return/).once
836
878
  @exceptions.should_receive(:track).once
837
- @options = {:return_message_callback => lambda { |i, t, r, m| raise Exception } }
879
+ @options = {:return_message_callback => lambda { |i, t, r, m| raise StandardError } }
838
880
  broker = RightAMQP::BrokerClient.new(@identity, @address, @serializer, @exceptions, @non_deliveries, @options)
839
881
  broker.__send__(:handle_return, @header, @message).should be_true
840
882
  end
@@ -881,7 +923,7 @@ describe RightAMQP::BrokerClient do
881
923
  broker.delete("queue1").should be_false
882
924
  end
883
925
 
884
- end # when deleteing
926
+ end # when deleting
885
927
 
886
928
  context "when monitoring" do
887
929
 
data/spec/spec_helper.rb CHANGED
@@ -44,11 +44,13 @@ module RightAMQP
44
44
  def setup_logger
45
45
  @logger = flexmock("logger")
46
46
  @logger.should_receive(:level).and_return(:info).by_default
47
- @logger.should_receive(:exception).by_default.and_return { |m| raise m }
48
47
  @logger.should_receive(:error).by_default.and_return { |m| raise m }
49
48
  @logger.should_receive(:warn).by_default.and_return { |m| raise m }
50
49
  @logger.should_receive(:info).by_default
51
50
  @logger.should_receive(:debug).by_default
51
+ # Note that the following puts the mock logger inside the default Decorator
52
+ # so the only way to mock the :exception interface is to flexmock the
53
+ # logger if the constructed class that uses RightSupport::Log::Mixin
52
54
  RightSupport::Log::Mixin.default_logger = @logger
53
55
  end
54
56
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-03 00:00:00.000000000Z
12
+ date: 2014-10-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: right_support
16
- requirement: &2160381580 !ruby/object:Gem::Requirement
16
+ requirement: &2160810180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '3.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *2160381580
27
+ version_requirements: *2160810180
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: eventmachine
30
- requirement: &2160380600 !ruby/object:Gem::Requirement
30
+ requirement: &2160809020 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,7 +38,7 @@ dependencies:
38
38
  version: '2.0'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *2160380600
41
+ version_requirements: *2160809020
42
42
  description: ! 'RightAMQP provides a high availability client for interfacing with
43
43
  the
44
44
 
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: -1268186546585631642
123
+ hash: 1112736972796387367
124
124
  requirements: []
125
125
  rubyforge_project:
126
126
  rubygems_version: 1.8.10