Class: Fluent::Test::FilterTestDriver
- Inherits:
-
TestDriver
- Object
- TestDriver
- Fluent::Test::FilterTestDriver
- Defined in:
- lib/fluent/test/filter_test.rb
Instance Attribute Summary collapse
-
#filtered ⇒ Object
readonly
Returns the value of attribute filtered.
-
#tag ⇒ Object
Returns the value of attribute tag.
Attributes inherited from TestDriver
Instance Method Summary collapse
- #emit(record, time = Engine.now) ⇒ Object (also: #filter)
- #emit_with_tag(tag, record, time = Engine.now) ⇒ Object (also: #filter_with_tag)
- #filter_stream(es) ⇒ Object
- #filter_stream_with_tag(tag, es) ⇒ Object
- #filtered_as_array ⇒ Object (also: #emits)
-
#initialize(klass, tag = 'filter.test', &block) ⇒ FilterTestDriver
constructor
A new instance of FilterTestDriver.
-
#run(num_waits = 0, &block) ⇒ Object
Almost filters don’t use threads so default is 0.
Methods inherited from TestDriver
Constructor Details
#initialize(klass, tag = 'filter.test', &block) ⇒ FilterTestDriver
Returns a new instance of FilterTestDriver.
24 25 26 27 28 29 |
# File 'lib/fluent/test/filter_test.rb', line 24 def initialize(klass, tag = 'filter.test', &block) super(klass, &block) @tag = tag @events = {} @filtered = MultiEventStream.new end |
Instance Attribute Details
#filtered ⇒ Object (readonly)
Returns the value of attribute filtered.
31 32 33 |
# File 'lib/fluent/test/filter_test.rb', line 31 def filtered @filtered end |
#tag ⇒ Object
Returns the value of attribute tag.
32 33 34 |
# File 'lib/fluent/test/filter_test.rb', line 32 def tag @tag end |
Instance Method Details
#emit(record, time = Engine.now) ⇒ Object Also known as: filter
34 35 36 |
# File 'lib/fluent/test/filter_test.rb', line 34 def emit(record, time = Engine.now) emit_with_tag(@tag, record, time) end |
#emit_with_tag(tag, record, time = Engine.now) ⇒ Object Also known as: filter_with_tag
39 40 41 42 |
# File 'lib/fluent/test/filter_test.rb', line 39 def emit_with_tag(tag, record, time = Engine.now) @events[tag] ||= MultiEventStream.new @events[tag].add(time, record) end |
#filter_stream(es) ⇒ Object
45 46 47 |
# File 'lib/fluent/test/filter_test.rb', line 45 def filter_stream(es) filter_stream_with_tag(@tag, es) end |
#filter_stream_with_tag(tag, es) ⇒ Object
49 50 51 |
# File 'lib/fluent/test/filter_test.rb', line 49 def filter_stream_with_tag(tag, es) @events[tag] = es end |
#filtered_as_array ⇒ Object Also known as: emits
53 54 55 56 57 58 59 |
# File 'lib/fluent/test/filter_test.rb', line 53 def filtered_as_array all = [] @filtered.each { |time, record| all << [@tag, time, record] } all end |
#run(num_waits = 0, &block) ⇒ Object
Almost filters don’t use threads so default is 0. It reduces test time.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fluent/test/filter_test.rb', line 63 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 |