[ML] Add check to prevent NoSuchElementException (elastic/x-pack-elasticsearch#1147)

Original commit: elastic/x-pack-elasticsearch@dca4020734
This commit is contained in:
David Kyle 2017-04-20 18:10:32 +01:00 committed by GitHub
parent f9b8c82137
commit a11e52fea2
2 changed files with 9 additions and 1 deletions

View File

@ -81,7 +81,9 @@ public class DataStreamDiagnostics {
*/
public void flush() {
// flush all we know
flush(movingBucketHistogram.lastKey() + 1);
if (movingBucketHistogram.isEmpty() == false) {
flush(movingBucketHistogram.lastKey() + 1);
}
}
/**

View File

@ -259,6 +259,12 @@ public class DataStreamDiagnosticsTests extends ESTestCase {
assertEquals(null, d.getLatestEmptyBucketTime());
}
public void testFlushAfterZeroRecords() {
DataStreamDiagnostics d = new DataStreamDiagnostics(job);
d.flush();
assertEquals(0, d.getBucketCount());
}
private void sendManyDataPoints(DataStreamDiagnostics d, long recordTimestampInMsMin, long recordTimestampInMsMax, long howMuch) {
long range = recordTimestampInMsMax - recordTimestampInMsMin;