class Fluent::Test::TimeSlicedOutputTestDriver

Attributes

tag[RW]

Public Class Methods

new(klass, tag='test', &block) click to toggle source
Calls superclass method Fluent::Test::InputTestDriver.new
# File lib/fluent/test/output_test.rb, line 104
def initialize(klass, tag='test', &block)
  super(klass, &block)
  @entries = []
  @expected_buffer = nil
  @tag = tag
end

Public Instance Methods

emit(record, time=Engine.now) click to toggle source
# File lib/fluent/test/output_test.rb, line 113
def emit(record, time=Engine.now)
  @entries << [time, record]
  self
end
expect_format(str) click to toggle source
# File lib/fluent/test/output_test.rb, line 118
def expect_format(str)
  (@expected_buffer ||= '') << str
end
run(&block) click to toggle source
Calls superclass method Fluent::Test::InputTestDriver#run
# File lib/fluent/test/output_test.rb, line 122
def run(&block)
  result = []
  super {
    block.call if block

    buffer = ''
    lines = {}
    # v0.12 TimeSlicedOutput doesn't call #format_stream
    @entries.each do |time, record|
      meta = @instance.metadata(@tag, time, record)
      line = @instance.format(@tag, time, record)
      buffer << line
      lines[meta] ||= []
      lines[meta] << line
    end

    if @expected_buffer
      assert_equal(@expected_buffer, buffer)
    end

    lines.keys.each do |meta|
      chunk = @instance.buffer.generate_chunk(meta).staged!
      chunk.append(lines[meta])
      begin
        result.push(@instance.write(chunk))
      ensure
        chunk.purge
      end
    end
  }
  result
end