Class: Tochtli::Test::TestRabbitConnection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestRabbitConnection

Returns a new instance of TestRabbitConnection.



36
37
38
39
40
41
# File 'lib/tochtli/test/test_case.rb', line 36

def initialize
  @channel      = TestRabbitChannel.new(self)
  @exchange     = TestRabbitExchange.new
  @publications = []
  @queues       = {}
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



34
35
36
# File 'lib/tochtli/test/test_case.rb', line 34

def channel
  @channel
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



34
35
36
# File 'lib/tochtli/test/test_case.rb', line 34

def exchange
  @exchange
end

#publicationsObject (readonly)

Returns the value of attribute publications.



34
35
36
# File 'lib/tochtli/test/test_case.rb', line 34

def publications
  @publications
end

Instance Method Details

#callback(&block) ⇒ Object



60
61
62
# File 'lib/tochtli/test/test_case.rb', line 60

def callback(&block)
  @callback = block
end

#create_channel(consumer_pool_size = 1) ⇒ Object



87
88
89
# File 'lib/tochtli/test/test_case.rb', line 87

def create_channel(consumer_pool_size = 1)
  TestRabbitChannel.new(self)
end

#exchange_nameObject



43
44
45
# File 'lib/tochtli/test/test_case.rb', line 43

def exchange_name
  @exchange.name
end

#get_publicationObject



56
57
58
# File 'lib/tochtli/test/test_case.rb', line 56

def get_publication
  @publications.shift
end

#loggerObject



71
72
73
# File 'lib/tochtli/test/test_case.rb', line 71

def logger
  Logger.new(STDOUT)
end

#publish(routing_key, message, options = {}) ⇒ Object



51
52
53
54
# File 'lib/tochtli/test/test_case.rb', line 51

def publish(routing_key, message, options={})
  @publications << options.merge(routing_key: routing_key, message: message)
  run_callback
end

#queue(name = nil, routing_keys = [], options = {}) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/tochtli/test/test_case.rb', line 75

def queue(name=nil, routing_keys=[], options={})
  queue = @queues[name]
  unless queue
    @queues[name] = queue = TestQueue.new(@channel, name, options)
  end
  queue
end

#queue_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/tochtli/test/test_case.rb', line 83

def queue_exists?(name)
  @queues.has_key?(name)
end

#reply_queueObject



47
48
49
# File 'lib/tochtli/test/test_case.rb', line 47

def reply_queue
  @reply_queue ||= Tochtli::ReplyQueue.new(self)
end

#run_callbackObject



64
65
66
67
68
69
# File 'lib/tochtli/test/test_case.rb', line 64

def run_callback
  if @callback
    @callback.call
    @callback = nil
  end
end