specs for on_exceptions param
MODIFY
lib/beetle/message.rb
lib/beetle/message.rb
@@ -82,7 +82,6 @@ module Beetle
# extracts various values from the AMQP header properties
def decode #:nodoc:
- # p header.attributes
amqp_headers = header.attributes
@uuid = amqp_headers[:message_id]
@timestamp = amqp_headers[:timestamp]
@@ -222,7 +221,7 @@ module Beetle
end
def exception_accepted?
- on_exceptions.nil? || on_exceptions.any?{ |klass| @exception.is_a? klass}
+ @exception.nil? || on_exceptions.nil? || on_exceptions.any?{ |klass| @exception.is_a? klass}
end
# have we already seen this message? if not, set the status to "incomplete" and store

MODIFY
test/beetle/message_test.rb
test/beetle/message_test.rb
@@ -345,7 +345,7 @@ module Beetle
assert_equal "52", @store.get(message.msg_id, :delay)
end
- test "a message should delete the mutex before resetting the timer if attempts and exception limits havn't been reached" do
+ test "a message should delete the mutex before resetting the timer if attempts and exception limits haven't been reached" do
Message.stubs(:now).returns(9)
header = header_with_params({})
message = Message.new("somequeue", header, 'foo', :delay => 42, :timeout => 10.seconds, :exceptions => 1, :store => @store)
@@ -377,6 +377,23 @@ module Beetle
assert_equal RC::ExceptionsLimitReached, message.__send__(:process_internal, proc)
end
+ test "a message should not be acked if the handler crashes and the exception has been registered" do
+ header = header_with_params({})
+ RegisteredException = Class.new(StandardError)
+ message = Message.new("somequeue", header, 'foo', :timeout => 10.seconds, :exceptions => 2,
+ :on_exceptions => [RegisteredException], :store => @store)
+ assert !message.attempts_limit_reached?
+ assert !message.exceptions_limit_reached?
+ assert !message.timed_out?
+ assert !message.simple?
+ assert message.exception_accepted? # @exception yet nil, hence 'accepted'
+
+ proc = lambda {|_| raise RegisteredException, "crash"}
+ message.expects(:completed!).never
+ header.expects(:ack).never
+ assert_equal RC::HandlerCrash, message.__send__(:process_internal, proc)
+ end
+
test "a message should be acked if the handler crashes and the exception has not been registered" do
header = header_with_params({})
RegisteredException = Class.new(StandardError)
@@ -389,8 +406,7 @@ module Beetle
assert !message.simple?
assert message.exception_accepted? # @exception yet nil, hence 'accepted'
- proc = lambda {|*args| raise OtherException, "crash"}
- s = sequence("s")
+ proc = lambda {|_| raise OtherException, "crash"}
message.expects(:completed!).once
header.expects(:ack)
assert_equal RC::ExceptionNotAccepted, message.__send__(:process_internal, proc)

specs for on_exceptions param