Class: Fluent::Test::Driver::BaseOwner
- Inherits:
-
Base
- Object
- Base
- Fluent::Test::Driver::BaseOwner
show all
- Defined in:
- lib/fluent/test/driver/base_owner.rb
Defined Under Namespace
Classes: Emit, ErrorEvent
Constant Summary
Constants inherited
from Base
Fluent::Test::Driver::Base::DEFAULT_TIMEOUT
Instance Attribute Summary
Attributes inherited from Base
#instance, #logs
Instance Method Summary
collapse
-
#configure(conf, syntax: :v1) ⇒ Object
-
#emit_count ⇒ Object
-
#emit_error_event(tag, time, record, error) ⇒ Object
-
#emit_event_stream(tag, es) ⇒ Object
-
#error_events(tag: nil) ⇒ Object
-
#event_streams(tag: nil) ⇒ Object
-
#events(tag: nil) ⇒ Object
-
#initialize(klass, opts: {}, &block) ⇒ BaseOwner
constructor
A new instance of BaseOwner.
-
#record_count ⇒ Object
-
#run(expect_emits: nil, expect_records: nil, timeout: nil, start: true, shutdown: true, &block) ⇒ Object
Methods inherited from Base
#break_if, #broken?, #end_if, #instance_hook_after_started, #instance_hook_before_stopped, #instance_shutdown, #instance_start, #run_actual, #stop?
Constructor Details
#initialize(klass, opts: {}, &block) ⇒ BaseOwner
Returns a new instance of BaseOwner.
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fluent/test/driver/base_owner.rb', line 24
def initialize(klass, opts: {}, &block)
super
if opts
@instance.system_config_override(opts)
end
@instance.log = TestLogger.new
@logs = @instance.log.out.logs
@event_streams = nil
@error_events = nil
end
|
Instance Method Details
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/fluent/test/driver/base_owner.rb', line 37
def configure(conf, syntax: :v1)
if conf.is_a?(Fluent::Config::Element)
@config = conf
else
@config = Config.parse(conf, "(test)", "(test_dir)", syntax: syntax)
end
if @instance.respond_to?(:router=)
@event_streams = []
@error_events = []
driver = self
mojule = Module.new do
define_method(:event_emitter_router) do |label_name|
TestEventRouter.new(driver)
end
end
@instance.singleton_class.prepend mojule
end
@instance.configure(@config)
self
end
|
#emit_count ⇒ Object
103
104
105
|
# File 'lib/fluent/test/driver/base_owner.rb', line 103
def emit_count
@event_streams.size
end
|
#emit_error_event(tag, time, record, error) ⇒ Object
69
70
71
|
# File 'lib/fluent/test/driver/base_owner.rb', line 69
def emit_error_event(tag, time, record, error)
@error_events << ErrorEvent.new(tag, time, record, error)
end
|
#emit_event_stream(tag, es) ⇒ Object
65
66
67
|
# File 'lib/fluent/test/driver/base_owner.rb', line 65
def emit_event_stream(tag, es)
@event_streams << Emit.new(tag, es)
end
|
#error_events(tag: nil) ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/fluent/test/driver/base_owner.rb', line 111
def error_events(tag: nil)
selected = @error_events.select{|e| tag.nil? ? true : e.tag == tag }
if block_given?
selected.each do |e|
yield e.tag, e.time, e.record, e.error
end
else
selected.map{|e| [e.tag, e.time, e.record, e.error] }
end
end
|
#event_streams(tag: nil) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/fluent/test/driver/base_owner.rb', line 91
def event_streams(tag: nil)
return [] if @event_streams.nil?
selected = @event_streams.select{|e| tag.nil? ? true : e.tag == tag }
if block_given?
selected.each do |e|
yield e.tag, e.es
end
else
selected.map{|e| [e.tag, e.es] }
end
end
|
#events(tag: nil) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/fluent/test/driver/base_owner.rb', line 73
def events(tag: nil)
if block_given?
event_streams(tag: tag) do |t, es|
es.each do |time, record|
yield t, time, record
end
end
else
list = []
event_streams(tag: tag) do |t, es|
es.each do |time, record|
list << [t, time, record]
end
end
list
end
end
|
#record_count ⇒ Object
107
108
109
|
# File 'lib/fluent/test/driver/base_owner.rb', line 107
def record_count
@event_streams.reduce(0) {|a, e| a + e.es.size }
end
|
#run(expect_emits: nil, expect_records: nil, timeout: nil, start: true, shutdown: true, &block) ⇒ Object
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/fluent/test/driver/base_owner.rb', line 122
def run(expect_emits: nil, expect_records: nil, timeout: nil, start: true, shutdown: true, &block)
if expect_emits
@run_post_conditions << ->(){ emit_count >= expect_emits }
end
if expect_records
@run_post_conditions << ->(){ record_count >= expect_records }
end
super(timeout: timeout, start: start, shutdown: shutdown, &block)
end
|