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.


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

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

Instance Method Details

#<<(message) ⇒ Object

Disable message logging if not required


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

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

#clear_messagesObject


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

def clear_messages
  @messages = []
end

#connectObject

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


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

def connect; end

#disable!Object

Clean up after ourselves to avoid memory leaks


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

def disable!
  @enabled = false
  clear_messages
end

#disconnectObject


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

def disconnect; end

#enable!Object


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

def enable!
  @enabled = true
  clear_messages
end

#last_messageObject


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

def last_message
  @messages.last
end

#message_countObject


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

def message_count
  @messages.length
end

#messages_matching(routing_key) ⇒ Object


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

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:


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

def with_chanel
  yield Channel.new(self)
end