class Fluent::Test::FilterTestDriver

Attributes

filtered[R]
tag[RW]

Public Class Methods

new(klass, tag = 'filter.test', &block) click to toggle source
Calls superclass method Fluent::Test::TestDriver.new
# File lib/fluent/test/filter_test.rb, line 23
def initialize(klass, tag = 'filter.test', &block)
  super(klass, &block)
  @tag = tag
  @events = {}
  @filtered = MultiEventStream.new
end

Public Instance Methods

emit(record, time = Engine.now) click to toggle source
# File lib/fluent/test/filter_test.rb, line 33
def emit(record, time = Engine.now)
  emit_with_tag(@tag, record, time)
end
Also aliased as: filter
emit_with_tag(tag, record, time = Engine.now) click to toggle source
# File lib/fluent/test/filter_test.rb, line 38
def emit_with_tag(tag, record, time = Engine.now)
  @events[tag] ||= MultiEventStream.new
  @events[tag].add(time, record)
end
Also aliased as: filter_with_tag
emits()
Alias for: filtered_as_array
filter(record, time = Engine.now)
Alias for: emit
filter_stream(es) click to toggle source
# File lib/fluent/test/filter_test.rb, line 44
def filter_stream(es)
  filter_stream_with_tag(@tag, es)
end
filter_stream_with_tag(tag, es) click to toggle source
# File lib/fluent/test/filter_test.rb, line 48
def filter_stream_with_tag(tag, es)
  @events[tag] = es
end
filter_with_tag(tag, record, time = Engine.now)
Alias for: emit_with_tag
filtered_as_array() click to toggle source
# File lib/fluent/test/filter_test.rb, line 52
def filtered_as_array
  all = []
  @filtered.each { |time, record|
    all << [@tag, time, record]
  }
  all
end
Also aliased as: emits
run(num_waits = 0, &block) click to toggle source

Almost filters don't use threads so default is 0. It reduces test time.

Calls superclass method Fluent::Test::TestDriver#run
# File lib/fluent/test/filter_test.rb, line 62
def run(num_waits = 0, &block)
  super(num_waits) {
    block.call if block

    @events.each { |tag, es|
      processed = @instance.filter_stream(tag, es)
      processed.each { |time, record|
        @filtered.add(time, record)
      }
    }
  }
  self
end