new HealthStatsAggregationTask(cmResult._manager).run();
//sleep for a few seconds to give stats stage time to trigger
Thread.sleep(1000);
// other verifications go here
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
ZNRecord record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
Map<String, Map<String,String>> recMap = record.getMapFields();
for(int i = 0; i < 2; i++)
{
String alertString = "(localhost_"+(12944 + i)+".RestQueryStats@DBName=TestDB0.latency)";
Map<String,String> alertStatusMap = recMap.get(alertwildcard+" : " + alertString);
String val = alertStatusMap.get(AlertValueAndStatus.VALUE_NAME);
boolean fired = Boolean.parseBoolean(alertStatusMap.get(AlertValueAndStatus.FIRED_NAME));
Assert.assertEquals(Double.parseDouble(val), (double)i * 5 + 0.1);
Assert.assertFalse(fired);
}
for(int i = 2; i < 5; i++)
{
String alertString = "(localhost_"+(12944 + i)+".RestQueryStats@DBName=TestDB0.latency)";
Map<String,String> alertStatusMap = recMap.get(alertwildcard+" : " + alertString);
String val = alertStatusMap.get(AlertValueAndStatus.VALUE_NAME);
boolean fired = Boolean.parseBoolean(alertStatusMap.get(AlertValueAndStatus.FIRED_NAME));
Assert.assertEquals(Double.parseDouble(val), (double)i * 5 + 0.1);
Assert.assertTrue(fired);
}
ZNRecord alertHistory = accessor.getProperty(keyBuilder.alertHistory()).getRecord();
String deltakey = (String) (alertHistory.getMapFields().keySet().toArray()[0]);
Map<String, String> delta = alertHistory.getMapField(deltakey);
Assert.assertEquals(delta.size() , 3);
for(int i = 2; i < 5; i++)
{
String alertString = "(localhost_"+(12944 + i)+".RestQueryStats@DBName#TestDB0.latency)GREATER(10)";
Assert.assertTrue(delta.get(alertString).equals("ON"));
}
// Drop and add another alert
_setupTool.getClusterManagementTool().dropAlert(clusterName, alertwildcard);
alertwildcard = "EXP(decay(1.0)(localhost*.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(15)";
_setupTool.getClusterManagementTool().addAlert(clusterName, alertwildcard);
new HealthStatsAggregationTask(cmResult._manager).run();
Thread.sleep(1000);
record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
recMap = record.getMapFields();
for(int i = 0; i < 3; i++)
{
String alertString = "(localhost_"+(12944 + i)+".RestQueryStats@DBName=TestDB0.latency)";
Map<String,String> alertStatusMap = recMap.get(alertwildcard+" : " + alertString);
String val = alertStatusMap.get(AlertValueAndStatus.VALUE_NAME);
boolean fired = Boolean.parseBoolean(alertStatusMap.get(AlertValueAndStatus.FIRED_NAME));
Assert.assertEquals(Double.parseDouble(val), (double)i * 5 + 0.1);
Assert.assertFalse(fired);
}
for(int i = 3; i < 5; i++)
{
String alertString = "(localhost_"+(12944 + i)+".RestQueryStats@DBName=TestDB0.latency)";
Map<String,String> alertStatusMap = recMap.get(alertwildcard+" : " + alertString);
String val = alertStatusMap.get(AlertValueAndStatus.VALUE_NAME);
boolean fired = Boolean.parseBoolean(alertStatusMap.get(AlertValueAndStatus.FIRED_NAME));
Assert.assertEquals(Double.parseDouble(val), (double)i * 5 + 0.1);
Assert.assertTrue(fired);
}
alertHistory = accessor.getProperty(keyBuilder.alertHistory()).getRecord();
deltakey = (String) (alertHistory.getMapFields().keySet().toArray()[1]);
delta = alertHistory.getMapField(deltakey);
Assert.assertTrue(delta.size() == 2);
for(int i = 3; i < 5; i++)