test: move java rest test to yaml rest test.
These test are just checking response / status code. It is cleaner to have these tests as yaml tests. Original commit: elastic/x-pack-elasticsearch@61c323059e
This commit is contained in:
parent
9f73f047eb
commit
d15933ac32
|
@ -31,52 +31,6 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
|
||||
public class ScheduledJobIT extends ESRestTestCase {
|
||||
|
||||
public void testStartJobScheduler_GivenMissingJob() {
|
||||
ResponseException e = expectThrows(ResponseException.class,
|
||||
() -> client().performRequest("post", PrelertPlugin.BASE_PATH + "schedulers/invalid-job/_start"));
|
||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
|
||||
}
|
||||
|
||||
public void testStartJobScheduler_GivenNonScheduledJob() throws Exception {
|
||||
String jobId = "_id1";
|
||||
createNonScheduledJob(jobId);
|
||||
|
||||
ResponseException e = expectThrows(ResponseException.class,
|
||||
() -> client().performRequest("post", PrelertPlugin.BASE_PATH + "schedulers/" + jobId + "/_start"));
|
||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400));
|
||||
String responseAsString = responseEntityToString(e.getResponse());
|
||||
assertThat(responseAsString, containsString("\"reason\":\"job [" + jobId + "] is not a scheduled job\""));
|
||||
}
|
||||
|
||||
public void testStartJobScheduler_jobNotOpened() throws Exception {
|
||||
String jobId = "_id1";
|
||||
createScheduledJob(jobId);
|
||||
|
||||
ResponseException e = expectThrows(ResponseException.class,
|
||||
() -> client().performRequest("post", PrelertPlugin.BASE_PATH + "schedulers/" + jobId + "/_start"));
|
||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(409));
|
||||
String responseAsString = responseEntityToString(e.getResponse());
|
||||
assertThat(responseAsString, containsString("\"reason\":\"cannot start scheduler, expected job status [OPENED], " +
|
||||
"but got [CLOSED]\""));
|
||||
}
|
||||
|
||||
public void testStartJobScheduler_schedulerAlreadyStarted() throws Exception {
|
||||
String jobId = "_id1";
|
||||
createScheduledJob(jobId);
|
||||
openJob(client(), jobId);
|
||||
Response startSchedulerRequest = client().performRequest("post",
|
||||
PrelertPlugin.BASE_PATH + "schedulers/" + jobId + "/_start?start=2016-06-01T00:00:00Z");
|
||||
assertThat(startSchedulerRequest.getStatusLine().getStatusCode(), equalTo(200));
|
||||
assertThat(responseEntityToString(startSchedulerRequest), containsString("{\"task\":\""));
|
||||
|
||||
ResponseException e = expectThrows(ResponseException.class,
|
||||
() -> client().performRequest("post", PrelertPlugin.BASE_PATH + "schedulers/" + jobId + "/_start"));
|
||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(409));
|
||||
String responseAsString = responseEntityToString(e.getResponse());
|
||||
assertThat(responseAsString, containsString("\"reason\":\"scheduler already started, expected scheduler status " +
|
||||
"[STOPPED], but got [STARTED]\""));
|
||||
}
|
||||
|
||||
public void testStartJobScheduler_GivenLookbackOnly() throws Exception {
|
||||
String jobId = "_id2";
|
||||
createAirlineDataIndex();
|
||||
|
@ -152,17 +106,6 @@ public class ScheduledJobIT extends ESRestTestCase {
|
|||
client().performRequest("post", "airline-data/_refresh");
|
||||
}
|
||||
|
||||
private Response createNonScheduledJob(String id) throws Exception {
|
||||
String job = "{\n" + " \"job_id\":\"" + id + "\",\n" + " \"description\":\"Analysis of response time by airline\",\n"
|
||||
+ " \"analysis_config\" : {\n" + " \"bucket_span\":3600,\n"
|
||||
+ " \"detectors\" :[{\"function\":\"mean\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"}]\n"
|
||||
+ " },\n" + " \"data_description\" : {\n" + " \"field_delimiter\":\",\",\n" + " " +
|
||||
"\"time_field\":\"time\",\n"
|
||||
+ " \"time_format\":\"yyyy-MM-dd'T'HH:mm:ssX\"\n" + " }\n" + "}";
|
||||
|
||||
return client().performRequest("put", PrelertPlugin.BASE_PATH + "anomaly_detectors", Collections.emptyMap(), new StringEntity(job));
|
||||
}
|
||||
|
||||
private Response createScheduledJob(String id) throws Exception {
|
||||
HttpHost httpHost = getClusterHosts().get(0);
|
||||
logger.info("Http host = " + httpHost.toURI());
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
setup:
|
||||
- do:
|
||||
xpack.prelert.put_job:
|
||||
body: >
|
||||
{
|
||||
"job_id":"non-scheduled-job",
|
||||
"description":"Analysis of response time by airline",
|
||||
"analysis_config" : {
|
||||
"bucket_span":3600,
|
||||
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||
},
|
||||
"data_description" : {
|
||||
"format":"JSON",
|
||||
"time_field":"time",
|
||||
"time_format":"epoch"
|
||||
}
|
||||
}
|
||||
- do:
|
||||
xpack.prelert.put_job:
|
||||
body: >
|
||||
{
|
||||
"job_id":"scheduled-job",
|
||||
"description":"Analysis of response time by airline",
|
||||
"analysis_config" : {
|
||||
"bucket_span":3600,
|
||||
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||
},
|
||||
"data_description" : {
|
||||
"format":"ELASTICSEARCH",
|
||||
"time_field":"time",
|
||||
"time_format":"epoch"
|
||||
},
|
||||
"scheduler_config" : {
|
||||
"indexes" : "airline-data",
|
||||
"types" : "response"
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
"Test start and stop scheduler happy path":
|
||||
- do:
|
||||
xpack.prelert.open_job:
|
||||
job_id: "scheduled-job"
|
||||
- do:
|
||||
xpack.prelert.start_job_scheduler:
|
||||
"job_id": "scheduled-job"
|
||||
"start": 0
|
||||
- do:
|
||||
xpack.prelert.stop_job_scheduler:
|
||||
"job_id": "scheduled-job"
|
||||
|
||||
|
||||
---
|
||||
"Test start non existing job":
|
||||
- do:
|
||||
catch: missing
|
||||
xpack.prelert.start_job_scheduler:
|
||||
"job_id": "non-existing-job"
|
||||
"start": 0
|
||||
|
||||
---
|
||||
"Test start non scheduled job":
|
||||
- do:
|
||||
catch: request
|
||||
xpack.prelert.start_job_scheduler:
|
||||
"job_id": "non-scheduled-job"
|
||||
"start": 0
|
||||
|
||||
---
|
||||
"Test start scheduled job, but not open":
|
||||
- do:
|
||||
catch: conflict
|
||||
xpack.prelert.start_job_scheduler:
|
||||
"job_id": "scheduled-job"
|
||||
"start": 0
|
||||
|
||||
---
|
||||
"Test start already started scheduled job":
|
||||
- do:
|
||||
xpack.prelert.open_job:
|
||||
job_id: "scheduled-job"
|
||||
- do:
|
||||
xpack.prelert.start_job_scheduler:
|
||||
"job_id": "scheduled-job"
|
||||
"start": 0
|
||||
- do:
|
||||
catch: conflict
|
||||
xpack.prelert.start_job_scheduler:
|
||||
"job_id": "scheduled-job"
|
||||
"start": 0
|
Loading…
Reference in New Issue