added log specs and a few cleanups

This commit is contained in:
Colin Surprenant 2012-02-14 16:47:00 -05:00
parent e4c0fa0516
commit 01976ea771
5 changed files with 171 additions and 17 deletions

View File

@ -15,10 +15,10 @@ module RedStorm
configure do |env|
debug true
# set the JRuby version property for this topology. this will only affect remote cluster execution
# for local execution use the --1.8|--1.9 switch when launching
set("topology.worker.childopts", "-Djruby.compat.version=RUBY1_9")
set "topology.worker.childopts", "-Djruby.compat.version=RUBY1_9"
end
on_submit do |env|

View File

@ -72,13 +72,12 @@ module RedStorm
declarer.declare(Fields.new(self.class.fields))
end
# default optional dsl methods/callbacks
private
# default noop optional dsl callbacks
def on_init; end
def on_close; end
private
def self.fields
@fields ||= []
end

View File

@ -92,15 +92,14 @@ module RedStorm
instance_exec(msg_id, &self.class.on_fail_block)
end
# default optional dsl methods/callbacks
private
# default optional noop dsl methods/callbacks
def on_init; end
def on_close; end
def on_ack(msg_id); end
def on_fail(msg_id); end
private
def self.fields
@fields ||= []
end

View File

@ -11,18 +11,27 @@ describe RedStorm::SimpleBolt do
describe "interface" do
it "should implement bolt proxy" do
spout = RedStorm::SimpleBolt.new
spout.should respond_to :execute
spout.should respond_to :cleanup
spout.should respond_to :prepare
spout.should respond_to :declare_output_fields
bolt = RedStorm::SimpleBolt.new
bolt.should respond_to :execute
bolt.should respond_to :cleanup
bolt.should respond_to :prepare
bolt.should respond_to :declare_output_fields
end
it "should implement dsl statement" do
it "should implement dsl class statements" do
RedStorm::SimpleBolt.should respond_to :output_fields
RedStorm::SimpleBolt.should respond_to :on_init
RedStorm::SimpleBolt.should respond_to :on_close
RedStorm::SimpleBolt.should respond_to :on_receive
RedStorm::SimpleBolt.should respond_to :log
end
it "should implement dsl instance statements" do
bolt = RedStorm::SimpleBolt.new
bolt.should respond_to :unanchored_emit
bolt.should respond_to :anchored_emit
bolt.should respond_to :ack
bolt.should respond_to :log
end
end
@ -188,7 +197,6 @@ describe RedStorm::SimpleBolt do
Bolt1.send(:ack?).should be_true
Bolt1.send(:anchor?).should be_true
end
end
describe "with default method" do
@ -240,7 +248,6 @@ describe RedStorm::SimpleBolt do
Bolt1.send(:ack?).should be_true
Bolt1.send(:anchor?).should be_true
end
end
end
@ -289,6 +296,77 @@ describe RedStorm::SimpleBolt do
bolt.cleanup
end
end
# log specs are mostly the same ats in the spout specs. if these are modified, sync with spout
describe "log statement" do
class Logger; end # mock log4j Logger class which does not exists in the specs context
describe "in class" do
it "should proxy to storm log4j logger" do
logger = mock(Logger)
Logger.should_receive("getLogger").with("Bolt1").and_return(logger)
logger.should_receive(:info).with("test")
class Bolt1 < RedStorm::SimpleBolt
log.info("test")
end
end
it "should use own class name as logger id" do
logger1 = mock(Logger)
logger2 = mock(Logger)
Logger.should_receive("getLogger").with("Bolt1").and_return(logger1)
Logger.should_receive("getLogger").with("Bolt2").and_return(logger2)
logger1.should_receive(:info).with("test1")
logger2.should_receive(:info).with("test2")
class Bolt1 < RedStorm::SimpleBolt
log.info("test1")
end
class Bolt2 < RedStorm::SimpleBolt
log.info("test2")
end
end
end
describe "in instance" do
it "should proxy to storm log4j logger" do
logger = mock(Logger)
Logger.should_receive("getLogger").with("Bolt1").and_return(logger)
class Bolt1 < RedStorm::SimpleBolt
on_init {log.info("test")}
end
logger.should_receive(:info).with("test")
bolt = Bolt1.new
bolt.prepare(nil, nil, nil)
end
it "should use own class name as logger id" do
logger1 = mock(Logger)
logger2 = mock(Logger)
Logger.should_receive("getLogger").with("Bolt1").and_return(logger1)
Logger.should_receive("getLogger").with("Bolt2").and_return(logger2)
class Bolt1 < RedStorm::SimpleBolt
on_init {log.info("test1")}
end
class Bolt2 < RedStorm::SimpleBolt
on_init {log.info("test2")}
end
logger1.should_receive(:info).with("test1")
bolt1 = Bolt1.new
bolt1.prepare(nil, nil, nil)
logger2.should_receive(:info).with("test2")
bolt2 = Bolt2.new
bolt2.prepare(nil, nil, nil)
end
end
end
end
describe "bolt" do

