[TEST] Stabilise UpdateInterimResultsIT

Depending on the random numbers fed to the analytics,
it is possible that the first planted anomaly ends up
in a different bucket due to the overlapping buckets feature.
Then that may result to a single interim bucket being available
due to overlapping buckets blocking the other interim bucket
from being considered.

I am removing the initial anomaly from the test as it is not useful
and it makes the test unstable.

relates elastic/x-pack-elasticsearch#1897

Original commit: elastic/x-pack-elasticsearch@aca7870708
This commit is contained in:
Dimitrios Athanasiou 2017-06-30 17:08:42 +01:00
parent e7e24c453c
commit 8264cbf72f
1 changed files with 5 additions and 9 deletions

View File

@ -16,9 +16,7 @@ import org.elasticsearch.xpack.ml.job.results.Bucket;
import org.junit.After; import org.junit.After;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -57,16 +55,14 @@ public class UpdateInterimResultsIT extends MlNativeAutodetectIntegTestCase {
openJob(job.getId()); openJob(job.getId());
time = 1400000000; time = 1400000000;
Map<Long, Integer> anomalies = new HashMap<>();
anomalies.put(1400021500L, 14);
// push some data, flush job, verify no interim results // push some data, flush job, verify no interim results
assertThat(postData(job.getId(), createData(50, anomalies)).getProcessedRecordCount(), equalTo(50L)); assertThat(postData(job.getId(), createData(50)).getProcessedRecordCount(), equalTo(50L));
flushJob(job.getId(), false); flushJob(job.getId(), false);
assertThat(getInterimResults(job.getId()).isEmpty(), is(true)); assertThat(getInterimResults(job.getId()).isEmpty(), is(true));
// push some more data, flush job, verify no interim results // push some more data, flush job, verify no interim results
assertThat(postData(job.getId(), createData(30, anomalies)).getProcessedRecordCount(), equalTo(30L)); assertThat(postData(job.getId(), createData(30)).getProcessedRecordCount(), equalTo(30L));
flushJob(job.getId(), false); flushJob(job.getId(), false);
assertThat(getInterimResults(job.getId()).isEmpty(), is(true)); assertThat(getInterimResults(job.getId()).isEmpty(), is(true));
assertThat(time, equalTo(1400040000L)); assertThat(time, equalTo(1400040000L));
@ -101,7 +97,7 @@ public class UpdateInterimResultsIT extends MlNativeAutodetectIntegTestCase {
// push rest of data, close, verify no interim results // push rest of data, close, verify no interim results
time += BUCKET_SPAN_SECONDS; time += BUCKET_SPAN_SECONDS;
assertThat(postData(job.getId(), createData(30, anomalies)).getProcessedRecordCount(), equalTo(30L)); assertThat(postData(job.getId(), createData(30)).getProcessedRecordCount(), equalTo(30L));
closeJob(job.getId()); closeJob(job.getId());
assertThat(getInterimResults(job.getId()).isEmpty(), is(true)); assertThat(getInterimResults(job.getId()).isEmpty(), is(true));
@ -114,10 +110,10 @@ public class UpdateInterimResultsIT extends MlNativeAutodetectIntegTestCase {
assertThat(bucket.get(0).getRecords().get(0).getActual().get(0), equalTo(14.0)); assertThat(bucket.get(0).getRecords().get(0).getActual().get(0), equalTo(14.0));
} }
private String createData(int halfBuckets, Map<Long, Integer> timeToValueMap) { private String createData(int halfBuckets) {
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
for (int i = 0; i < halfBuckets; i++) { for (int i = 0; i < halfBuckets; i++) {
int value = timeToValueMap.getOrDefault(time, randomIntBetween(1, 3)); int value = randomIntBetween(1, 3);
data.append("{\"time\":").append(time).append(", \"value\":").append(value).append("}\n"); data.append("{\"time\":").append(time).append(", \"value\":").append(value).append("}\n");
time += BUCKET_SPAN_SECONDS / 2; time += BUCKET_SPAN_SECONDS / 2;
} }