Permalink
Browse files

check in test cases

  • Loading branch information...
1 parent 5f69d41 commit 25f04263b0b07f6676a06ef2875d8f68fb05e90b @gnufied committed Jun 20, 2008
View
@@ -18,13 +18,13 @@ require "optparse"
require "bdrb_config"
BackgrounDRb::Config.parse_cmd_options ARGV
-CONFIG_FILE = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")
+BDRB_CONFIG = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")
require RAILS_HOME + "/config/environment"
require "backgroundrb_server"
-pid_file = "#{RAILS_HOME}/tmp/pids/backgroundrb_#{CONFIG_FILE[:backgroundrb][:port]}.pid"
-SERVER_LOGGER = "#{RAILS_HOME}/log/backgroundrb_debug_#{CONFIG_FILE[:backgroundrb][:port]}.log"
+pid_file = "#{RAILS_HOME}/tmp/pids/backgroundrb_#{BDRB_CONFIG[:backgroundrb][:port]}.pid"
+SERVER_LOGGER = "#{RAILS_HOME}/log/backgroundrb_debug_#{BDRB_CONFIG[:backgroundrb][:port]}.log"
case ARGV[0]
when 'start'
@@ -35,7 +35,7 @@ when 'start'
op = File.open(pid_file, "w")
op.write(Process.pid().to_s)
op.close
- if CONFIG_FILE[:backgroundrb][:log].nil? or CONFIG_FILE[:backgroundrb][:log] != 'foreground'
+ if BDRB_CONFIG[:backgroundrb][:log].nil? or BDRB_CONFIG[:backgroundrb][:log] != 'foreground'
log_file = File.open(SERVER_LOGGER,"w+")
[STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)}
end
@@ -13,7 +13,7 @@
require "optparse"
require "bdrb_config"
-CONFIG_FILE = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")
+BDRB_CONFIG = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")
require "backgroundrb_server"
require RAILS_HOME + "/config/environment"
@@ -20,7 +20,7 @@ def memcache_instance
:urlencode => false
}
t_cache = MemCache.new(memcache_options)
- t_cache.servers = CONFIG_FILE[:memcache].split(',')
+ t_cache.servers = BDRB_CONFIG[:memcache].split(',')
t_cache
end
View
@@ -2,7 +2,7 @@ class LogWorker < Packet::Worker
set_worker_name :log_worker
attr_accessor :log_file
def worker_init
- @log_file = Logger.new("#{RAILS_HOME}/log/backgroundrb_#{CONFIG_FILE[:backgroundrb][:port]}.log")
+ @log_file = Logger.new("#{RAILS_HOME}/log/backgroundrb_#{BDRB_CONFIG[:backgroundrb][:port]}.log")
end
def receive_data p_data
@@ -9,7 +9,7 @@ def initialize(log_mode,log_flag = true)
if @log_mode == :foreground
@logger = ::Logger.new(STDOUT)
else
- @logger = ::Logger.new("#{RAILS_HOME}/log/backgroundrb_debug_#{CONFIG_FILE[:backgroundrb][:port]}.log")
+ @logger = ::Logger.new("#{RAILS_HOME}/log/backgroundrb_debug_#{BDRB_CONFIG[:backgroundrb][:port]}.log")
end
end
@@ -152,18 +152,18 @@ class MasterProxy
def initialize
raise "Running old Ruby version, upgrade to Ruby >= 1.8.5" unless check_for_ruby_version
- log_flag = CONFIG_FILE[:backgroundrb][:debug_log].nil? ? true : CONFIG_FILE[:backgroundrb][:debug_log]
- debug_logger = DebugMaster.new(CONFIG_FILE[:backgroundrb][:log],log_flag)
+ log_flag = BDRB_CONFIG[:backgroundrb][:debug_log].nil? ? true : BDRB_CONFIG[:backgroundrb][:debug_log]
+ debug_logger = DebugMaster.new(BDRB_CONFIG[:backgroundrb][:log],log_flag)
load_rails_env
find_reloadable_worker
Packet::Reactor.run do |t_reactor|
@reactor = t_reactor
- enable_memcache_result_hash(t_reactor) if CONFIG_FILE[:backgroundrb][:result_storage] && CONFIG_FILE[:backgroundrb][:result_storage][:memcache]
+ enable_memcache_result_hash(t_reactor) if BDRB_CONFIG[:backgroundrb][:result_storage] && BDRB_CONFIG[:backgroundrb][:result_storage][:memcache]
t_reactor.start_worker(:worker => :log_worker) if log_flag
- t_reactor.start_server(CONFIG_FILE[:backgroundrb][:ip],CONFIG_FILE[:backgroundrb][:port],MasterWorker) { |conn| conn.debug_logger = debug_logger }
+ t_reactor.start_server(BDRB_CONFIG[:backgroundrb][:ip],BDRB_CONFIG[:backgroundrb][:port],MasterWorker) { |conn| conn.debug_logger = debug_logger }
t_reactor.next_turn { reload_workers }
end
end
@@ -194,7 +194,7 @@ def find_reloadable_worker
def load_reloadable_schedule(t_worker)
worker_method_triggers = { }
- worker_schedule = CONFIG_FILE[:schedules][t_worker.worker_name.to_sym]
+ worker_schedule = BDRB_CONFIG[:schedules][t_worker.worker_name.to_sym]
worker_schedule && worker_schedule.each do |key,value|
case value[:trigger_args]
@@ -271,7 +271,7 @@ def enable_memcache_result_hash(t_reactor)
:urlencode => false
}
cache = MemCache.new(memcache_options)
- cache.servers = CONFIG_FILE[:backgroundrb][:result_storage][:memcache].split(',')
+ cache.servers = BDRB_CONFIG[:backgroundrb][:result_storage][:memcache].split(',')
t_reactor.set_result_hash(cache)
end
@@ -115,7 +115,7 @@ def worker_init
Thread.current[:job_key] = nil
@logger = PacketLogger.new(self,log_flag)
@thread_pool = ThreadPool.new(pool_size || 20,@logger)
- @cache = ResultStorage.new(worker_name,worker_options[:worker_key],CONFIG_FILE[:backgroundrb][:result_storage])
+ @cache = ResultStorage.new(worker_name,worker_options[:worker_key],BDRB_CONFIG[:backgroundrb][:result_storage])
if(worker_options && worker_options[:schedule] && no_auto_load)
load_schedule_from_args
View
@@ -14,9 +14,10 @@
["server","server/lib","lib","lib/backgroundrb"].each { |x| $LOAD_PATH.unshift(PACKET_APP + "/#{x}")}
$LOAD_PATH.unshift(WORKER_ROOT)
-# require "#{PACKET_APP}/server/master_worker"
require "packet"
-require "backgroundrb_server"
require "bdrb_config"
-# there should be a way to stub out reactor loop of bdrb
+
+
+require "backgroundrb_server"
+
@@ -1,41 +1,41 @@
-require File.join(File.dirname(__FILE__) + "/bdrb_test_helper")
+require File.join(File.dirname(__FILE__) + "/..","bdrb_test_helper")
-context "Master proxy for reloadable workers" do
- BackgrounDRb::Config::RAILS_ENV = "production"
- CONFIG_FILE = {:schedules=>
+context "Master proxy for reloadable workers" do
+ ENV["RAILS_ENV"] = "production"
+ BDRB_CONFIG = {:schedules=>
{
:foo_worker => { :barbar => {:trigger_args=>"*/10 * * * * *", :data =>"Hello World" }},
:bar_worker => { :do_job => {:trigger_args=>"*/10 * * * * *", :data =>"Hello World" }}
- },
- :backgroundrb=> {:log=>"foreground", :lazy_load=>true, :debug_log=>false, :environment=>"production", :port=>11006, :ip=>"localhost"}
+ },
+ :backgroundrb=> {:log => "foreground", :debug_log => false, :environment => "production", :port => 11006, :ip => "localhost"}
}
-
- setup do
+
+ setup do
Packet::Reactor.stubs(:run)
@master_proxy = BackgrounDRb::MasterProxy.new
end
-
+
specify "should load schedule of workers which are reloadable" do
@master_proxy.find_reloadable_worker
- @master_proxy.reloadable_workers.should.not.be []
+ @master_proxy.reloadable_workers.should.not == []
@master_proxy.reloadable_workers.should == [BarWorker]
@master_proxy.worker_triggers.should.not.be {}
assert @master_proxy.worker_triggers.keys.include?(:bar_worker)
assert @master_proxy.worker_triggers[:bar_worker].keys.include?(:do_job)
@master_proxy.worker_triggers[:bar_worker][:do_job].should.not.be { }
end
-
+
specify "load schedule should load schedule of worker specified" do
- require "bar_worker"
+ #require "bar_worker"
@master_proxy.load_reloadable_schedule(BarWorker).should.not.be { }
end
-
+
specify "should invoke worker methods which are ready to run" do
-
+
end
-
+
specify "should not run worker methods which are not ready to run" do
-
+
end
end
@@ -0,0 +1,14 @@
+require File.join(File.dirname(__FILE__) + "/..","bdrb_test_helper")
+
+context "Result storage" do
+ setup do
+ @cache = BackgrounDRb::ResultStorage.new(:some_worker,:crap)
+ end
+
+ specify "should store result" do
+ @cache[:foo] = "Wow"
+ @cache[:foo].should == "Wow"
+ @cache.delete(:foo)
+ @cache[:foo].should == nil
+ end
+end
@@ -0,0 +1,7 @@
+class BarWorker < BackgrounDRb::MetaWorker
+ set_worker_name :bar_worker
+ reload_on_schedule true
+ def create
+
+ end
+end

0 comments on commit 25f0426

Please sign in to comment.