Test: Replaced the internal clearing of the alert manager between tests with public stop alert service, delete alerts and alerts history index and start alert service calls.
Original commit: elastic/x-pack-elasticsearch@57c0120eb4
This commit is contained in:
parent
4b147b8f85
commit
c9e181e597
|
@ -215,15 +215,6 @@ public class AlertManager extends AbstractComponent {
|
|||
internalStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing only to clear the alerts and actions between tests.
|
||||
*/
|
||||
public void clear() {
|
||||
actionManager.restart();
|
||||
scheduler.clear();
|
||||
alertsStore.clear();
|
||||
}
|
||||
|
||||
private void internalStop() {
|
||||
if (state.compareAndSet(State.STARTED, State.STOPPING)) {
|
||||
logger.info("Stopping alert manager...");
|
||||
|
|
|
@ -140,13 +140,6 @@ public class AlertsStore extends AbstractComponent {
|
|||
return deleteResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists for testing purposes
|
||||
*/
|
||||
public void clear() {
|
||||
alertMap.clear();
|
||||
}
|
||||
|
||||
public ConcurrentMap<String, Alert> getAlerts() {
|
||||
return alertMap;
|
||||
}
|
||||
|
@ -187,7 +180,7 @@ public class AlertsStore extends AbstractComponent {
|
|||
|
||||
public void stop() {
|
||||
if (started.compareAndSet(true, false)) {
|
||||
clear();
|
||||
alertMap.clear();
|
||||
logger.info("Stopped alert store");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,14 +135,6 @@ public class AlertActionManager extends AbstractComponent {
|
|||
return started.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists for testing purposes.
|
||||
*/
|
||||
public void restart() {
|
||||
stop();
|
||||
doStart();
|
||||
}
|
||||
|
||||
private void doStart() {
|
||||
logger.info("Starting job queue");
|
||||
if (started.compareAndSet(false, true)) {
|
||||
|
|
|
@ -100,19 +100,6 @@ public class AlertScheduler extends AbstractComponent {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists for testing purposes
|
||||
*/
|
||||
public void clear() {
|
||||
try {
|
||||
if (scheduler != null) {
|
||||
scheduler.clear();
|
||||
}
|
||||
} catch (SchedulerException se){
|
||||
throw new ElasticsearchException("Failed to clear scheduler", se);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the alert with the specified name to be fired according to the specified cron expression.
|
||||
*/
|
||||
|
|
|
@ -63,11 +63,13 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest
|
|||
}
|
||||
|
||||
@After
|
||||
public void clearAlerts() {
|
||||
// Clear all internal state. Use manager directly because perhaps there isn't an elected master at this point
|
||||
for (AlertManager manager : internalTestCluster().getInstances(AlertManager.class)) {
|
||||
manager.clear();
|
||||
}
|
||||
public void clearAlerts() throws Exception {
|
||||
// Clear all internal alerting state for the next test method:
|
||||
stopAlerting();
|
||||
client().admin().indices().prepareDelete(AlertsStore.ALERT_INDEX, AlertActionManager.ALERT_HISTORY_INDEX)
|
||||
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
|
||||
.get();
|
||||
startAlerting();
|
||||
}
|
||||
|
||||
protected BytesReference createAlertSource(String cron, SearchRequest request, String scriptTrigger) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue