[ML] Add datafeed run time fields integration test (#62535) (#62538)

This commit is contained in:
David Kyle 2020-09-17 13:41:07 +01:00 committed by GitHub
parent d3bdff6bbf
commit 417ce9396d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 5 deletions

View File

@ -33,7 +33,6 @@ import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@ -128,6 +127,11 @@ public class DatafeedJobsRestIT extends ESRestTestCase {
+ " \"keyword\":{\"type\":\"keyword\"}"
+ " }"
+ " },"
+ " \"airline_lowercase_rt\": { "
+ " \"type\":\"runtime\","
+ " \"runtime_type\": \"keyword\","
+ " \"script\" : { \"source\": \"emit(params._source.airline.toLowerCase())\" }"
+ " },"
+ " \"responsetime\": { \"type\":\"float\"}"
+ " }"
+ " }"
@ -293,6 +297,13 @@ public class DatafeedJobsRestIT extends ESRestTestCase {
.execute();
}
public void testLookbackOnlyWithRuntimeFields() throws Exception {
new LookbackOnlyTestHelper("test-lookback-only-with-runtime-fields", "airline-data")
.setAirlineVariant("airline_lowercase_rt")
.setShouldSucceedProcessing(true)
.execute();
}
public void testLookbackonlyWithNestedFields() throws Exception {
String jobId = "test-lookback-only-with-nested-fields";
Request createJobRequest = new Request("PUT", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId);
@ -462,7 +473,7 @@ public class DatafeedJobsRestIT extends ESRestTestCase {
public void testLookbackOnlyGivenEmptyIndex() throws Exception {
new LookbackOnlyTestHelper("test-lookback-only-given-empty-index", "airline-data-empty")
.setShouldSucceedInput(false).setShouldSucceedProcessing(false).execute();
.setShouldSucceedInput(false).setShouldSucceedProcessing(false).execute();
}
public void testInsufficientSearchPrivilegesOnPut() throws Exception {
@ -1083,9 +1094,9 @@ public class DatafeedJobsRestIT extends ESRestTestCase {
}
private class LookbackOnlyTestHelper {
private String jobId;
private final String jobId;
private final String dataIndex;
private String airlineVariant;
private String dataIndex;
private String scriptedFields;
private boolean shouldSucceedInput;
private boolean shouldSucceedProcessing;
@ -1120,7 +1131,8 @@ public class DatafeedJobsRestIT extends ESRestTestCase {
}
public void execute() throws Exception {
createJob(jobId, airlineVariant);
Response jobResponse = createJob(jobId, airlineVariant);
assertThat(jobResponse.getStatusLine().getStatusCode(), equalTo(200));
String datafeedId = "datafeed-" + jobId;
new DatafeedBuilder(datafeedId, jobId, dataIndex).setScriptedFields(scriptedFields).build();
openJob(client(), jobId);