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 = EventTime.now) ⇒ Object (also: #filter)
- #emit_with_tag(tag, record, time = EventTime.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.
23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#filtered ⇒ Object (readonly)
Returns the value of attribute filtered.
30 31 32 |
# File 'lib/fluent/test/filter_test.rb', line 30 def filtered @filtered end |
#tag ⇒ Object
Returns the value of attribute tag.
31 32 33 |
# File 'lib/fluent/test/filter_test.rb', line 31 def tag @tag end |
Instance Method Details
#emit(record, time = EventTime.now) ⇒ Object Also known as: filter
33 34 35 |
# File 'lib/fluent/test/filter_test.rb', line 33 def emit(record, time = EventTime.now) emit_with_tag(@tag, record, time) end |
#emit_with_tag(tag, record, time = EventTime.now) ⇒ Object Also known as: filter_with_tag
38 39 40 41 |
# File 'lib/fluent/test/filter_test.rb', line 38 def emit_with_tag(tag, record, time = EventTime.now) @events[tag] ||= MultiEventStream.new @events[tag].add(time, record) end |
#filter_stream(es) ⇒ Object
44 45 46 |
# 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) ⇒ Object
48 49 50 |
# File 'lib/fluent/test/filter_test.rb', line 48 def filter_stream_with_tag(tag, es) @events[tag] = es end |
#filtered_as_array ⇒ Object Also known as: emits
52 53 54 55 56 57 58 |
# File 'lib/fluent/test/filter_test.rb', line 52 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.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |