Permalink
Browse files

basics for starting localized rabbitmq; still need to autodetect ERLA…

…NG_HOME
  • Loading branch information...
rick committed Nov 26, 2008
1 parent 422bbf4 commit 3a7d6b730fbdbc65360cbad6425cb520726aecbb
Showing with 84 additions and 7 deletions.
  1. +72 −6 spec/rake/rabbitmq.rake_spec.rb
  2. +12 −1 tasks/rabbitmq.rake
@@ -16,19 +16,76 @@
it 'should work without arguments' do
lambda { RabbitMQ.running? }.should_not raise_error(ArgumentError)
end
it 'should not allow arguments' do
lambda { RabbitMQ.running?(:foo) }.should raise_error(ArgumentError)
end
it 'should attempt to connect to rabbitmq'
it 'should return true if rabbitmq is running'
it 'should return false if rabbitmq is not running'
end
describe 'settup up a localized rabbitmq environment' do
before :each do
stub(RabbitMQ).find_erlang_home { '/path/to/erlang/home' }
@server = File.expand_path(File.dirname(__FILE__) + '/../../run/')
@old_erlang_home, ENV['ERLANG_HOME'] = ENV['ERLANG_HOME'], nil
@old_rabbitmq_base, ENV['RABBITMQ_BASE'] = ENV['RABBITMQ_BASE'], nil
@old_mnesia_base, ENV['MNESIA_BASE'] = ENV['MNESIA_BASE'], nil
@old_log_base, ENV['LOG_BASE'] = ENV['LOG_BASE'], nil
end
after :each do
ENV['ERLANG_HOME'] = @old_erlang_home
ENV['RABBITMQ_BASE'] = @old_rabbitmq_base
ENV['MNESIA_BASE'] = @old_mnesia_base
ENV['LOG_BASE'] = @old_log_base
end
it 'should work without arguments' do
lambda { RabbitMQ.setup_environment }.should_not raise_error(ArgumentError)
end
it 'should not allow arguments' do
lambda { RabbitMQ.setup_environment(:foo) }.should raise_error(ArgumentError)
end
it 'should lookup the erlang home path' do
mock(RabbitMQ).find_erlang_home
RabbitMQ.setup_environment
end
it 'should set the ERLANG_HOME path' do
RabbitMQ.setup_environment
ENV['ERLANG_HOME'].should == '/path/to/erlang/home'
end
it 'should set the RABBITMQ_BASE path' do
RabbitMQ.setup_environment
ENV['RABBITMQ_BASE'].should == "#{@server}/rabbitmq/"
end
it 'should set the MNESIA_BASE path' do
RabbitMQ.setup_environment
ENV['MNESIA_BASE'].should == "#{@server}/mnesia/"
end
it 'should set the LOG_BASE path' do
RabbitMQ.setup_environment
ENV['LOG_BASE'].should == "#{@server}/../log/"
end
end
describe 'starting the rabbitmq server' do
before :each do
stub(RabbitMQ).system(anything)
stub(RabbitMQ).setup_environment
stub(Dir).chdir(anything)
end
it 'should work without arguments' do
lambda { RabbitMQ.start }.should_not raise_error(ArgumentError)
end
@@ -37,13 +94,22 @@
lambda { RabbitMQ.start(:foo) }.should raise_error(ArgumentError)
end
it 'should localize the ... setting'
it 'should configure the environment for localized running of rabbitmq' do
mock(RabbitMQ).setup_environment
RabbitMQ.start
end
it 'should run the server from the rabbitmq sbin directory' do
mock(Dir).chdir(File.expand_path(File.dirname(__FILE__) + '/../../run/rabbitmq/sbin/'))
RabbitMQ.start
end
it 'should start the rabbitmq server' do
mock(RabbitMQ).system("./rabbitmq-server")
RabbitMQ.start
end
end
describe 'when running rabbitmq:start' do
def run_task
@rake["rabbitmq:start"].invoke
View
@@ -5,7 +5,18 @@ class RabbitMQ
def running?
end
def setup_environment
server = File.expand_path(File.dirname(__FILE__) + '/../run/')
ENV['ERLANG_HOME'] = find_erlang_home
ENV['RABBITMQ_BASE'] = "#{server}/rabbitmq/"
ENV['MNESIA_BASE'] = "#{server}/mnesia/"
ENV['LOG_BASE'] = "#{server}/../log/"
end
def start
setup_environment
Dir.chdir(File.expand_path(File.dirname(__FILE__) + '/../run/rabbitmq/sbin'))
system("./rabbitmq-server")
end
end
end
@@ -14,7 +25,7 @@ namespace :rabbitmq do
desc 'start the rabbitmq server'
task :start do
raise "RabbitMQ server is not installed -- please run 'rake install_dependencies' first." unless
RakeInstall.is_installed?('rabbitmq')
RakeInstall.is_installed?('run/rabbitmq')
RabbitMQ.start unless RabbitMQ.running?
end
end

0 comments on commit 3a7d6b7

Please sign in to comment.