Class: Fluent::Test::TestDriver

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions
Defined in:
lib/fluent/test/base.rb

Direct Known Subclasses

FilterTestDriver, InputTestDriver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, &block) ⇒ TestDriver

Returns a new instance of TestDriver.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fluent/test/base.rb', line 40

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 = Class.new(klass)
      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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



59
60
61
# File 'lib/fluent/test/base.rb', line 59

def config
  @config
end

#instanceObject (readonly)

Returns the value of attribute instance.



59
60
61
# File 'lib/fluent/test/base.rb', line 59

def instance
  @instance
end

Instance Method Details

#configure(str, use_v1 = false) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fluent/test/base.rb', line 61

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

#run(num_waits = 10, &block) ⇒ Object

num_waits is for checking thread status. This will be removed after improved plugin API



75
76
77
78
79
80
81
82
83
84
# File 'lib/fluent/test/base.rb', line 75

def run(num_waits = 10, &block)
  @instance.start
  begin
    # wait until thread starts
    num_waits.times { sleep 0.05 }
    return yield
  ensure
    @instance.shutdown
  end
end