Skip to content

Commit 6fcd606

Browse files
authored
[ML] Get ForecastRequestStats doc in RestoreModelSnapshotIT (#31973)
1 parent edf83c1 commit 6fcd606

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

x-pack/qa/ml-native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.xpack.ml.integration;
77

88
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
9+
import org.elasticsearch.action.get.GetResponse;
910
import org.elasticsearch.action.search.SearchResponse;
1011
import org.elasticsearch.client.Client;
1112
import org.elasticsearch.cluster.ClusterModule;
@@ -342,21 +343,17 @@ protected void waitForecastToFinish(String jobId, String forecastId) throws Exce
342343
}
343344

344345
protected ForecastRequestStats getForecastStats(String jobId, String forecastId) {
345-
SearchResponse searchResponse = client().prepareSearch(AnomalyDetectorsIndex.jobResultsAliasedName(jobId))
346-
.setQuery(QueryBuilders.boolQuery()
347-
.filter(QueryBuilders.termQuery(Result.RESULT_TYPE.getPreferredName(), ForecastRequestStats.RESULT_TYPE_VALUE))
348-
.filter(QueryBuilders.termQuery(Job.ID.getPreferredName(), jobId))
349-
.filter(QueryBuilders.termQuery(ForecastRequestStats.FORECAST_ID.getPreferredName(), forecastId)))
346+
GetResponse getResponse = client().prepareGet()
347+
.setIndex(AnomalyDetectorsIndex.jobResultsAliasedName(jobId))
348+
.setId(ForecastRequestStats.documentId(jobId, forecastId))
350349
.execute().actionGet();
351-
SearchHits hits = searchResponse.getHits();
352-
if (hits.getTotalHits() == 0) {
350+
351+
if (getResponse.isExists() == false) {
353352
return null;
354353
}
355-
assertThat(hits.getTotalHits(), equalTo(1L));
356-
try {
357-
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
354+
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
358355
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
359-
hits.getHits()[0].getSourceRef().streamInput());
356+
getResponse.getSourceAsBytesRef().streamInput())) {
360357
return ForecastRequestStats.STRICT_PARSER.apply(parser, null);
361358
} catch (IOException e) {
362359
throw new IllegalStateException(e);

x-pack/qa/ml-native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/RestoreModelSnapshotIT.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import java.util.Map;
2424
import java.util.stream.Collectors;
2525

26+
import static org.hamcrest.Matchers.anyOf;
27+
import static org.hamcrest.Matchers.empty;
2628
import static org.hamcrest.Matchers.equalTo;
29+
import static org.hamcrest.Matchers.greaterThan;
30+
import static org.hamcrest.Matchers.nullValue;
2731

2832
/**
2933
* This test aims to catch regressions where,
@@ -69,7 +73,9 @@ public void test() throws Exception {
6973
String forecastId = forecast(job.getId(), TimeValue.timeValueHours(3), null);
7074
waitForecastToFinish(job.getId(), forecastId);
7175
ForecastRequestStats forecastStats = getForecastStats(job.getId(), forecastId);
72-
assertThat(forecastStats.getStatus(), equalTo(ForecastRequestStats.ForecastRequestStatus.FINISHED));
76+
assertThat(forecastStats.getMessages(), anyOf(nullValue(), empty()));
77+
assertThat(forecastStats.getMemoryUsage(), greaterThan(0L));
78+
assertEquals(forecastStats.getRecordCount(), 3L);
7379

7480
closeJob(job.getId());
7581

0 commit comments

Comments
 (0)