|
17 | 17 | import org.elasticsearch.common.settings.Settings;
|
18 | 18 | import org.elasticsearch.common.unit.ByteSizeUnit;
|
19 | 19 | import org.elasticsearch.common.unit.ByteSizeValue;
|
20 |
| -import org.elasticsearch.common.unit.TimeValue; |
21 | 20 | import org.elasticsearch.common.util.concurrent.ThreadContext;
|
22 | 21 | import org.elasticsearch.index.shard.ShardId;
|
23 | 22 | import org.elasticsearch.test.ESTestCase;
|
|
52 | 51 | import java.util.Iterator;
|
53 | 52 | import java.util.List;
|
54 | 53 | import java.util.concurrent.ScheduledThreadPoolExecutor;
|
55 |
| -import java.util.concurrent.TimeUnit; |
56 | 54 | import java.util.concurrent.TimeoutException;
|
57 | 55 |
|
58 | 56 | import static org.hamcrest.Matchers.equalTo;
|
59 | 57 | import static org.hamcrest.Matchers.is;
|
60 | 58 | import static org.hamcrest.Matchers.nullValue;
|
61 | 59 | import static org.mockito.Matchers.any;
|
62 |
| -import static org.mockito.Matchers.anyString; |
63 | 60 | import static org.mockito.Matchers.eq;
|
64 | 61 | import static org.mockito.Matchers.same;
|
65 | 62 | import static org.mockito.Mockito.doThrow;
|
@@ -213,65 +210,6 @@ public void testProcessResult_categoryDefinition() {
|
213 | 210 | verify(persister).bulkPersisterBuilder(eq(JOB_ID), any());
|
214 | 211 | }
|
215 | 212 |
|
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 | 213 | public void testProcessResult_flushAcknowledgement() {
|
276 | 214 | AutodetectResult result = mock(AutodetectResult.class);
|
277 | 215 | FlushAcknowledgement flushAcknowledgement = mock(FlushAcknowledgement.class);
|
@@ -335,11 +273,6 @@ public void testProcessResult_modelSizeStats() {
|
335 | 273 | }
|
336 | 274 |
|
337 | 275 | public void testProcessResult_modelSizeStatsWithMemoryStatusChanges() {
|
338 |
| - TimeValue delay = TimeValue.timeValueSeconds(5); |
339 |
| - // Set up schedule delay time |
340 |
| - when(threadPool.schedule(any(Runnable.class), any(TimeValue.class), anyString())) |
341 |
| - .thenAnswer(i -> executor.schedule((Runnable) i.getArguments()[0], delay.nanos(), TimeUnit.NANOSECONDS)); |
342 |
| - |
343 | 276 | AutodetectResult result = mock(AutodetectResult.class);
|
344 | 277 | processorUnderTest.setDeleteInterimRequired(false);
|
345 | 278 |
|
@@ -374,6 +307,48 @@ public void testProcessResult_modelSizeStatsWithMemoryStatusChanges() {
|
374 | 307 | verify(auditor).error(JOB_ID, Messages.getMessage(Messages.JOB_AUDIT_MEMORY_STATUS_HARD_LIMIT, "512mb", "1kb"));
|
375 | 308 | }
|
376 | 309 |
|
| 310 | + public void testProcessResult_modelSizeStatsWithCategorizationStatusChanges() { |
| 311 | + AutodetectResult result = mock(AutodetectResult.class); |
| 312 | + processorUnderTest.setDeleteInterimRequired(false); |
| 313 | + |
| 314 | + // First one with ok |
| 315 | + ModelSizeStats modelSizeStats = |
| 316 | + new ModelSizeStats.Builder(JOB_ID).setCategorizationStatus(ModelSizeStats.CategorizationStatus.OK).build(); |
| 317 | + when(result.getModelSizeStats()).thenReturn(modelSizeStats); |
| 318 | + processorUnderTest.processResult(result); |
| 319 | + |
| 320 | + // Now one with warn |
| 321 | + modelSizeStats = new ModelSizeStats.Builder(JOB_ID).setCategorizationStatus(ModelSizeStats.CategorizationStatus.WARN).build(); |
| 322 | + when(result.getModelSizeStats()).thenReturn(modelSizeStats); |
| 323 | + processorUnderTest.processResult(result); |
| 324 | + |
| 325 | + // Another with warn |
| 326 | + modelSizeStats = new ModelSizeStats.Builder(JOB_ID).setCategorizationStatus(ModelSizeStats.CategorizationStatus.WARN).build(); |
| 327 | + when(result.getModelSizeStats()).thenReturn(modelSizeStats); |
| 328 | + processorUnderTest.processResult(result); |
| 329 | + |
| 330 | + verify(persister).bulkPersisterBuilder(eq(JOB_ID), any()); |
| 331 | + verify(persister, times(3)).persistModelSizeStats(any(ModelSizeStats.class), any()); |
| 332 | + // We should have only fired one notification; only the change from ok to warn should have fired, not the subsequent warn |
| 333 | + verify(auditor).warning(JOB_ID, Messages.getMessage(Messages.JOB_AUDIT_CATEGORIZATION_STATUS_WARN, "warn", 0)); |
| 334 | + } |
| 335 | + |
| 336 | + public void testProcessResult_modelSizeStatsWithFirstCategorizationStatusWarn() { |
| 337 | + AutodetectResult result = mock(AutodetectResult.class); |
| 338 | + processorUnderTest.setDeleteInterimRequired(false); |
| 339 | + |
| 340 | + // First one with warn - this works because a default constructed ModelSizeStats has CategorizationStatus.OK |
| 341 | + ModelSizeStats modelSizeStats = |
| 342 | + new ModelSizeStats.Builder(JOB_ID).setCategorizationStatus(ModelSizeStats.CategorizationStatus.WARN).build(); |
| 343 | + when(result.getModelSizeStats()).thenReturn(modelSizeStats); |
| 344 | + processorUnderTest.processResult(result); |
| 345 | + |
| 346 | + verify(persister).bulkPersisterBuilder(eq(JOB_ID), any()); |
| 347 | + verify(persister).persistModelSizeStats(any(ModelSizeStats.class), any()); |
| 348 | + // We should have only fired one notification; only the change from ok to warn should have fired, not the subsequent warn |
| 349 | + verify(auditor).warning(JOB_ID, Messages.getMessage(Messages.JOB_AUDIT_CATEGORIZATION_STATUS_WARN, "warn", 0)); |
| 350 | + } |
| 351 | + |
377 | 352 | public void testProcessResult_modelSnapshot() {
|
378 | 353 | AutodetectResult result = mock(AutodetectResult.class);
|
379 | 354 | ModelSnapshot modelSnapshot = new ModelSnapshot.Builder(JOB_ID)
|
|
0 commit comments