20
20
import java .util .Map ;
21
21
22
22
import static org .hamcrest .Matchers .equalTo ;
23
+ import static org .hamcrest .Matchers .is ;
23
24
24
25
public class RerouteProcessorTests extends ESTestCase {
25
26
@@ -29,6 +30,7 @@ public void testDefaults() throws Exception {
29
30
RerouteProcessor processor = createRerouteProcessor (List .of (), List .of ());
30
31
processor .execute (ingestDocument );
31
32
assertDataSetFields (ingestDocument , "logs" , "generic" , "default" );
33
+ assertThat (ingestDocument .isReroute (), is (true ));
32
34
}
33
35
34
36
public void testEventDataset () throws Exception {
@@ -38,6 +40,7 @@ public void testEventDataset() throws Exception {
38
40
RerouteProcessor processor = createRerouteProcessor (List .of ("{{event.dataset}}" ), List .of ());
39
41
processor .execute (ingestDocument );
40
42
assertDataSetFields (ingestDocument , "logs" , "foo" , "default" );
43
+ assertThat (ingestDocument .isReroute (), is (true ));
41
44
assertThat (ingestDocument .getFieldValue ("event.dataset" , String .class ), equalTo ("foo" ));
42
45
}
43
46
@@ -48,6 +51,7 @@ public void testEventDatasetDottedFieldName() throws Exception {
48
51
RerouteProcessor processor = createRerouteProcessor (List .of ("{{event.dataset}}" ), List .of ());
49
52
processor .execute (ingestDocument );
50
53
assertDataSetFields (ingestDocument , "logs" , "foo" , "default" );
54
+ assertThat (ingestDocument .isReroute (), is (true ));
51
55
assertThat (ingestDocument .getCtxMap ().get ("event.dataset" ), equalTo ("foo" ));
52
56
assertFalse (ingestDocument .getCtxMap ().containsKey ("event" ));
53
57
}
@@ -59,6 +63,7 @@ public void testNoDataset() throws Exception {
59
63
RerouteProcessor processor = createRerouteProcessor (List .of ("{{ds}}" ), List .of ());
60
64
processor .execute (ingestDocument );
61
65
assertDataSetFields (ingestDocument , "logs" , "foo" , "default" );
66
+ assertThat (ingestDocument .isReroute (), is (true ));
62
67
assertFalse (ingestDocument .hasField ("event.dataset" ));
63
68
}
64
69
@@ -70,6 +75,7 @@ public void testSkipFirstProcessor() throws Exception {
70
75
CompoundProcessor processor = new CompoundProcessor (new SkipProcessor (skippedProcessor ), executedProcessor );
71
76
processor .execute (ingestDocument );
72
77
assertDataSetFields (ingestDocument , "logs" , "executed" , "default" );
78
+ assertThat (ingestDocument .isReroute (), is (true ));
73
79
}
74
80
75
81
public void testSkipLastProcessor () throws Exception {
@@ -80,6 +86,7 @@ public void testSkipLastProcessor() throws Exception {
80
86
CompoundProcessor processor = new CompoundProcessor (executedProcessor , skippedProcessor );
81
87
processor .execute (ingestDocument );
82
88
assertDataSetFields (ingestDocument , "logs" , "executed" , "default" );
89
+ assertThat (ingestDocument .isReroute (), is (true ));
83
90
}
84
91
85
92
public void testDataStreamFieldsFromDocument () throws Exception {
@@ -90,6 +97,7 @@ public void testDataStreamFieldsFromDocument() throws Exception {
90
97
RerouteProcessor processor = createRerouteProcessor (List .of (), List .of ());
91
98
processor .execute (ingestDocument );
92
99
assertDataSetFields (ingestDocument , "logs" , "foo" , "bar" );
100
+ assertThat (ingestDocument .isReroute (), is (true ));
93
101
}
94
102
95
103
public void testDataStreamFieldsFromDocumentDottedNotation () throws Exception {
@@ -101,6 +109,7 @@ public void testDataStreamFieldsFromDocumentDottedNotation() throws Exception {
101
109
RerouteProcessor processor = createRerouteProcessor (List .of (), List .of ());
102
110
processor .execute (ingestDocument );
103
111
assertDataSetFields (ingestDocument , "logs" , "foo" , "bar" );
112
+ assertThat (ingestDocument .isReroute (), is (true ));
104
113
}
105
114
106
115
public void testInvalidDataStreamFieldsFromDocument () throws Exception {
@@ -111,6 +120,7 @@ public void testInvalidDataStreamFieldsFromDocument() throws Exception {
111
120
RerouteProcessor processor = createRerouteProcessor (List .of (), List .of ());
112
121
processor .execute (ingestDocument );
113
122
assertDataSetFields (ingestDocument , "logs" , "foo_bar" , "baz_qux" );
123
+ assertThat (ingestDocument .isReroute (), is (true ));
114
124
}
115
125
116
126
public void testDestination () throws Exception {
@@ -120,6 +130,7 @@ public void testDestination() throws Exception {
120
130
processor .execute (ingestDocument );
121
131
assertFalse (ingestDocument .hasField ("data_stream" ));
122
132
assertThat (ingestDocument .getFieldValue ("_index" , String .class ), equalTo ("foo" ));
133
+ assertThat (ingestDocument .isReroute (), is (true ));
123
134
}
124
135
125
136
public void testFieldReference () throws Exception {
@@ -130,6 +141,7 @@ public void testFieldReference() throws Exception {
130
141
RerouteProcessor processor = createRerouteProcessor (List .of ("{{service.name}}" ), List .of ("{{service.environment}}" ));
131
142
processor .execute (ingestDocument );
132
143
assertDataSetFields (ingestDocument , "logs" , "opbeans_java" , "dev" );
144
+ assertThat (ingestDocument .isReroute (), is (true ));
133
145
}
134
146
135
147
public void testRerouteToCurrentTarget () throws Exception {
@@ -142,6 +154,7 @@ public void testRerouteToCurrentTarget() throws Exception {
142
154
);
143
155
processor .execute (ingestDocument );
144
156
assertDataSetFields (ingestDocument , "logs" , "generic" , "default" );
157
+ assertThat (ingestDocument .isReroute (), is (true ));
145
158
assertFalse (ingestDocument .hasField ("pipeline_is_continued" ));
146
159
}
147
160
@@ -156,6 +169,7 @@ public void testFieldReferenceWithMissingReroutesToCurrentTarget() throws Except
156
169
processor .execute (ingestDocument );
157
170
assertThat (ingestDocument .getFieldValue ("_index" , String .class ), equalTo ("logs-generic-default" ));
158
171
assertDataSetFields (ingestDocument , "logs" , "generic" , "default" );
172
+ assertThat (ingestDocument .isReroute (), is (true ));
159
173
assertFalse (ingestDocument .hasField ("pipeline_is_continued" ));
160
174
}
161
175
@@ -170,6 +184,7 @@ public void testDataStreamFieldReference() throws Exception {
170
184
);
171
185
processor .execute (ingestDocument );
172
186
assertDataSetFields (ingestDocument , "logs" , "dataset_from_doc" , "namespace_from_doc" );
187
+ assertThat (ingestDocument .isReroute (), is (true ));
173
188
}
174
189
175
190
public void testDatasetFieldReferenceMissingValue () throws Exception {
@@ -181,6 +196,7 @@ public void testDatasetFieldReferenceMissingValue() throws Exception {
181
196
);
182
197
processor .execute (ingestDocument );
183
198
assertDataSetFields (ingestDocument , "logs" , "fallback" , "fallback" );
199
+ assertThat (ingestDocument .isReroute (), is (true ));
184
200
}
185
201
186
202
public void testDatasetFieldReference () throws Exception {
@@ -194,6 +210,7 @@ public void testDatasetFieldReference() throws Exception {
194
210
);
195
211
processor .execute (ingestDocument );
196
212
assertDataSetFields (ingestDocument , "logs" , "generic" , "default" );
213
+ assertThat (ingestDocument .isReroute (), is (true ));
197
214
}
198
215
199
216
public void testFallbackToValuesFrom_index () throws Exception {
@@ -204,6 +221,7 @@ public void testFallbackToValuesFrom_index() throws Exception {
204
221
RerouteProcessor processor = createRerouteProcessor (List .of ("{{foo}}" ), List .of ("{{bar}}" ));
205
222
processor .execute (ingestDocument );
206
223
assertDataSetFields (ingestDocument , "logs" , "generic" , "default" );
224
+ assertThat (ingestDocument .isReroute (), is (true ));
207
225
}
208
226
209
227
public void testInvalidDataStreamName () throws Exception {
@@ -212,6 +230,7 @@ public void testInvalidDataStreamName() throws Exception {
212
230
RerouteProcessor processor = createRerouteProcessor (List .of (), List .of ());
213
231
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> processor .execute (ingestDocument ));
214
232
assertThat (e .getMessage (), equalTo ("invalid data stream name: [foo]; must follow naming scheme <type>-<dataset>-<namespace>" ));
233
+ assertThat (ingestDocument .isReroute (), is (false ));
215
234
}
216
235
217
236
{
@@ -220,6 +239,7 @@ public void testInvalidDataStreamName() throws Exception {
220
239
RerouteProcessor processor = createRerouteProcessor ("bar" );
221
240
processor .execute (ingestDocument );
222
241
assertThat (ingestDocument .getFieldValue ("_index" , String .class ), equalTo ("bar" ));
242
+ assertThat (ingestDocument .isReroute (), is (true ));
223
243
}
224
244
}
225
245
@@ -229,6 +249,7 @@ public void testRouteOnNonStringFieldFails() {
229
249
RerouteProcessor processor = createRerouteProcessor (List .of ("{{numeric_field}}" ), List .of ());
230
250
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> processor .execute (ingestDocument ));
231
251
assertThat (e .getMessage (), equalTo ("field [numeric_field] of type [java.lang.Integer] cannot be cast to [java.lang.String]" ));
252
+ assertThat (ingestDocument .isReroute (), is (false ));
232
253
}
233
254
234
255
public void testDatasetSanitization () {
0 commit comments