Parent

Class/Module Index [+]

Quicksearch

Fluent::Test::InputTestDriver

Attributes

emit_streams[R]
expected_emits_length[RW]
run_timeout[RW]

Public Class Methods

new(klass, &block) click to toggle source
# File lib/fluent/test/input_test.rb, line 26
def initialize(klass, &block)
  FileBuffer.clear_buffer_paths
  super(klass, &block)
  @emit_streams = []
  @expects = nil
  # for checking only the number of emitted records during run
  @expected_emits_length = nil
  @run_timeout = 5
end

Public Instance Methods

emits() click to toggle source
# File lib/fluent/test/input_test.rb, line 49
def emits
  all = []
  @emit_streams.each {|tag,events|
    events.each {|time,record|
      all << [tag, time, record]
    }
  }
  all
end
events() click to toggle source
# File lib/fluent/test/input_test.rb, line 59
def events
  all = []
  @emit_streams.each {|tag,events|
    all.concat events
  }
  all
end
expect_emit(tag, time, record) click to toggle source
# File lib/fluent/test/input_test.rb, line 36
def expect_emit(tag, time, record)
  (@expects ||= []) << [tag, time, record]
  self
end
expected_emits() click to toggle source
# File lib/fluent/test/input_test.rb, line 41
def expected_emits
  @expects ||= []
end
records() click to toggle source
# File lib/fluent/test/input_test.rb, line 67
def records
  all = []
  @emit_streams.each {|tag,events|
    events.each {|time,record|
      all << record
    }
  }
  all
end
register_run_breaking_condition(&block) click to toggle source
# File lib/fluent/test/input_test.rb, line 84
def register_run_breaking_condition(&block)
  if block
    @run_breaking_conditions ||= []
    @run_breaking_conditions << block
  end
end
register_run_post_condition(&block) click to toggle source
# File lib/fluent/test/input_test.rb, line 77
def register_run_post_condition(&block)
  if block
    @run_post_conditions ||= []
    @run_post_conditions << block
  end
end
run(&block) click to toggle source
# File lib/fluent/test/input_test.rb, line 105
def run(&block)
  m = method(:emit_stream)
  Engine.define_singleton_method(:emit_stream) {|tag,es|
    m.call(tag, es)
  }
  instance.router.define_singleton_method(:emit_stream) {|tag,es|
    m.call(tag, es)
  }
  super {
    block.call if block

    if @expected_emits_length || @expects || @run_post_conditions
      # counters for emits and emit_streams
      i, j = 0, 0

      # Events of expected length will be emitted at the end.
      max_length = @expected_emits_length
      max_length ||= @expects.length if @expects
      if max_length
        register_run_post_condition do
          i == max_length
        end
      end

      # Set runnning timeout to avoid infinite loop caused by some errors.
      started_at = Time.now
      register_run_breaking_condition do
        Time.now >= started_at + @run_timeout
      end

      until run_should_stop?
        if j >= @emit_streams.length
          sleep 0.01
          next
        end

        tag, events = @emit_streams[j]
        events.each do |time, record|
          assert_equal(@expects[i], [tag, time, record]) if @expects
          i += 1
        end
        j += 1
      end
      assert_equal(@expects.length, i) if @expects
    end
  }
  self
end
run_should_stop?() click to toggle source
# File lib/fluent/test/input_test.rb, line 91
def run_should_stop?
  # Should stop running if post conditions are not registered.
  return true unless @run_post_conditions

  # Should stop running if all of the post conditions are true.
  return true if @run_post_conditions.all? {|proc| proc.call }

  # Should stop running if any of the breaking conditions is true.
  # In this case, some post conditions may be not true.
  return true if @run_breaking_conditions && @run_breaking_conditions.any? {|proc| proc.call }

  false
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.