1111import org .elasticsearch .xpack .core .ml .job .config .DataDescription ;
1212import org .elasticsearch .xpack .core .ml .job .config .Detector ;
1313import org .elasticsearch .xpack .core .ml .job .config .Job ;
14+ import org .elasticsearch .xpack .core .ml .job .process .autodetect .state .DataCounts ;
1415import org .junit .Before ;
1516
1617import java .util .Arrays ;
@@ -20,6 +21,7 @@ public class DataStreamDiagnosticsTests extends ESTestCase {
2021
2122 private static final long BUCKET_SPAN = 60000 ;
2223 private Job job ;
24+ private DataCounts dataCounts ;
2325
2426 @ Before
2527 public void setUpMocks () {
@@ -32,10 +34,11 @@ public void setUpMocks() {
3234 builder .setAnalysisConfig (acBuilder );
3335 builder .setDataDescription (new DataDescription .Builder ());
3436 job = createJob (TimeValue .timeValueMillis (BUCKET_SPAN ), null );
37+ dataCounts = new DataCounts (job .getId ());
3538 }
3639
3740 public void testIncompleteBuckets () {
38- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
41+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
3942
4043 d .checkRecord (1000 );
4144 d .checkRecord (2000 );
@@ -81,7 +84,7 @@ public void testIncompleteBuckets() {
8184 }
8285
8386 public void testSimple () {
84- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
87+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
8588
8689 d .checkRecord (70000 );
8790 d .checkRecord (130000 );
@@ -103,7 +106,7 @@ public void testSimple() {
103106 }
104107
105108 public void testSimpleReverse () {
106- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
109+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
107110
108111 d .checkRecord (610000 );
109112 d .checkRecord (550000 );
@@ -126,7 +129,7 @@ public void testSimpleReverse() {
126129
127130 public void testWithLatencyLessThanTenBuckets () {
128131 job = createJob (TimeValue .timeValueMillis (BUCKET_SPAN ), TimeValue .timeValueMillis (3 * BUCKET_SPAN ));
129- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
132+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
130133
131134 long timestamp = 70000 ;
132135 while (timestamp < 70000 + 20 * BUCKET_SPAN ) {
@@ -141,7 +144,7 @@ public void testWithLatencyLessThanTenBuckets() {
141144
142145 public void testWithLatencyGreaterThanTenBuckets () {
143146 job = createJob (TimeValue .timeValueMillis (BUCKET_SPAN ), TimeValue .timeValueMillis (13 * BUCKET_SPAN + 10000 ));
144- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
147+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
145148
146149 long timestamp = 70000 ;
147150 while (timestamp < 70000 + 20 * BUCKET_SPAN ) {
@@ -155,7 +158,7 @@ public void testWithLatencyGreaterThanTenBuckets() {
155158 }
156159
157160 public void testEmptyBuckets () {
158- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
161+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
159162
160163 d .checkRecord (10000 );
161164 d .checkRecord (70000 );
@@ -177,7 +180,7 @@ public void testEmptyBuckets() {
177180 }
178181
179182 public void testEmptyBucketsStartLater () {
180- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
183+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
181184
182185 d .checkRecord (1110000 );
183186 d .checkRecord (1170000 );
@@ -199,7 +202,7 @@ public void testEmptyBucketsStartLater() {
199202 }
200203
201204 public void testSparseBuckets () {
202- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
205+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
203206
204207 sendManyDataPoints (d , 10000 , 69000 , 1000 );
205208 sendManyDataPoints (d , 70000 , 129000 , 1200 );
@@ -227,7 +230,7 @@ public void testSparseBuckets() {
227230 * signal
228231 */
229232 public void testSparseBucketsLast () {
230- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
233+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
231234
232235 sendManyDataPoints (d , 10000 , 69000 , 1000 );
233236 sendManyDataPoints (d , 70000 , 129000 , 1200 );
@@ -255,7 +258,7 @@ public void testSparseBucketsLast() {
255258 * signal on the 2nd to last
256259 */
257260 public void testSparseBucketsLastTwo () {
258- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
261+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
259262
260263 sendManyDataPoints (d , 10000 , 69000 , 1000 );
261264 sendManyDataPoints (d , 70000 , 129000 , 1200 );
@@ -280,7 +283,7 @@ public void testSparseBucketsLastTwo() {
280283 }
281284
282285 public void testMixedEmptyAndSparseBuckets () {
283- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
286+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
284287
285288 sendManyDataPoints (d , 10000 , 69000 , 1000 );
286289 sendManyDataPoints (d , 70000 , 129000 , 1200 );
@@ -308,7 +311,7 @@ public void testMixedEmptyAndSparseBuckets() {
308311 * whether counts are right.
309312 */
310313 public void testEmptyBucketsLongerOutage () {
311- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
314+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
312315
313316 d .checkRecord (10000 );
314317 d .checkRecord (70000 );
@@ -336,7 +339,7 @@ public void testEmptyBucketsLongerOutage() {
336339 * The number of sparse buckets should not be to much, it could be normal.
337340 */
338341 public void testSparseBucketsLongerPeriod () {
339- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
342+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
340343
341344 sendManyDataPoints (d , 10000 , 69000 , 1000 );
342345 sendManyDataPoints (d , 70000 , 129000 , 1200 );
@@ -374,7 +377,7 @@ private static Job createJob(TimeValue bucketSpan, TimeValue latency) {
374377 }
375378
376379 public void testFlushAfterZeroRecords () {
377- DataStreamDiagnostics d = new DataStreamDiagnostics (job );
380+ DataStreamDiagnostics d = new DataStreamDiagnostics (job , dataCounts );
378381 d .flush ();
379382 assertEquals (0 , d .getBucketCount ());
380383 }
0 commit comments