Skip to content

Instantly share code, notes, and snippets.

@garethr
Created November 21, 2010 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethr/708940 to your computer and use it in GitHub Desktop.
Save garethr/708940 to your computer and use it in GitHub Desktop.
using cucumber for monitoring AMQP server
Feature: AMQP capacity
To make sure the rest of the system is in order
Our message queues must not be backed up
Scenario: Check queue status
Given I have a AMQP server on example.com
And I want to check on the fork queue
Then it should have less than 400 messages
Then it should have at least 5 consumers
Then it should have less than 50 messages per consumer
require 'rubygems'
require 'mq'
# simple function to get at the number of messages on a queue and the
# number of consumers using it and store them in variables for later use
def get_details_of_queue(queue, host)
AMQP.start(:host => host) do
jobs = MQ.queue(queue)
jobs.status do |msgs, cns|
@messages = msgs
@consumers = cns
end
AMQP.stop{ EM.stop }
end
end
# set up some defaults so we can compare numbers without
# raising exceptions
Before do
@messages = 0
@consumers = 0
end
# Step definitions for testing various conditions on the queue
Given /I have a AMQP server on (.+)$/ do |host|
@host = host
end
And /I want to check on the (\w+) queue$/ do |queue|
get_details_of_queue(queue, @host)
end
Then /it should have less than (\d+) messages per consumer$/ do |messages|
@consumers.should > 0
messages.to_i.should < @messages/@consumers
end
Then /it should have less than (\d+) messages$/ do |messages|
@messages.should < messages.to_i
end
Then /it should have at least (\d+) messages$/ do |messages|
@messages.should >= messages.to_i
end
Then /it should have more than (\d+) messages$/ do |messages|
@messages.should > messages.to_i
end
Then /It should have more than (\d+) consumers$/ do |consumers|
@consumers.should > consumers.to_i
end
Then /It should have less than (\d+) consumers$/ do |consumers|
@consumers.should < consumers.to_i
end
Then /It should have (\d+) consumers$/ do |consumers|
@consumers.should == consumers.to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment