Class: Warren::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/warren/test.rb

Overview

Class Warren::Test provides provides a dummy RabbitMQ connection pool for use during development

Defined Under Namespace

Classes: Channel

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Test

Creates a test warren with no messages. Test warrens are shared across all threads.

Parameters:

  • _args (_)

    Configuration arguments are ignored.


22
23
24
25
# File 'lib/warren/test.rb', line 22

def initialize(*_args)
  @messages = []
  @enabled = false
end

Instance Method Details

#<<(message) ⇒ Object

Disable message logging if not required


74
75
76
# File 'lib/warren/test.rb', line 74

def <<(message)
  @messages << message if @enabled
end

#clear_messagesObject


46
47
48
# File 'lib/warren/test.rb', line 46

def clear_messages
  @messages = []
end

#connectObject

Provide API compatibility with the RabbitMQ versions Do nothing in this case


31
# File 'lib/warren/test.rb', line 31

def connect; end

#disable!Object

Clean up after ourselves to avoid memory leaks


68
69
70
71
# File 'lib/warren/test.rb', line 68

def disable!
  @enabled = false
  clear_messages
end

#disconnectObject


33
# File 'lib/warren/test.rb', line 33

def disconnect; end

#enable!Object


62
63
64
65
# File 'lib/warren/test.rb', line 62

def enable!
  @enabled = true
  clear_messages
end

#last_messageObject


50
51
52
# File 'lib/warren/test.rb', line 50

def last_message
  @messages.last
end

#message_countObject


54
55
56
# File 'lib/warren/test.rb', line 54

def message_count
  @messages.length
end

#messages_matching(routing_key) ⇒ Object


58
59
60
# File 'lib/warren/test.rb', line 58

def messages_matching(routing_key)
  @messages.count { |message| message.routing_key == routing_key }
end

#with_chanel {|Channel.new(self)| ... } ⇒ void

This method returns an undefined value.

Yields an exchange which gets returned to the pool on block closure

Yields:

Yield Returns:


42
43
44
# File 'lib/warren/test.rb', line 42

def with_chanel
  yield Channel.new(self)
end