@@ -133,7 +133,7 @@ public void testProcess() throws TimeoutException {
133
133
verify (persister ).commitStateWrites (JOB_ID );
134
134
}
135
135
136
- public void testProcessResult_bucket () throws Exception {
136
+ public void testProcessResult_bucket () {
137
137
when (bulkBuilder .persistTimingStats (any (TimingStats .class ))).thenReturn (bulkBuilder );
138
138
when (bulkBuilder .persistBucket (any (Bucket .class ))).thenReturn (bulkBuilder );
139
139
AutodetectResult result = mock (AutodetectResult .class );
@@ -150,7 +150,7 @@ public void testProcessResult_bucket() throws Exception {
150
150
verify (persister , never ()).deleteInterimResults (JOB_ID );
151
151
}
152
152
153
- public void testProcessResult_bucket_deleteInterimRequired () throws Exception {
153
+ public void testProcessResult_bucket_deleteInterimRequired () {
154
154
when (bulkBuilder .persistTimingStats (any (TimingStats .class ))).thenReturn (bulkBuilder );
155
155
when (bulkBuilder .persistBucket (any (Bucket .class ))).thenReturn (bulkBuilder );
156
156
AutodetectResult result = mock (AutodetectResult .class );
@@ -167,7 +167,7 @@ public void testProcessResult_bucket_deleteInterimRequired() throws Exception {
167
167
verify (persister ).deleteInterimResults (JOB_ID );
168
168
}
169
169
170
- public void testProcessResult_records () throws Exception {
170
+ public void testProcessResult_records () {
171
171
AutodetectResult result = mock (AutodetectResult .class );
172
172
List <AnomalyRecord > records =
173
173
Arrays .asList (
@@ -183,7 +183,7 @@ public void testProcessResult_records() throws Exception {
183
183
verify (persister ).bulkPersisterBuilder (eq (JOB_ID ), any ());
184
184
}
185
185
186
- public void testProcessResult_influencers () throws Exception {
186
+ public void testProcessResult_influencers () {
187
187
AutodetectResult result = mock (AutodetectResult .class );
188
188
List <Influencer > influencers =
189
189
Arrays .asList (
@@ -199,9 +199,10 @@ public void testProcessResult_influencers() throws Exception {
199
199
verify (persister ).bulkPersisterBuilder (eq (JOB_ID ), any ());
200
200
}
201
201
202
- public void testProcessResult_categoryDefinition () throws Exception {
202
+ public void testProcessResult_categoryDefinition () {
203
203
AutodetectResult result = mock (AutodetectResult .class );
204
204
CategoryDefinition categoryDefinition = mock (CategoryDefinition .class );
205
+ when (categoryDefinition .getCategoryId ()).thenReturn (1L );
205
206
when (result .getCategoryDefinition ()).thenReturn (categoryDefinition );
206
207
207
208
processorUnderTest .setDeleteInterimRequired (false );
@@ -212,7 +213,66 @@ public void testProcessResult_categoryDefinition() throws Exception {
212
213
verify (persister ).bulkPersisterBuilder (eq (JOB_ID ), any ());
213
214
}
214
215
215
- public void testProcessResult_flushAcknowledgement () throws Exception {
216
+ public void testProcessResult_excessiveCategoryDefinitionCountEarly () {
217
+ int iterations = 3 ;
218
+ int categoryCount = AutodetectResultProcessor .EXCESSIVE_EARLY_CATEGORY_COUNT * 2 ;
219
+
220
+ processorUnderTest .setDeleteInterimRequired (false );
221
+
222
+ AutodetectResult result = mock (AutodetectResult .class );
223
+ for (int iteration = 1 ; iteration <= iterations ; ++iteration ) {
224
+ for (int categoryId = 1 ; categoryId <= categoryCount ; ++categoryId ) {
225
+ CategoryDefinition categoryDefinition = new CategoryDefinition (JOB_ID );
226
+ categoryDefinition .setCategoryId (categoryId );
227
+ when (result .getCategoryDefinition ()).thenReturn (categoryDefinition );
228
+
229
+ processorUnderTest .processResult (result );
230
+ }
231
+ }
232
+
233
+ verify (bulkBuilder , never ()).executeRequest ();
234
+ verify (persister , times (iterations * categoryCount )).persistCategoryDefinition (any (CategoryDefinition .class ), any ());
235
+ verify (persister ).bulkPersisterBuilder (eq (JOB_ID ), any ());
236
+ verify (auditor ).warning (eq (JOB_ID ), eq (Messages .getMessage (Messages .JOB_AUDIT_EXCESSIVE_EARLY_CATEGORIES ,
237
+ AutodetectResultProcessor .EXCESSIVE_EARLY_CATEGORY_COUNT , 1 )));
238
+ }
239
+
240
+ public void testProcessResult_highCategoryDefinitionCountLateOn () {
241
+ int iterations = 3 ;
242
+ int categoryCount = AutodetectResultProcessor .EXCESSIVE_EARLY_CATEGORY_COUNT * 2 ;
243
+
244
+ processorUnderTest .setDeleteInterimRequired (false );
245
+
246
+ when (bulkBuilder .persistTimingStats (any (TimingStats .class ))).thenReturn (bulkBuilder );
247
+ when (bulkBuilder .persistBucket (any (Bucket .class ))).thenReturn (bulkBuilder );
248
+
249
+ AutodetectResult bucketResult = mock (AutodetectResult .class );
250
+ final int numPriorBuckets = (int ) AutodetectResultProcessor .EARLY_BUCKET_THRESHOLD + 1 ;
251
+ for (int i = 0 ; i < numPriorBuckets ; ++i ) {
252
+ Bucket bucket = new Bucket (JOB_ID , new Date (i * 1000 + 1000000 ), BUCKET_SPAN_MS );
253
+ when (bucketResult .getBucket ()).thenReturn (bucket );
254
+ processorUnderTest .processResult (bucketResult );
255
+ }
256
+
257
+ AutodetectResult categoryResult = mock (AutodetectResult .class );
258
+ for (int iteration = 1 ; iteration <= iterations ; ++iteration ) {
259
+ for (int categoryId = 1 ; categoryId <= categoryCount ; ++categoryId ) {
260
+ CategoryDefinition categoryDefinition = new CategoryDefinition (JOB_ID );
261
+ categoryDefinition .setCategoryId (categoryId );
262
+ when (categoryResult .getCategoryDefinition ()).thenReturn (categoryDefinition );
263
+ processorUnderTest .processResult (categoryResult );
264
+ }
265
+ }
266
+
267
+ verify (bulkBuilder ).persistTimingStats (any (TimingStats .class ));
268
+ verify (bulkBuilder , times (numPriorBuckets )).persistBucket (any (Bucket .class ));
269
+ verify (bulkBuilder , times (numPriorBuckets )).executeRequest ();
270
+ verify (persister , times (iterations * categoryCount )).persistCategoryDefinition (any (CategoryDefinition .class ), any ());
271
+ verify (persister ).bulkPersisterBuilder (eq (JOB_ID ), any ());
272
+ verify (auditor , never ()).warning (eq (JOB_ID ), anyString ());
273
+ }
274
+
275
+ public void testProcessResult_flushAcknowledgement () {
216
276
AutodetectResult result = mock (AutodetectResult .class );
217
277
FlushAcknowledgement flushAcknowledgement = mock (FlushAcknowledgement .class );
218
278
when (flushAcknowledgement .getId ()).thenReturn (JOB_ID );
@@ -228,12 +288,13 @@ public void testProcessResult_flushAcknowledgement() throws Exception {
228
288
verify (bulkBuilder ).executeRequest ();
229
289
}
230
290
231
- public void testProcessResult_flushAcknowledgementMustBeProcessedLast () throws Exception {
291
+ public void testProcessResult_flushAcknowledgementMustBeProcessedLast () {
232
292
AutodetectResult result = mock (AutodetectResult .class );
233
293
FlushAcknowledgement flushAcknowledgement = mock (FlushAcknowledgement .class );
234
294
when (flushAcknowledgement .getId ()).thenReturn (JOB_ID );
235
295
when (result .getFlushAcknowledgement ()).thenReturn (flushAcknowledgement );
236
296
CategoryDefinition categoryDefinition = mock (CategoryDefinition .class );
297
+ when (categoryDefinition .getCategoryId ()).thenReturn (1L );
237
298
when (result .getCategoryDefinition ()).thenReturn (categoryDefinition );
238
299
239
300
processorUnderTest .setDeleteInterimRequired (false );
@@ -248,7 +309,7 @@ public void testProcessResult_flushAcknowledgementMustBeProcessedLast() throws E
248
309
inOrder .verify (flushListener ).acknowledgeFlush (flushAcknowledgement , null );
249
310
}
250
311
251
- public void testProcessResult_modelPlot () throws Exception {
312
+ public void testProcessResult_modelPlot () {
252
313
AutodetectResult result = mock (AutodetectResult .class );
253
314
ModelPlot modelPlot = mock (ModelPlot .class );
254
315
when (result .getModelPlot ()).thenReturn (modelPlot );
@@ -260,7 +321,7 @@ public void testProcessResult_modelPlot() throws Exception {
260
321
verify (bulkBuilder ).persistModelPlot (modelPlot );
261
322
}
262
323
263
- public void testProcessResult_modelSizeStats () throws Exception {
324
+ public void testProcessResult_modelSizeStats () {
264
325
AutodetectResult result = mock (AutodetectResult .class );
265
326
ModelSizeStats modelSizeStats = mock (ModelSizeStats .class );
266
327
when (result .getModelSizeStats ()).thenReturn (modelSizeStats );
@@ -273,7 +334,7 @@ public void testProcessResult_modelSizeStats() throws Exception {
273
334
verify (persister ).persistModelSizeStats (eq (modelSizeStats ), any ());
274
335
}
275
336
276
- public void testProcessResult_modelSizeStatsWithMemoryStatusChanges () throws Exception {
337
+ public void testProcessResult_modelSizeStatsWithMemoryStatusChanges () {
277
338
TimeValue delay = TimeValue .timeValueSeconds (5 );
278
339
// Set up schedule delay time
279
340
when (threadPool .schedule (any (Runnable .class ), any (TimeValue .class ), anyString ()))
@@ -313,7 +374,7 @@ public void testProcessResult_modelSizeStatsWithMemoryStatusChanges() throws Exc
313
374
verify (auditor ).error (JOB_ID , Messages .getMessage (Messages .JOB_AUDIT_MEMORY_STATUS_HARD_LIMIT , "512mb" , "1kb" ));
314
375
}
315
376
316
- public void testProcessResult_modelSnapshot () throws Exception {
377
+ public void testProcessResult_modelSnapshot () {
317
378
AutodetectResult result = mock (AutodetectResult .class );
318
379
ModelSnapshot modelSnapshot = new ModelSnapshot .Builder (JOB_ID )
319
380
.setSnapshotId ("a_snapshot_id" )
@@ -337,7 +398,7 @@ public void testProcessResult_modelSnapshot() throws Exception {
337
398
verify (client ).execute (same (UpdateJobAction .INSTANCE ), eq (expectedJobUpdateRequest ), any ());
338
399
}
339
400
340
- public void testProcessResult_quantiles_givenRenormalizationIsEnabled () throws Exception {
401
+ public void testProcessResult_quantiles_givenRenormalizationIsEnabled () {
341
402
AutodetectResult result = mock (AutodetectResult .class );
342
403
Quantiles quantiles = mock (Quantiles .class );
343
404
when (result .getQuantiles ()).thenReturn (quantiles );
@@ -354,7 +415,7 @@ public void testProcessResult_quantiles_givenRenormalizationIsEnabled() throws E
354
415
verify (renormalizer ).renormalize (quantiles );
355
416
}
356
417
357
- public void testProcessResult_quantiles_givenRenormalizationIsDisabled () throws Exception {
418
+ public void testProcessResult_quantiles_givenRenormalizationIsDisabled () {
358
419
AutodetectResult result = mock (AutodetectResult .class );
359
420
Quantiles quantiles = mock (Quantiles .class );
360
421
when (result .getQuantiles ()).thenReturn (quantiles );
0 commit comments