From 713327cee5bf914eed76f488339034b596f84feb Mon Sep 17 00:00:00 2001 From: Brian Murphy Date: Wed, 26 Nov 2014 14:36:34 +0000 Subject: [PATCH] TEST : Add bootstrap test to boot strap different history indices. Original commit: elastic/x-pack-elasticsearch@72c36f6d4dfdf0842f869a042b90aa96a57ec26a --- .../elasticsearch/alerts/BootStrapTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java index 17b14567f5b..4d5c91b5bf0 100644 --- a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java +++ b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java @@ -22,6 +22,7 @@ import org.elasticsearch.script.ScriptService; import org.junit.Test; import java.util.ArrayList; +import java.util.concurrent.TimeUnit; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; @@ -97,4 +98,50 @@ public class BootStrapTest extends AbstractAlertingTests { assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(1L)); } + @Test + public void testBootStrapManyHistoryIndices() throws Exception { + int numberOfAlertHistoryEntriesPerIndex = randomIntBetween(5,10); + int numberOfAlertHistoryIndices = randomIntBetween(2,8); + DateTime now = new DateTime(); + SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value"))); + + for (int i=0; i(), + "0 0/5 * * * ? *", + new DateTime(), + 0, + true, + new TimeValue(0), + AlertAckState.NOT_ACKABLE); + AlertActionEntry entry = new AlertActionEntry(alert, historyIndexDate, historyIndexDate, AlertActionState.SEARCH_NEEDED); + IndexResponse indexResponse = client().prepareIndex(actionHistoryIndex, AlertActionManager.ALERT_HISTORY_TYPE, entry.getId()) + .setConsistencyLevel(WriteConsistencyLevel.ALL) + .setSource(XContentFactory.jsonBuilder().value(entry)) + .get(); + assertTrue(indexResponse.isCreated()); + } + client().admin().indices().prepareRefresh(actionHistoryIndex).get(); + } + + stopAlerting(); + startAlerting(); + AlertsStatsResponse response = alertClient().prepareAlertsStats().get(); + + assertTrue(response.isAlertActionManagerStarted()); + assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L)); + assertThat(response.getAlertActionManagerLargestQueueSize(), + equalTo((long)(numberOfAlertHistoryEntriesPerIndex*numberOfAlertHistoryIndices))); + + } + + }