Skip to content

Commit

Permalink
Add get and search to watcher thread pool test
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Apr 17, 2024
1 parent 459b790 commit 448312e
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
package org.elasticsearch.xpack.watcher;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.indices.SystemIndexThreadPoolTestCase;
import org.elasticsearch.license.LicenseSettings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.store.MockFSIndexStore;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.watcher.transport.actions.QueryWatchesAction;
import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequestBuilder;
import org.elasticsearch.xpack.core.watcher.transport.actions.put.PutWatchRequestBuilder;
import org.elasticsearch.xpack.ilm.IndexLifecycle;
import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition;
Expand All @@ -28,6 +31,7 @@
import static org.elasticsearch.xpack.watcher.input.InputBuilders.noneInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.equalTo;

public class WatcherThreadPoolTests extends SystemIndexThreadPoolTestCase {

Expand Down Expand Up @@ -60,13 +64,29 @@ protected Collection<Class<? extends Plugin>> getMockPlugins() {

public void testWatcherThreadPools() {
runWithBlockedThreadPools(() -> {
var response = new PutWatchRequestBuilder(client(), "test-watch").setSource(
watchBuilder().trigger(schedule(interval("3s")))
.input(noneInput())
.condition(InternalAlwaysCondition.INSTANCE)
.addAction("indexer", indexAction("test-index"))
).get();
assertTrue(response.isCreated());
{
// write
var response = new PutWatchRequestBuilder(client(), "test-watch").setSource(
watchBuilder().trigger(schedule(interval("3m")))
.input(noneInput())
.condition(InternalAlwaysCondition.INSTANCE)
.addAction("indexer", indexAction("test-index"))
).get();
assertTrue(response.isCreated());
}

{
// get
var response = new GetWatchRequestBuilder(client()).setId("test-watch").get();
assertThat(response.getId(), equalTo("test-watch"));
}

{
// search
var request = new QueryWatchesAction.Request(null, null, new TermQueryBuilder("_id", "test-watch"), null, null);
var response = client().execute(QueryWatchesAction.INSTANCE, request).actionGet();
assertThat(response.getWatchTotalCount(), equalTo(1L));
}
});
}
}

0 comments on commit 448312e

Please sign in to comment.