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 111
def initialize(klass, tag='test', &block)
  super(klass, &block)
  @entries = {}
  @expected_buffer = nil
  @tag = tag
end

Public Instance Methods

emit(record, time=Time.now) click to toggle source
# File lib/fluent/test/output_test.rb, line 120
def emit(record, time=Time.now)
  slicer = @instance.instance_eval{@time_slicer}
  key = slicer.call(time.to_i)
  @entries[key] = [] unless @entries.has_key?(key)
  @entries[key] << [time.to_i, record]
  self
end
expect_format(str) click to toggle source
# File lib/fluent/test/output_test.rb, line 128
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 132
def run(&block)
  result = []
  super {
    block.call if block

    buffer = ''
    @entries.keys.each {|key|
      es = ArrayEventStream.new(@entries[key])
      @instance.emit(@tag, es, NullOutputChain.instance)
      buffer << @instance.format_stream(@tag, es)
    }

    if @expected_buffer
      assert_equal(@expected_buffer, buffer)
    end

    chunks = []
    @instance.instance_eval do
      @buffer.instance_eval{ @map.keys }.each do |key|
        @buffer.push(key)
        chunks << @buffer.instance_eval{ @queue.pop }
      end
    end
    chunks.each { |chunk|
      begin
        result.push(@instance.write(chunk))
      ensure
        chunk.purge
      end
    }
  }
  result
end