View File

@ -21,7 +21,7 @@ describe RedStorm::SimpleSpout do
spout.should respond_to :fail
end
it "should implement dsl statement" do
it "should implement dsl class statement" do
RedStorm::SimpleSpout.should respond_to :set
RedStorm::SimpleSpout.should respond_to :output_fields
RedStorm::SimpleSpout.should respond_to :on_init
@ -29,7 +29,15 @@ describe RedStorm::SimpleSpout do
RedStorm::SimpleSpout.should respond_to :on_send
RedStorm::SimpleSpout.should respond_to :on_ack
RedStorm::SimpleSpout.should respond_to :on_fail
RedStorm::SimpleSpout.should respond_to :log
end
it "should implement dsl instance statements" do
spout = RedStorm::SimpleSpout.new
spout.should respond_to :emit
spout.should respond_to :log
end
end
describe "dsl" do
@ -316,6 +324,76 @@ describe RedStorm::SimpleSpout do
end
end
# log specs are mostly the same ats in the bolt specs. if these are modified, sync with bolt
describe "log statement" do
class Logger; end # mock log4j Logger class which does not exists in the specs context
describe "in class" do
it "should proxy to storm log4j logger" do
logger = mock(Logger)
Logger.should_receive("getLogger").with("Spout1").and_return(logger)
logger.should_receive(:info).with("test")
class Spout1 < RedStorm::SimpleSpout
log.info("test")
end
end
it "should use own class name as logger id" do
logger1 = mock(Logger)
logger2 = mock(Logger)
Logger.should_receive("getLogger").with("Spout1").and_return(logger1)
Logger.should_receive("getLogger").with("Spout2").and_return(logger2)
logger1.should_receive(:info).with("test1")
logger2.should_receive(:info).with("test2")
class Spout1 < RedStorm::SimpleSpout
log.info("test1")
end
class Spout2 < RedStorm::SimpleSpout
log.info("test2")
end
end
end
describe "in instance" do
it "should proxy to storm log4j logger" do
logger = mock(Logger)
Logger.should_receive("getLogger").with("Spout1").and_return(logger)
class Spout1 < RedStorm::SimpleSpout
on_init {log.info("test")}
end
logger.should_receive(:info).with("test")
spout = Spout1.new
spout.open(nil, nil, nil)
end
it "should use own class name as logger id" do
logger1 = mock(Logger)
logger2 = mock(Logger)
Logger.should_receive("getLogger").with("Spout1").and_return(logger1)
Logger.should_receive("getLogger").with("Spout2").and_return(logger2)
class Spout1 < RedStorm::SimpleSpout
on_init {log.info("test1")}
end
class Spout2 < RedStorm::SimpleSpout
on_init {log.info("test2")}
end
logger1.should_receive(:info).with("test1")
spout1 = Spout1.new
spout1.open(nil, nil, nil)
logger2.should_receive(:info).with("test2")
spout2 = Spout2.new
spout2.open(nil, nil, nil)
end
end
end
end
describe "spout" do