}
@Test
public void testMetainfoParsing() throws Exception {
InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes());
Metainfo metainfo = new MetainfoParser().parse(metainfo_1);
Assert.assertEquals(metainfo.getServices().size(), 1);
Service service = metainfo.getServices().get(0);
log.info("Service: " + service.toString());
Assert.assertEquals(service.getName(), "HBASE");
Assert.assertEquals(service.getComponents().size(), 2);
List<Component> components = service.getComponents();
int found = 0;
for (Component component : components) {
if (component.getName().equals("HBASE_MASTER")) {
Assert.assertEquals(component.getMinInstanceCount(), "1");
Assert.assertEquals(component.getMaxInstanceCount(), "2");
Assert.assertEquals(component.getCommandScript().getScript(), "scripts/hbase_master.py");
Assert.assertEquals(component.getCategory(), "MASTER");
found++;
}
if (component.getName().equals("HBASE_REGIONSERVER")) {
Assert.assertEquals(component.getMinInstanceCount(), "1");
Assert.assertNull(component.getMaxInstanceCount());
Assert.assertEquals(component.getCommandScript().getScript(), "scripts/hbase_regionserver.py");
Assert.assertEquals(component.getCategory(), "SLAVE");
found++;
}
}
Assert.assertEquals(found, 2);
assert service.getExportGroups().size() == 1;
List<ExportGroup> egs = service.getExportGroups();
ExportGroup eg = egs.get(0);
assert eg.getName().equals("QuickLinks");
assert eg.getExports().size() == 2;
found = 0;
for (Export export : eg.getExports()) {
if (export.getName().equals("JMX_Endpoint")) {
found++;
Assert.assertEquals(export.getValue(),
"http://${HBASE_MASTER_HOST}:${site.hbase-site.hbase.master.info.port}/jmx");
}
if (export.getName().equals("Master_Status")) {
found++;
Assert.assertEquals(export.getValue(),
"http://${HBASE_MASTER_HOST}:${site.hbase-site.hbase.master.info.port}/master-status");
}
}
Assert.assertEquals(found, 2);
List<CommandOrder> cmdOrders = service.getCommandOrder();
Assert.assertEquals(cmdOrders.size(), 2);
found = 0;
for (CommandOrder co : service.getCommandOrder()) {
if (co.getCommand().equals("HBASE_REGIONSERVER-START")) {
Assert.assertTrue(co.getRequires().equals("HBASE_MASTER-STARTED"));
found++;
}
if (co.getCommand().equals("A-START")) {
Assert.assertEquals(co.getRequires(), "B-STARTED");
found++;
}
}
Assert.assertEquals(found, 2);
AgentProviderService aps = new AgentProviderService();
AgentProviderService mockAps = Mockito.spy(aps);
doReturn(metainfo).when(mockAps).getMetainfo();
String scriptPath = mockAps.getScriptPathFromMetainfo("HBASE_MASTER");
Assert.assertEquals(scriptPath, "scripts/hbase_master.py");
String metainfo_1_str_bad = "<metainfo>\n"
+ " <schemaVersion>2.0</schemaVersion>\n"
+ " <services>\n"
+ " <service>\n"
+ " <name>HBASE</name>\n"
+ " <comment>\n"
+ " Apache HBase\n"
+ " </comment>\n";
metainfo_1 = new ByteArrayInputStream(metainfo_1_str_bad.getBytes());
metainfo = new MetainfoParser().parse(metainfo_1);
Assert.assertNull(metainfo);
}