|
@@ -5,6 +5,10 @@
|
|
|
*/
|
|
|
package org.elasticsearch.xpack.ml.datafeed;
|
|
|
|
|
|
+import org.elasticsearch.ElasticsearchException;
|
|
|
+import org.elasticsearch.ElasticsearchWrapperException;
|
|
|
+import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
|
|
+import org.elasticsearch.action.search.ShardSearchFailure;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor;
|
|
|
import org.junit.Before;
|
|
@@ -27,33 +31,43 @@ public class ProblemTrackerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testReportExtractionProblem() {
|
|
|
- problemTracker.reportExtractionProblem("foo");
|
|
|
+ problemTracker.reportExtractionProblem(createExtractionProblem("top level", "cause"));
|
|
|
|
|
|
- verify(auditor).error("foo", "Datafeed is encountering errors extracting data: foo");
|
|
|
+ verify(auditor).error("foo", "Datafeed is encountering errors extracting data: cause");
|
|
|
+ assertTrue(problemTracker.hasProblems());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testReportExtractionProblem_GivenSearchPhaseExecutionException() {
|
|
|
+ SearchPhaseExecutionException searchPhaseExecutionException = new SearchPhaseExecutionException("test-phase",
|
|
|
+ "partial shards failure", new ShardSearchFailure[] { new ShardSearchFailure(new ElasticsearchException("for the cause!")) });
|
|
|
+
|
|
|
+ problemTracker.reportExtractionProblem(new DatafeedJob.ExtractionProblemException(0L, searchPhaseExecutionException));
|
|
|
+
|
|
|
+ verify(auditor).error("foo", "Datafeed is encountering errors extracting data: for the cause!");
|
|
|
assertTrue(problemTracker.hasProblems());
|
|
|
}
|
|
|
|
|
|
public void testReportAnalysisProblem() {
|
|
|
- problemTracker.reportAnalysisProblem("foo");
|
|
|
+ problemTracker.reportAnalysisProblem(createAnalysisProblem("top level", "cause"));
|
|
|
|
|
|
- verify(auditor).error("foo", "Datafeed is encountering errors submitting data for analysis: foo");
|
|
|
+ verify(auditor).error("foo", "Datafeed is encountering errors submitting data for analysis: cause");
|
|
|
assertTrue(problemTracker.hasProblems());
|
|
|
}
|
|
|
|
|
|
public void testReportProblem_GivenSameProblemTwice() {
|
|
|
- problemTracker.reportExtractionProblem("foo");
|
|
|
- problemTracker.reportAnalysisProblem("foo");
|
|
|
+ problemTracker.reportExtractionProblem(createExtractionProblem("top level", "cause"));
|
|
|
+ problemTracker.reportAnalysisProblem(createAnalysisProblem("top level", "cause"));
|
|
|
|
|
|
- verify(auditor, times(1)).error("foo", "Datafeed is encountering errors extracting data: foo");
|
|
|
+ verify(auditor, times(1)).error("foo", "Datafeed is encountering errors extracting data: cause");
|
|
|
assertTrue(problemTracker.hasProblems());
|
|
|
}
|
|
|
|
|
|
public void testReportProblem_GivenSameProblemAfterFinishReport() {
|
|
|
- problemTracker.reportExtractionProblem("foo");
|
|
|
+ problemTracker.reportExtractionProblem(createExtractionProblem("top level", "cause"));
|
|
|
problemTracker.finishReport();
|
|
|
- problemTracker.reportExtractionProblem("foo");
|
|
|
+ problemTracker.reportExtractionProblem(createExtractionProblem("top level", "cause"));
|
|
|
|
|
|
- verify(auditor, times(1)).error("foo", "Datafeed is encountering errors extracting data: foo");
|
|
|
+ verify(auditor, times(1)).error("foo", "Datafeed is encountering errors extracting data: cause");
|
|
|
assertTrue(problemTracker.hasProblems());
|
|
|
}
|
|
|
|
|
@@ -108,7 +122,7 @@ public class ProblemTrackerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testFinishReport_GivenRecovery() {
|
|
|
- problemTracker.reportExtractionProblem("bar");
|
|
|
+ problemTracker.reportExtractionProblem(createExtractionProblem("top level", "bar"));
|
|
|
problemTracker.finishReport();
|
|
|
problemTracker.finishReport();
|
|
|
|
|
@@ -116,4 +130,23 @@ public class ProblemTrackerTests extends ESTestCase {
|
|
|
verify(auditor).info("foo", "Datafeed has recovered data extraction and analysis");
|
|
|
assertFalse(problemTracker.hasProblems());
|
|
|
}
|
|
|
+
|
|
|
+ private static DatafeedJob.ExtractionProblemException createExtractionProblem(String error, String cause) {
|
|
|
+ Exception causeException = new RuntimeException(cause);
|
|
|
+ Exception wrappedException = new TestWrappedException(error, causeException);
|
|
|
+ return new DatafeedJob.ExtractionProblemException(0L, wrappedException);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static DatafeedJob.AnalysisProblemException createAnalysisProblem(String error, String cause) {
|
|
|
+ Exception causeException = new RuntimeException(cause);
|
|
|
+ Exception wrappedException = new TestWrappedException(error, causeException);
|
|
|
+ return new DatafeedJob.AnalysisProblemException(0L, false, wrappedException);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class TestWrappedException extends RuntimeException implements ElasticsearchWrapperException {
|
|
|
+
|
|
|
+ TestWrappedException(String message, Throwable cause) {
|
|
|
+ super(message, cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|