# File lib/fluent/test/base.rb, line 28 def initialize(klass, &block) if klass.is_a?(Class) if block # Create new class for test w/ overwritten methods # klass.dup is worse because its ancestors does NOT include original class name klass_name = klass.name klass = Class.new(klass) klass.define_singleton_method("name") { klass_name } klass.module_eval(&block) end @instance = klass.new else @instance = klass end @instance.router = Engine.root_agent.event_router @instance.log = TestLogger.new Engine.root_agent.instance_variable_set(:@log, @instance.log) @config = Config.new end
# File lib/fluent/test/base.rb, line 51 def configure(str, use_v1 = false) if str.is_a?(Fluent::Config::Element) @config = str else @config = Config.parse(str, "(test)", "(test_dir)", use_v1) end if label_name = @config['@label'] Engine.root_agent.add_label(label_name) end @instance.configure(@config) self end
num_waits is for checking thread status. This will be removed after improved plugin API
# File lib/fluent/test/base.rb, line 65 def run(num_waits = 10, &block) @instance.start @instance.after_start begin # wait until thread starts num_waits.times { sleep 0.05 } return yield ensure @instance.shutdown end end