@Test()
public void TestReportData()
{
MockHelixManager manager = new MockHelixManager();
ResourceMonitor monitor = new ResourceMonitor(_clusterName, _dbName);
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
Builder keyBuilder = helixDataAccessor.keyBuilder();
ExternalView externalView =
helixDataAccessor.getProperty(keyBuilder.externalView(_dbName));
IdealState idealState = helixDataAccessor.getProperty(keyBuilder.idealStates(_dbName));
monitor.updateExternalView(externalView, idealState);
AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), 0);
AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), 0);
AssertJUnit.assertEquals(monitor.getExternalViewPartitionGauge(), _partitions);
AssertJUnit.assertEquals(monitor.getPartitionGauge(), _partitions);
monitor.getBeanName();
int n = 4;
for (int i = 0; i < n; i++)
{
Map<String, String> map = externalView.getStateMap(_dbName + "_" + 3 * i);
String key = map.keySet().toArray()[0].toString();
map.put(key, "ERROR");
externalView.setStateMap(_dbName + "_" + 3 * i, map);
}
monitor.updateExternalView(externalView, idealState);
AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), 0);
AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), n);
AssertJUnit.assertEquals(monitor.getExternalViewPartitionGauge(), _partitions);
AssertJUnit.assertEquals(monitor.getPartitionGauge(), _partitions);
n = 5;
for (int i = 0; i < n; i++)
{
externalView.getRecord().getMapFields().remove(_dbName + "_" + 4 * i);
}
monitor.updateExternalView(externalView, idealState);
AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), n
* (_replicas + 1));
AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), 3);
AssertJUnit.assertEquals(monitor.getExternalViewPartitionGauge(), _partitions - n);
AssertJUnit.assertEquals(monitor.getPartitionGauge(), _partitions);
}