Class: Fluent::Test::TimeSlicedOutputTestDriver
- Inherits:
-
InputTestDriver
- Object
- TestDriver
- InputTestDriver
- Fluent::Test::TimeSlicedOutputTestDriver
- Defined in:
- lib/fluent/test/output_test.rb
Instance Attribute Summary collapse
-
#tag ⇒ Object
Returns the value of attribute tag.
Attributes inherited from InputTestDriver
#emit_streams, #event_streams, #expected_emits_length, #run_timeout
Attributes inherited from TestDriver
Instance Method Summary collapse
- #emit(record, time = EventTime.now) ⇒ Object
- #expect_format(str) ⇒ Object
-
#initialize(klass, tag = 'test', &block) ⇒ TimeSlicedOutputTestDriver
constructor
A new instance of TimeSlicedOutputTestDriver.
- #run(&block) ⇒ Object
Methods inherited from InputTestDriver
#emits, #events, #expect_emit, #expected_emits, #records, #register_run_breaking_condition, #register_run_post_condition, #run_should_stop?
Methods inherited from TestDriver
Constructor Details
#initialize(klass, tag = 'test', &block) ⇒ TimeSlicedOutputTestDriver
Returns a new instance of TimeSlicedOutputTestDriver.
104 105 106 107 108 109 |
# File 'lib/fluent/test/output_test.rb', line 104 def initialize(klass, tag='test', &block) super(klass, &block) @entries = [] @expected_buffer = nil @tag = tag end |
Instance Attribute Details
#tag ⇒ Object
Returns the value of attribute tag.
111 112 113 |
# File 'lib/fluent/test/output_test.rb', line 111 def tag @tag end |
Instance Method Details
#emit(record, time = EventTime.now) ⇒ Object
113 114 115 116 |
# File 'lib/fluent/test/output_test.rb', line 113 def emit(record, time=EventTime.now) @entries << [time, record] self end |
#expect_format(str) ⇒ Object
118 119 120 |
# File 'lib/fluent/test/output_test.rb', line 118 def expect_format(str) (@expected_buffer ||= '') << str end |
#run(&block) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fluent/test/output_test.rb', line 122 def run(&block) result = [] super { block.call if block buffer = '' lines = {} # v0.12 TimeSlicedOutput doesn't call #format_stream @entries.each do |time, record| = @instance.(@tag, time, record) line = @instance.format(@tag, time, record) buffer << line lines[] ||= [] lines[] << line end if @expected_buffer assert_equal(@expected_buffer, buffer) end lines.each_key do || chunk = @instance.buffer.generate_chunk().staged! chunk.append(lines[]) begin result.push(@instance.write(chunk)) ensure chunk.purge end end } result end |