class Fluent::Test::BufferedOutputTestDriver

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 52
def initialize(klass, tag='test', &block)
  super(klass, &block)
  @entries = []
  @expected_buffer = nil
  @tag = tag

  def @instance.buffer
    @buffer
  end
end

Public Instance Methods

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

    es = ArrayEventStream.new(@entries)
    buffer = @instance.format_stream(@tag, es)

    if @expected_buffer
      assert_equal(@expected_buffer, buffer)
    end

    chunk = if @instance.instance_eval{ @chunk_key_tag }
              @instance.buffer.generate_chunk(@instance.metadata(@tag, nil, nil)).staged!
            else
              @instance.buffer.generate_chunk(@instance.metadata(nil, nil, nil)).staged!
            end
    chunk.concat(buffer, es.size)

    begin
      result = @instance.write(chunk)
    ensure
      chunk.purge
    end
  }
  result
end