Test: changed default node settings

Core: AlertManager sets itself now

Original commit: elastic/x-pack-elasticsearch@fad2318528
This commit is contained in:
Martijn van Groningen 2014-11-07 21:47:02 +01:00
parent a6bb3b533f
commit b11f0bf6df
4 changed files with 15 additions and 23 deletions

View File

@ -38,7 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
// The KeyedLock make sure that we only lock on the same alert, but not on different alerts.
public class AlertManager extends AbstractComponent {
private AlertScheduler scheduler;
private final AlertScheduler scheduler;
private final AlertsStore alertsStore;
private final TriggerManager triggerManager;
private final ClusterService clusterService;
@ -48,9 +48,12 @@ public class AlertManager extends AbstractComponent {
@Inject
public AlertManager(Settings settings, ClusterService clusterService, AlertsStore alertsStore,
IndicesService indicesService, TriggerManager triggerManager, AlertActionManager actionManager, AlertActionRegistry actionRegistry) {
public AlertManager(Settings settings, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore,
IndicesService indicesService, TriggerManager triggerManager, AlertActionManager actionManager,
AlertActionRegistry actionRegistry) {
super(settings);
this.scheduler = scheduler;
this.scheduler.setAlertManager(this);
this.alertsStore = alertsStore;
this.clusterService = clusterService;
this.triggerManager = triggerManager;
@ -68,10 +71,6 @@ public class AlertManager extends AbstractComponent {
});
}
public void setAlertScheduler(AlertScheduler scheduler){
this.scheduler = scheduler;
}
public DeleteResponse deleteAlert(String name) throws InterruptedException, ExecutionException {
ensureStarted();
if (alertsStore.hasAlert(name)) {

View File

@ -19,13 +19,15 @@ import org.quartz.simpl.SimpleJobFactory;
public class AlertScheduler extends AbstractComponent {
private volatile Scheduler scheduler;
private final AlertManager alertManager;
private AlertManager alertManager;
@Inject
public AlertScheduler(Settings settings, AlertManager alertManager) {
public AlertScheduler(Settings settings) {
super(settings);
}
public void setAlertManager(AlertManager alertManager){
this.alertManager = alertManager;
alertManager.setAlertScheduler(this);
}
public void start() {

View File

@ -42,11 +42,8 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest
return ImmutableSettings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("scroll.size", randomIntBetween(1, 100))
.put("plugin.mandatory", "alerts")
.put("plugin.types", AlertsPlugin.class.getName())
.put("node.mode", "network")
.put("http.enabled", true)
.put("plugins.load_classpath_plugins", false)
.build();
}

View File

@ -6,26 +6,19 @@
package org.elasticsearch.alerts;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.alerts.actions.AlertAction;
import org.elasticsearch.alerts.client.AlertsClientInterface;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.joda.time.DateTime;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import java.util.ArrayList;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.is;
/**
*/
@ -54,9 +47,10 @@ public class BasicAlertingTest extends AbstractAlertingTests {
client().prepareIndex("my-index", "my-type").setSource("field", "value").get();
SearchRequest searchRequest = new SearchRequest("my-index").source(searchSource().query(matchAllQuery()));
BytesReference alertSource = createAlertSource("0/5 * * * * ? *", searchRequest, "hits.total == 1");
alertsClient.prepareIndexAlert("my-first-alert")
IndexAlertResponse indexResponse = alertsClient.prepareIndexAlert("my-first-alert")
.setAlertSource(alertSource)
.get();
assertThat(indexResponse.indexResponse().isCreated(), is(true));
DeleteAlertRequest deleteAlertRequest = new DeleteAlertRequest("my-first-alert");
DeleteAlertResponse deleteAlertResponse = alertsClient.deleteAlert(deleteAlertRequest).actionGet();