mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Improve watcher smoke test stability
port test re-factorings from elastic/x-pack-elasticsearch#4240 to improve smoke test stability relates elastic/x-pack-elasticsearch#4311 elastic/x-pack-elasticsearch#3812 Original commit: elastic/x-pack-elasticsearch@d5fb16eef4
This commit is contained in:
parent
9eaec0c808
commit
81a3f367f8
@ -7,6 +7,7 @@ package org.elasticsearch.smoketest;
|
|||||||
|
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.SecureString;
|
import org.elasticsearch.common.settings.SecureString;
|
||||||
@ -26,6 +27,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||||
import static org.hamcrest.Matchers.hasEntry;
|
import static org.hamcrest.Matchers.hasEntry;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
@ -50,20 +52,37 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
|
|||||||
|
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
try {
|
try {
|
||||||
adminClient().performRequest("POST", "_xpack/watcher/_start");
|
|
||||||
|
|
||||||
for (String template : WatcherIndexTemplateRegistryField.TEMPLATE_NAMES) {
|
|
||||||
assertOK(adminClient().performRequest("HEAD", "_template/" + template));
|
|
||||||
}
|
|
||||||
|
|
||||||
Response statsResponse = adminClient().performRequest("GET", "_xpack/watcher/stats");
|
Response statsResponse = adminClient().performRequest("GET", "_xpack/watcher/stats");
|
||||||
ObjectPath objectPath = ObjectPath.createFromResponse(statsResponse);
|
ObjectPath objectPath = ObjectPath.createFromResponse(statsResponse);
|
||||||
String state = objectPath.evaluate("stats.0.watcher_state");
|
String state = objectPath.evaluate("stats.0.watcher_state");
|
||||||
assertThat(state, is("started"));
|
|
||||||
|
switch (state) {
|
||||||
|
case "stopped":
|
||||||
|
Response startResponse = adminClient().performRequest("POST", "_xpack/watcher/_start");
|
||||||
|
assertOK(startResponse);
|
||||||
|
String body = EntityUtils.toString(startResponse.getEntity());
|
||||||
|
assertThat(body, containsString("\"acknowledged\":true"));
|
||||||
|
break;
|
||||||
|
case "stopping":
|
||||||
|
throw new AssertionError("waiting until stopping state reached stopped state to start again");
|
||||||
|
case "starting":
|
||||||
|
throw new AssertionError("waiting until starting state reached started state");
|
||||||
|
case "started":
|
||||||
|
// all good here, we are done
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError("unknown state[" + state + "]");
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assertBusy(() -> {
|
||||||
|
for (String template : WatcherIndexTemplateRegistryField.TEMPLATE_NAMES) {
|
||||||
|
assertOK(adminClient().performRequest("HEAD", "_template/" + template));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -73,11 +92,27 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
|
|||||||
|
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
try {
|
try {
|
||||||
adminClient().performRequest("POST", "_xpack/watcher/_stop", Collections.emptyMap());
|
|
||||||
Response statsResponse = adminClient().performRequest("GET", "_xpack/watcher/stats");
|
Response statsResponse = adminClient().performRequest("GET", "_xpack/watcher/stats");
|
||||||
ObjectPath objectPath = ObjectPath.createFromResponse(statsResponse);
|
ObjectPath objectPath = ObjectPath.createFromResponse(statsResponse);
|
||||||
String state = objectPath.evaluate("stats.0.watcher_state");
|
String state = objectPath.evaluate("stats.0.watcher_state");
|
||||||
assertThat(state, is("stopped"));
|
|
||||||
|
switch (state) {
|
||||||
|
case "stopped":
|
||||||
|
// all good here, we are done
|
||||||
|
break;
|
||||||
|
case "stopping":
|
||||||
|
throw new AssertionError("waiting until stopping state reached stopped state");
|
||||||
|
case "starting":
|
||||||
|
throw new AssertionError("waiting until starting state reached started state to stop");
|
||||||
|
case "started":
|
||||||
|
Response stopResponse = adminClient().performRequest("POST", "_xpack/watcher/_stop", Collections.emptyMap());
|
||||||
|
assertOK(stopResponse);
|
||||||
|
String body = EntityUtils.toString(stopResponse.getEntity());
|
||||||
|
assertThat(body, containsString("\"acknowledged\":true"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError("unknown state[" + state + "]");
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user