initial import of failover code

This commit is contained in:
2011-01-26 15:29:46 +00:00
parent 2ac3a09c03
commit b3fc9826b0
17 changed files with 569 additions and 13 deletions

9
spec/spec_helper.rb Normal file
View File

@@ -0,0 +1,9 @@
# add project-relative load paths
$LOAD_PATH.unshift File.dirname(__FILE__)
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
# require stuff
require 'rubygems'
require 'amqp/failover'
require 'rspec'
require 'rspec/autorun'

View File

@@ -0,0 +1,59 @@
# encoding: utf-8
require 'spec_helper'
describe AMQP::Failover::Config do
before(:each) do
@conf = AMQP::Failover::Config.new
[:primary, :configs, :refs].each do |var|
@conf.instance_variable_set("@#{var}", nil)
end
@raw_configs = [
{:host => 'rabbit3.local'},
{:host => 'rabbit2.local'},
{:host => 'rabbit2.local', :port => 5673}
]
@configs = @raw_configs.map { |conf| @conf.default_config.merge(conf) }
end
after(:each) do
[:primary, :configs, :refs].each do |var|
@conf.instance_variable_set("@#{var}", nil)
end
end
it "should set and get configs" do
@conf.primary.should == 0
@conf.configs.should have(0).items
@conf.set(@raw_configs[0])
@conf.configs.should have(1).items
@conf.get(0).should == @configs[0]
@conf.set(@raw_configs[1])
@conf.configs.should have(2).items
@conf.get(1).should == @configs[1]
@conf.set(@raw_configs[1], :the_one)
@conf.configs.should have(2).items
@conf.get(1).should == @configs[1]
@conf.get(:the_one).should == @configs[1]
@conf.load_array(@raw_configs)
@conf.configs.should have(3).items
@conf.get_primary.should == @configs[0]
@conf.primary = 1
@conf.get_primary.should == @configs[1]
end
it "should #find_next" do
@conf.load(@raw_configs)
@conf.configs.should have(3).items
@conf.find_next(@configs[0]).should == @configs[1]
@conf.find_next(@configs[1]).should == @configs[2]
@conf.find_next(@configs[2]).should == @configs[0]
end
end