{
history = property.getRecord();
historySize = property.getRecord().getMapFields().size();
}
HealthStatsAggregationTask task = new HealthStatsAggregationTask(_startCMResultMap.get(controllerName)._manager);
task.run();
Thread.sleep(100);
history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
//
Assert.assertEquals(history.getMapFields().size(), 1 + historySize);
TreeMap<String, Map<String, String>> recordMap = new TreeMap<String, Map<String, String>>();
recordMap.putAll( history.getMapFields());
Map<String, String> lastRecord = recordMap.firstEntry().getValue();
Assert.assertTrue(lastRecord.size() == 4);
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
setHealthData(metrics1, metrics2);
task.run();
Thread.sleep(100);
history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
// no change
Assert.assertEquals(history.getMapFields().size(), 1 + historySize);
recordMap = new TreeMap<String, Map<String, String>>();
recordMap.putAll( history.getMapFields());
lastRecord = recordMap.firstEntry().getValue();
Assert.assertTrue(lastRecord.size() == 4);
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
int [] metrics3 = {21, 44, 22, 14, 16};
int [] metrics4 = {122, 115, 222, 41,16};
setHealthData(metrics3, metrics4);
task.run();
Thread.sleep(100);
history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
// new delta should be recorded
Assert.assertEquals(history.getMapFields().size(), 2 + historySize);
recordMap = new TreeMap<String, Map<String, String>>();
recordMap.putAll( history.getMapFields());
lastRecord = recordMap.lastEntry().getValue();
Assert.assertEquals(lastRecord.size(), 6);
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
int [] metrics5 = {0, 0, 0, 0, 0};
int [] metrics6 = {0, 0, 0, 0,0};
setHealthData(metrics5, metrics6);
task.run();
Thread.sleep(500);
history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
// reset everything
Assert.assertEquals(history.getMapFields().size(), 3 + historySize);
recordMap = new TreeMap<String, Map<String, String>>();
recordMap.putAll( history.getMapFields());
lastRecord = recordMap.lastEntry().getValue();
Assert.assertTrue(lastRecord.size() == 6);
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
// Size of the history should be 30
for(int i = 0;i < 27; i++)
{
int x = i % 2;
int y = (i+1) % 2;
int[] metricsx = {19 + 3*x, 19 + 3*y, 19 + 4*x, 18+4*y, 17+5*y};
int[] metricsy = {99 + 3*x, 99 + 3*y, 98 + 4*x, 98+4*y, 97+5*y};
setHealthData(metricsx, metricsy);
task.run();
Thread.sleep(100);
history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
Assert.assertEquals(history.getMapFields().size(), Math.min(3 + i + 1 + historySize, 30));
recordMap = new TreeMap<String, Map<String, String>>();
recordMap.putAll( history.getMapFields());
lastRecord = recordMap.lastEntry().getValue();
if(i == 0)
{
Assert.assertTrue(lastRecord.size() == 6);
Assert.assertTrue(lastRecord.get("(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
}
else
{
System.out.println(lastRecord.size());
Assert.assertEquals(lastRecord.size() , 10);
if(x == 0)
{
Assert.assertTrue(lastRecord.get("(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
}
else
{
Assert.assertTrue(lastRecord.get("(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
}
}
}
// size limit is 30
for(int i = 0;i < 10; i++)
{
int x = i % 2;
int y = (i+1) % 2;
int[] metricsx = {19 + 3*x, 19 + 3*y, 19 + 4*x, 18+4*y, 17+5*y};
int[] metricsy = {99 + 3*x, 99 + 3*y, 98 + 4*x, 98+4*y, 97+5*y};
setHealthData(metricsx, metricsy);
task.run();
Thread.sleep(100);
history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
Assert.assertEquals(history.getMapFields().size(), 30);
recordMap = new TreeMap<String, Map<String, String>>();