1
1
require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/multi_output '
3
3
require 'fluent/plugin/out_roundrobin'
4
4
5
5
class RoundRobinOutputTest < Test ::Unit ::TestCase
6
6
class << self
7
7
def startup
8
8
$LOAD_PATH. unshift File . expand_path ( File . join ( File . dirname ( __FILE__ ) , '..' , 'scripts' ) )
9
9
require 'fluent/plugin/out_test'
10
+ require 'fluent/plugin/out_test2'
10
11
end
11
12
12
13
def shutdown
@@ -20,47 +21,54 @@ def setup
20
21
21
22
CONFIG = %[
22
23
<store>
23
- type test
24
+ @ type test
24
25
name c0
25
26
</store>
26
27
<store>
27
- type test
28
+ @ type test2
28
29
name c1
29
30
</store>
30
31
<store>
31
- type test
32
+ @ type test
32
33
name c2
33
34
</store>
34
35
]
35
36
CONFIG_WITH_WEIGHT = %[
36
37
<store>
37
- type test
38
+ @ type test
38
39
name c0
39
40
weight 3
40
41
</store>
41
42
<store>
42
- type test
43
+ @ type test2
43
44
name c1
44
45
weight 3
45
46
</store>
46
47
<store>
47
- type test
48
+ @ type test
48
49
name c2
49
50
</store>
50
51
]
51
52
52
53
def create_driver ( conf = CONFIG )
53
- Fluent ::Test ::OutputTestDriver . new ( Fluent ::RoundRobinOutput ) . configure ( conf )
54
+ Fluent ::Test ::Driver :: MultiOutput . new ( Fluent :: Plugin ::RoundRobinOutput ) . configure ( conf )
54
55
end
55
56
56
57
def test_configure
57
58
d = create_driver
58
59
59
60
outputs = d . instance . outputs
60
61
assert_equal 3 , outputs . size
61
- assert_equal Fluent ::TestOutput , outputs [ 0 ] . class
62
- assert_equal Fluent ::TestOutput , outputs [ 1 ] . class
63
- assert_equal Fluent ::TestOutput , outputs [ 2 ] . class
62
+
63
+ assert_equal Fluent ::Plugin ::TestOutput , outputs [ 0 ] . class
64
+ assert_equal Fluent ::Plugin ::Test2Output , outputs [ 1 ] . class
65
+ assert_equal Fluent ::Plugin ::TestOutput , outputs [ 2 ] . class
66
+
67
+ assert !outputs [ 0 ] . has_router?
68
+ assert outputs [ 1 ] . has_router?
69
+ assert outputs [ 1 ] . router
70
+ assert !outputs [ 2 ] . has_router?
71
+
64
72
assert_equal "c0" , outputs [ 0 ] . name
65
73
assert_equal "c1" , outputs [ 1 ] . name
66
74
assert_equal "c2" , outputs [ 2 ] . name
@@ -75,9 +83,11 @@ def test_configure
75
83
76
84
outputs = d . instance . outputs
77
85
assert_equal 3 , outputs . size
78
- assert_equal Fluent ::TestOutput , outputs [ 0 ] . class
79
- assert_equal Fluent ::TestOutput , outputs [ 1 ] . class
80
- assert_equal Fluent ::TestOutput , outputs [ 2 ] . class
86
+
87
+ assert_equal Fluent ::Plugin ::TestOutput , outputs [ 0 ] . class
88
+ assert_equal Fluent ::Plugin ::Test2Output , outputs [ 1 ] . class
89
+ assert_equal Fluent ::Plugin ::TestOutput , outputs [ 2 ] . class
90
+
81
91
assert_equal "c0" , outputs [ 0 ] . name
82
92
assert_equal "c1" , outputs [ 1 ] . name
83
93
assert_equal "c2" , outputs [ 2 ] . name
@@ -89,15 +99,15 @@ def test_configure
89
99
assert_equal 1 , weights [ 2 ]
90
100
end
91
101
92
- def test_emit
102
+ def test_events_feeded_to_plugins_by_roundrobin
93
103
d = create_driver
94
104
95
- time = Time . parse ( "2011-01-02 13:14:15 UTC" ) . to_i
96
- d . run do
97
- d . emit ( { "a" => 1 } , time )
98
- d . emit ( { "a" => 2 } , time )
99
- d . emit ( { "a" => 3 } , time )
100
- d . emit ( { "a" => 4 } , time )
105
+ time = event_time ( "2011-01-02 13:14:15 UTC" )
106
+ d . run ( default_tag : 'test' ) do
107
+ d . feed ( time , { "a" => 1 } )
108
+ d . feed ( time , { "a" => 2 } )
109
+ d . feed ( time , { "a" => 3 } )
110
+ d . feed ( time , { "a" => 4 } )
101
111
end
102
112
103
113
os = d . instance . outputs
@@ -114,19 +124,15 @@ def test_emit
114
124
assert_equal [
115
125
[ time , { "a" => 3 } ] ,
116
126
] , os [ 2 ] . events
117
-
118
- d . instance . outputs . each { |o |
119
- assert_not_nil o . router
120
- }
121
127
end
122
128
123
- def test_emit_weighted
129
+ def test_events_feeded_with_specified_weights
124
130
d = create_driver ( CONFIG_WITH_WEIGHT )
125
131
126
- time = Time . parse ( "2011-01-02 13:14:15 UTC" ) . to_i
127
- d . run do
132
+ time = event_time ( "2011-01-02 13:14:15 UTC" )
133
+ d . run ( default_tag : 'test' ) do
128
134
14 . times do |i |
129
- d . emit ( { "a" => i } , time )
135
+ d . feed ( time , { "a" => i } )
130
136
end
131
137
end
132
138
0 commit comments