| 5827 |
amar.kumar |
1 |
package net.sourceforge.stat4j;
|
|
|
2 |
|
|
|
3 |
import junit.framework.TestCase;
|
|
|
4 |
|
|
|
5 |
import java.util.Properties;
|
|
|
6 |
|
|
|
7 |
public class AlertTest extends TestCase {
|
|
|
8 |
|
|
|
9 |
private static final int QUIET_PERIOD_MS = 1;
|
|
|
10 |
private static final double MEASURE_WARN = 0.0;
|
|
|
11 |
private static final double MEASURE_CRITICAL = 4.0;
|
|
|
12 |
|
|
|
13 |
private final Threshold belowOne = Threshold.toThreshold("<1");
|
|
|
14 |
|
|
|
15 |
private Alert alert;
|
|
|
16 |
|
|
|
17 |
@Override
|
|
|
18 |
protected void setUp() throws Exception {
|
|
|
19 |
alert = new Alert();
|
|
|
20 |
Properties properties = new Properties();
|
|
|
21 |
properties.setProperty("quietperiod", String.valueOf(QUIET_PERIOD_MS));
|
|
|
22 |
properties.setProperty("warn", "<1");
|
|
|
23 |
properties.setProperty("critical", ">3");
|
|
|
24 |
alert.init("test", properties);
|
|
|
25 |
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public void test_not_triggered_again_for_quietperiod() throws Exception {
|
|
|
29 |
assertTrue("1st triggering event should pass through", alert.evaluateAlert(MEASURE_WARN));
|
|
|
30 |
assertFalse("Should keep quiet after the first triggering for the length of the quiet period"
|
|
|
31 |
, alert.evaluateAlert(0.0));
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public void test_triggered_again_after_quietperiod_end() throws Exception {
|
|
|
35 |
assertTrue("1st triggering event should pass through", alert.evaluateAlert(MEASURE_WARN));
|
|
|
36 |
simulateQuietPeriodEnded();
|
|
|
37 |
assertTrue("Another event after the quiet period's end should trigger new alert"
|
|
|
38 |
, alert.evaluateAlert(MEASURE_WARN));
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
private void simulateQuietPeriodEnded() {
|
|
|
42 |
alert.lastAlertedMs = System.currentTimeMillis() - (QUIET_PERIOD_MS + 1);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public void test_new_critical_event_triggers_alert_even_in_quiet_period() throws Exception {
|
|
|
46 |
assertTrue("1st triggering event should pass through", alert.evaluateAlert(MEASURE_WARN));
|
|
|
47 |
assertTrue("Following critical alert shall pass through too", alert.evaluateAlert(MEASURE_CRITICAL));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public void test_reset_after_quiet_period_end() throws Exception {
|
|
|
51 |
alert.evaluateAlert(MEASURE_WARN); // Start quiet period
|
|
|
52 |
alert.evaluateAlert(MEASURE_CRITICAL); // Log anyway - critical
|
|
|
53 |
|
|
|
54 |
simulateQuietPeriodEnded();
|
|
|
55 |
|
|
|
56 |
assertTrue("After reset: 1st triggering event should pass through", alert.evaluateAlert(MEASURE_WARN));
|
|
|
57 |
assertTrue("After reset: Following critical alert shall pass through too", alert.evaluateAlert(MEASURE_CRITICAL));
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public void test_repeated_warn_and_critical_events_ignored_in_quiet_period() throws Exception {
|
|
|
61 |
assertTrue("1st triggering event should pass through", alert.evaluateAlert(MEASURE_WARN));
|
|
|
62 |
assertTrue("Following critical alert shall pass through too", alert.evaluateAlert(MEASURE_CRITICAL));
|
|
|
63 |
assertFalse("Repeated warn shall be ignored in quiet period", alert.evaluateAlert(MEASURE_WARN));
|
|
|
64 |
assertFalse("Repeated critical shall be ignored in quiet period too", alert.evaluateAlert(MEASURE_CRITICAL));
|
|
|
65 |
}
|
|
|
66 |
}
|