class Fluent::Test::Driver::Output

Public Class Methods

new(klass, opts: {}, &block) click to toggle source
Calls superclass method Fluent::Test::Driver::EventFeeder.new
# File lib/fluent/test/driver/output.rb, line 29
def initialize(klass, opts: {}, &block)
  super
  raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Output" unless @instance.is_a? Fluent::Plugin::Output
  @instance.in_tests = true
  @flush_buffer_at_cleanup = nil
  @format_hook = nil
  @format_results = []
end

Public Instance Methods

flush() click to toggle source
# File lib/fluent/test/driver/output.rb, line 55
def flush
  @instance.force_flush
  Timeout.timeout(10){ sleep 0.1 until !@instance.buffer || @instance.buffer.queue.size == 0 }
end
formatted() click to toggle source
# File lib/fluent/test/driver/output.rb, line 51
def formatted
  @format_results
end
instance_hook_after_started() click to toggle source
# File lib/fluent/test/driver/output.rb, line 60
def instance_hook_after_started
  super

  # it's decided after #start whether output plugin instances use @custom_format or not.
  if @instance.instance_eval{ @custom_format }
    @format_hook = format_hook = ->(result){ @format_results << result }
    m = Module.new do
      define_method(:format) do |tag, time, record|
        result = super(tag, time, record)
        format_hook.call(result)
        result
      end
    end
    @instance.singleton_class.prepend m
  end
end
run(flush: true, **kwargs, &block) click to toggle source
Calls superclass method Fluent::Test::Driver::EventFeeder#run
# File lib/fluent/test/driver/output.rb, line 38
def run(flush: true, **kwargs, &block)
  @flush_buffer_at_cleanup = flush
  super(**kwargs, &block)
end
run_actual(**kwargs, &block) click to toggle source
Calls superclass method Fluent::Test::Driver::Base#run_actual
# File lib/fluent/test/driver/output.rb, line 43
def run_actual(**kwargs, &block)
  super(**kwargs, &block)
  if @flush_buffer_at_cleanup
    @instance.force_flush
    Timeout.timeout(10){ sleep 0.1 until !@instance.buffer || @instance.buffer.queue.size == 0 }
  end
end