EntityGraph implements ConfigurationChangeListener { public Set<Entity> getDependents(Entity entity) throws IvoryException { Node entityNode = new Node(entity.getEntityType(), entity.getName()); if (graph.containsKey(entityNode)) { ConfigurationStore store = ConfigurationStore.get(); Set<Entity> dependents = new HashSet<Entity>(); for (Node node : graph.get(entityNode)) { Entity dependentEntity = store.get(node.type, node.name); assert dependentEntity != null : "Unable to find " + node; dependents.add(dependentEntity); } return dependents; } else { return null; } } private  EntityGraph(); static EntityGraph get(); Set<Entity> getDependents(Entity entity); @Override void onAdd(Entity entity); @Override void onRemove(Entity entity); @Override void onChange(Entity oldEntity, Entity newEntity);  }
@Test public void testOnRemove2() throws Exception { Process p1 = new Process(); p1.setName("ap1"); Process p2 = new Process(); p2.setName("ap2"); Cluster cluster = new Cluster(); cluster.setName("ac1"); cluster.setColo("3"); Feed f1 = addInput(p1, "af1", cluster); Feed f3 = addOutput(p1, "af3", cluster); Feed f2 = addOutput(p2, "af2", cluster); attachInput(p2, f3); org.apache.ivory.entity.v0.process.Cluster processCluster = new org.apache.ivory.entity.v0.process.Cluster(); processCluster.setName("ac1"); p1.setClusters(new org.apache.ivory.entity.v0.process.Clusters()); p1.getClusters().getClusters().add(processCluster); processCluster = new org.apache.ivory.entity.v0.process.Cluster(); processCluster.setName("ac1"); p2.setClusters(new org.apache.ivory.entity.v0.process.Clusters()); p2.getClusters().getClusters().add(processCluster); store.publish(EntityType.CLUSTER, cluster); store.publish(EntityType.FEED, f1); store.publish(EntityType.FEED, f2); store.publish(EntityType.FEED, f3); store.publish(EntityType.PROCESS, p1); store.publish(EntityType.PROCESS, p2); Set<Entity> entities = graph.getDependents(p1); Assert.assertEquals(entities.size(), 3); Assert.assertTrue(entities.contains(cluster)); Assert.assertTrue(entities.contains(f1)); Assert.assertTrue(entities.contains(f3)); entities = graph.getDependents(p2); Assert.assertEquals(entities.size(), 3); Assert.assertTrue(entities.contains(cluster)); Assert.assertTrue(entities.contains(f2)); Assert.assertTrue(entities.contains(f3)); entities = graph.getDependents(f1); Assert.assertEquals(entities.size(), 2); Assert.assertTrue(entities.contains(p1)); Assert.assertTrue(entities.contains(cluster)); entities = graph.getDependents(f2); Assert.assertEquals(entities.size(), 2); Assert.assertTrue(entities.contains(p2)); Assert.assertTrue(entities.contains(cluster)); entities = graph.getDependents(f3); Assert.assertEquals(entities.size(), 3); Assert.assertTrue(entities.contains(p2)); Assert.assertTrue(entities.contains(p1)); Assert.assertTrue(entities.contains(cluster)); entities = graph.getDependents(cluster); Assert.assertEquals(entities.size(), 5); Assert.assertTrue(entities.contains(p1)); Assert.assertTrue(entities.contains(p2)); Assert.assertTrue(entities.contains(f1)); Assert.assertTrue(entities.contains(f2)); Assert.assertTrue(entities.contains(f3)); store.remove(EntityType.PROCESS, p2.getName()); store.remove(EntityType.FEED, f2.getName()); entities = graph.getDependents(p1); Assert.assertEquals(entities.size(), 3); Assert.assertTrue(entities.contains(cluster)); Assert.assertTrue(entities.contains(f1)); Assert.assertTrue(entities.contains(f3)); entities = graph.getDependents(p2); Assert.assertTrue(entities == null); entities = graph.getDependents(f1); Assert.assertEquals(entities.size(), 2); Assert.assertTrue(entities.contains(p1)); Assert.assertTrue(entities.contains(cluster)); entities = graph.getDependents(f2); Assert.assertTrue(entities == null); entities = graph.getDependents(f3); Assert.assertEquals(entities.size(), 2); Assert.assertTrue(entities.contains(p1)); Assert.assertTrue(entities.contains(cluster)); entities = graph.getDependents(cluster); Assert.assertEquals(entities.size(), 3); Assert.assertTrue(entities.contains(p1)); Assert.assertTrue(entities.contains(f1)); Assert.assertTrue(entities.contains(f3)); }