mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-03 09:29:11 +00:00
Test: Fixed and cleanup bootstrap test
Original commit: elastic/x-pack-elasticsearch@7455bd8c00
This commit is contained in:
parent
19622d4f0b
commit
c2e4fe375d
@ -141,13 +141,13 @@ public class AlertActionManager extends AbstractComponent {
|
||||
public void loadQueue() {
|
||||
client.admin().indices().refresh(new RefreshRequest(ALERT_HISTORY_INDEX)).actionGet();
|
||||
|
||||
SearchResponse response = client.prepareSearch()
|
||||
SearchResponse response = client.prepareSearch(ALERT_HISTORY_INDEX)
|
||||
.setQuery(QueryBuilders.termQuery(AlertActionState.FIELD_NAME, AlertActionState.SEARCH_NEEDED.toString()))
|
||||
.setSearchType(SearchType.SCAN)
|
||||
.setScroll(scrollTimeout)
|
||||
.setSize(scrollSize)
|
||||
.setTypes(ALERT_HISTORY_TYPE)
|
||||
.setIndices(ALERT_HISTORY_INDEX).get();
|
||||
.get();
|
||||
try {
|
||||
if (response.getHits().getTotalHits() > 0) {
|
||||
response = client.prepareSearchScroll(response.getScrollId()).setScroll(scrollTimeout).get();
|
||||
|
@ -6,7 +6,7 @@
|
||||
package org.elasticsearch.alerts;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.WriteConsistencyLevel;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.alerts.actions.AlertAction;
|
||||
@ -26,7 +26,6 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
@ -35,30 +34,21 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numClientNodes = 0, transportClientRatio = 0, numDataNodes = 3)
|
||||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE, numClientNodes = 0, transportClientRatio = 0)
|
||||
public class BootStrapTest extends AbstractAlertingTests {
|
||||
|
||||
@Test
|
||||
public void testBootStrapAlerts() throws Exception {
|
||||
ensureGreen();
|
||||
ensureAlertingStarted();
|
||||
|
||||
SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
|
||||
BytesReference alertSource = createAlertSource("0 0/5 * * * ? *", searchRequest, "hits.total == 1");
|
||||
alertClient().prepareIndexAlert("my-first-alert")
|
||||
.setAlertSource(alertSource)
|
||||
client().prepareIndex(AlertsStore.ALERT_INDEX, AlertsStore.ALERT_TYPE, "my-first-alert")
|
||||
.setSource(alertSource)
|
||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||
.get();
|
||||
|
||||
AlertsStatsRequest alertsStatsRequest = alertClient().prepareAlertsStats().request();
|
||||
AlertsStatsResponse response = alertClient().alertsStats(alertsStatsRequest).actionGet();
|
||||
|
||||
assertTrue(response.isAlertActionManagerStarted());
|
||||
assertTrue(response.isAlertManagerStarted());
|
||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L));
|
||||
|
||||
refresh();
|
||||
|
||||
String oldMaster = internalTestCluster().getMasterName();
|
||||
|
||||
try {
|
||||
internalTestCluster().stopCurrentMasterNode();
|
||||
} catch (IOException ioe) {
|
||||
@ -70,12 +60,11 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||
Thread.sleep(maxTime.getMillis());
|
||||
|
||||
String newMaster = internalTestCluster().getMasterName();
|
||||
|
||||
assertFalse(newMaster.equals(oldMaster));
|
||||
logger.info("Switched master from [{}] to [{}]",oldMaster,newMaster);
|
||||
|
||||
alertsStatsRequest = alertClient().prepareAlertsStats().request();
|
||||
response = alertClient().alertsStats(alertsStatsRequest).actionGet();
|
||||
AlertsStatsRequest alertsStatsRequest = alertClient().prepareAlertsStats().request();
|
||||
AlertsStatsResponse response = alertClient().alertsStats(alertsStatsRequest).actionGet();
|
||||
|
||||
assertTrue(response.isAlertActionManagerStarted());
|
||||
assertTrue(response.isAlertManagerStarted());
|
||||
@ -85,7 +74,8 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||
|
||||
@Test
|
||||
public void testBootStrapHistory() throws Exception {
|
||||
ensureGreen();
|
||||
ensureAlertingStarted();
|
||||
internalTestCluster().ensureAtLeastNumDataNodes(2);
|
||||
|
||||
SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
|
||||
AlertsStatsRequest alertsStatsRequest = alertClient().prepareAlertsStats().request();
|
||||
@ -104,31 +94,14 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||
0,
|
||||
true );
|
||||
|
||||
AlertActionEntry entry =
|
||||
new AlertActionEntry(alert,
|
||||
new DateTime(),
|
||||
new DateTime(),
|
||||
AlertActionState.SEARCH_NEEDED);
|
||||
|
||||
IndexResponse indexResponse = client().prepareIndex().setIndex(AlertActionManager.ALERT_HISTORY_INDEX).setType(AlertActionManager.ALERT_HISTORY_TYPE).setId(entry.getId())
|
||||
AlertActionEntry entry = new AlertActionEntry(alert, new DateTime(), new DateTime(), AlertActionState.SEARCH_NEEDED);
|
||||
IndexResponse indexResponse = client().prepareIndex(AlertActionManager.ALERT_HISTORY_INDEX, AlertActionManager.ALERT_HISTORY_TYPE, entry.getId())
|
||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||
.setSource(XContentFactory.jsonBuilder().value(entry))
|
||||
.get();
|
||||
|
||||
assertTrue(indexResponse.isCreated());
|
||||
|
||||
GetResponse getResponse = client().prepareGet(AlertActionManager.ALERT_HISTORY_INDEX, AlertActionManager.ALERT_HISTORY_TYPE, entry.getId()).get();
|
||||
assertTrue(getResponse.isExists());
|
||||
assertEquals(getResponse.getId(), entry.getId());
|
||||
logger.info("Successfully indexed [{}]", entry.getId());
|
||||
|
||||
Map<String,Object> responseMap = getResponse.getSourceAsMap();
|
||||
|
||||
logger.info("State [{}]", responseMap.get(AlertActionState.FIELD_NAME) );
|
||||
|
||||
//client().admin().indices().prepareRefresh(AlertActionManager.ALERT_HISTORY_INDEX).get();
|
||||
|
||||
String oldMaster = internalTestCluster().getMasterName();
|
||||
|
||||
try {
|
||||
internalTestCluster().stopCurrentMasterNode();
|
||||
} catch (IOException ioe) {
|
||||
@ -140,7 +113,6 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||
Thread.sleep(maxTime.getMillis());
|
||||
|
||||
String newMaster = internalTestCluster().getMasterName();
|
||||
|
||||
assertFalse(newMaster.equals(oldMaster));
|
||||
logger.info("Switched master from [{}] to [{}]",oldMaster,newMaster);
|
||||
|
||||
@ -152,7 +124,6 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||
|
||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
||||
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(1L));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user