Update smoke test watcher test suite with the changes in master branch.
Relates to #32299
This commit is contained in:
parent
8bdf654cc7
commit
53ac28e398
|
@ -167,6 +167,7 @@ final class WatcherIndexingListener implements IndexingOperationListener, Cluste
|
||||||
@Override
|
@Override
|
||||||
public Engine.Delete preDelete(ShardId shardId, Engine.Delete delete) {
|
public Engine.Delete preDelete(ShardId shardId, Engine.Delete delete) {
|
||||||
if (isWatchDocument(shardId.getIndexName())) {
|
if (isWatchDocument(shardId.getIndexName())) {
|
||||||
|
logger.debug("removing watch [{}] to trigger service via delete", delete.id());
|
||||||
triggerService.remove(delete.id());
|
triggerService.remove(delete.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,13 @@ package org.elasticsearch.smoketest;
|
||||||
|
|
||||||
import org.elasticsearch.client.Request;
|
import org.elasticsearch.client.Request;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
|
import org.elasticsearch.client.ResponseException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.SecureString;
|
import org.elasticsearch.common.settings.SecureString;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||||
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
||||||
import org.elasticsearch.xpack.test.rest.XPackRestTestConstants;
|
import org.elasticsearch.xpack.test.rest.XPackRestTestConstants;
|
||||||
|
@ -110,7 +112,7 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase {
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32299")
|
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32299")
|
||||||
public void testMonitorClusterHealth() throws Exception {
|
public void testMonitorClusterHealth() throws Exception {
|
||||||
String watchId = "cluster_health_watch";
|
final String watchId = "cluster_health_watch";
|
||||||
|
|
||||||
// get master publish address
|
// get master publish address
|
||||||
Response clusterStateResponse = adminClient().performRequest(new Request("GET", "/_cluster/state"));
|
Response clusterStateResponse = adminClient().performRequest(new Request("GET", "/_cluster/state"));
|
||||||
|
@ -124,7 +126,7 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase {
|
||||||
assertThat(address, is(notNullValue()));
|
assertThat(address, is(notNullValue()));
|
||||||
String[] splitAddress = address.split(":", 2);
|
String[] splitAddress = address.split(":", 2);
|
||||||
String host = splitAddress[0];
|
String host = splitAddress[0];
|
||||||
int port = Integer.valueOf(splitAddress[1]);
|
int port = Integer.parseInt(splitAddress[1]);
|
||||||
|
|
||||||
// put watch
|
// put watch
|
||||||
try (XContentBuilder builder = jsonBuilder()) {
|
try (XContentBuilder builder = jsonBuilder()) {
|
||||||
|
@ -156,11 +158,17 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase {
|
||||||
|
|
||||||
// check watch history
|
// check watch history
|
||||||
ObjectPath objectPath = getWatchHistoryEntry(watchId);
|
ObjectPath objectPath = getWatchHistoryEntry(watchId);
|
||||||
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
|
Boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
|
||||||
assertThat(conditionMet, is(true));
|
String historyEntriesAsString = Strings.toString(objectPath.toXContentBuilder(XContentType.JSON.xContent()));
|
||||||
|
assertThat("condition not met in response [" + historyEntriesAsString + "]", conditionMet, is(true));
|
||||||
|
|
||||||
deleteWatch(watchId);
|
deleteWatch(watchId);
|
||||||
assertWatchCount(0);
|
// Wrap inside an assertBusy(...), because watch may execute just after being deleted,
|
||||||
|
// This tries to re-add the watch which fails, because of version conflict,
|
||||||
|
// but for a moment the watch count from watcher stats api may be incorrect.
|
||||||
|
// (via WatcherIndexingListener#preIndex)
|
||||||
|
// The WatcherIndexingListener#postIndex() detects this version conflict and corrects the watch count.
|
||||||
|
assertBusy(() -> assertWatchCount(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexWatch(String watchId, XContentBuilder builder) throws Exception {
|
private void indexWatch(String watchId, XContentBuilder builder) throws Exception {
|
||||||
|
@ -182,16 +190,54 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase {
|
||||||
private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
|
private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
|
||||||
final AtomicReference<ObjectPath> objectPathReference = new AtomicReference<>();
|
final AtomicReference<ObjectPath> objectPathReference = new AtomicReference<>();
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
client().performRequest(new Request("POST", "/.watcher-history-*/_refresh"));
|
try {
|
||||||
|
client().performRequest(new Request("POST", "/.watcher-history-*/_refresh"));
|
||||||
|
} catch (ResponseException e) {
|
||||||
|
final String err = "Failed to perform refresh of watcher history";
|
||||||
|
logger.error(err, e);
|
||||||
|
throw new AssertionError(err, e);
|
||||||
|
}
|
||||||
|
|
||||||
try (XContentBuilder builder = jsonBuilder()) {
|
try (XContentBuilder builder = jsonBuilder()) {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.startObject("query").startObject("bool").startArray("must");
|
{
|
||||||
builder.startObject().startObject("term").startObject("watch_id").field("value", watchId).endObject().endObject()
|
builder.startObject("query");
|
||||||
.endObject();
|
{
|
||||||
builder.endArray().endObject().endObject();
|
builder.startObject("bool");
|
||||||
builder.startArray("sort").startObject().startObject("trigger_event.triggered_time").field("order", "desc").endObject()
|
builder.startArray("must");
|
||||||
.endObject().endArray();
|
builder.startObject();
|
||||||
|
{
|
||||||
|
builder.startObject("term");
|
||||||
|
builder.startObject("watch_id");
|
||||||
|
builder.field("value", watchId);
|
||||||
|
builder.endObject();
|
||||||
|
builder.endObject();
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
builder.startObject();
|
||||||
|
{
|
||||||
|
builder.startObject("term");
|
||||||
|
builder.startObject("state");
|
||||||
|
builder.field("value", "executed");
|
||||||
|
builder.endObject();
|
||||||
|
builder.endObject();
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
builder.endArray();
|
||||||
|
builder.endObject();
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
builder.startArray("sort");
|
||||||
|
builder.startObject();
|
||||||
|
{
|
||||||
|
|
||||||
|
builder.startObject("result.execution_time");
|
||||||
|
builder.field("order", "desc");
|
||||||
|
builder.endObject();
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
builder.endArray();
|
||||||
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
Request searchRequest = new Request("POST", "/.watcher-history-*/_search");
|
Request searchRequest = new Request("POST", "/.watcher-history-*/_search");
|
||||||
|
@ -204,6 +250,10 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase {
|
||||||
String watchid = objectPath.evaluate("hits.hits.0._source.watch_id");
|
String watchid = objectPath.evaluate("hits.hits.0._source.watch_id");
|
||||||
assertThat(watchid, is(watchId));
|
assertThat(watchid, is(watchId));
|
||||||
objectPathReference.set(objectPath);
|
objectPathReference.set(objectPath);
|
||||||
|
} catch (ResponseException e) {
|
||||||
|
final String err = "Failed to perform search of watcher history";
|
||||||
|
logger.error(err, e);
|
||||||
|
throw new AssertionError(err, e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return objectPathReference.get();
|
return objectPathReference.get();
|
||||||
|
|
Loading…
Reference in New Issue