Map<String, String> oldConfigs = new HashMap<String, String>();
oldConfigs.put("type1", "v1");
oldConfigs.put("type2", "v1");
oldConfigs.put("type3", "v1");
HostComponentStateEntityPK primaryKey =
new HostComponentStateEntityPK();
primaryKey.setClusterId(clusters.getCluster("C1").getClusterId());
primaryKey.setServiceName("HDFS");
primaryKey.setComponentName("DATANODE");
primaryKey.setHostName("h1");
HostComponentStateEntity entity =
hostComponentStateDAO.findByPK(primaryKey);
Collection<HostComponentConfigMappingEntity> entities =
entity.getHostComponentConfigMappingEntities();
Assert.assertEquals(0, entities.size());
impl.setConfigs(oldConfigs);
impl.persist();
Assert.assertEquals(3, impl.getConfigVersions().size());
entity = hostComponentStateDAO.findByPK(primaryKey);
entities = entity.getHostComponentConfigMappingEntities();
Assert.assertEquals(3, entities.size());
Map<String, String> newConfigs = new HashMap<String, String>();
newConfigs.put("type1", "v1");
newConfigs.put("type2", "v3");
newConfigs.put("type4", "v5");
ServiceComponentHostStartEvent startEvent =
new ServiceComponentHostStartEvent("DATANODE", "h1", 1, newConfigs);
impl.handleEvent(startEvent);
Assert.assertEquals(newConfigs.size(),
impl.getConfigVersions().size());
entity = hostComponentStateDAO.findByPK(primaryKey);
entities = entity.getHostComponentConfigMappingEntities();
Assert.assertEquals(3, entities.size());
for (HostComponentConfigMappingEntity e : entities) {
LOG.debug("Found live config "
+ e.getConfigType() + ":" + e.getVersionTag());
Assert.assertTrue(e.getComponentName().equals("DATANODE")
&& e.getClusterId() == primaryKey.getClusterId()
&& e.getHostName().equals("h1")
&& e.getServiceName().equals("HDFS"));
if (e.getConfigType().equals("type1")) {
Assert.assertEquals("v1", e.getVersionTag());
} else if (e.getConfigType().equals("type2")) {