private void testLocationUnmanagedOnStop(LocationSpec<? extends Location> locationSpec) { EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class) .location(locationSpec) .child( EntitySpec.create(EmptySoftwareProcess.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, Boolean.TRUE) .configure(EmptySoftwareProcess.USE_SSH_MONITORING, Boolean.FALSE)); BasicApplication app = mgmt.getEntityManager().createEntity(appSpec); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getLocations(), ImmutableList.of()); app.start(ImmutableList.<Location>of()); Location appLocation = Iterables.getOnlyElement(app.getLocations()); assertOwned(app, appLocation); Location entityLocation = Iterables.getOnlyElement(child.getLocations()); // No owner tag because it's created by SoftwareProcess, not by Brooklyn internals assertNotOwned(entityLocation); app.stop(); Assert.assertEquals(child.getLocations(), ImmutableList.of()); Assert.assertFalse(mgmt.getEntityManager().isManaged(child)); Assert.assertFalse(mgmt.getEntityManager().isManaged(app)); Set<Location> locs = ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()); Assert.assertFalse( locs.contains(entityLocation), locs + " should not contain " + entityLocation); Assert.assertFalse(locs.contains(appLocation), locs + " should not contain " + appLocation); }
private void assertOwned(BasicApplication app, Location loc) { NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, loc.tags().getTags()); Assert.assertNotNull(ownerEntityTag); Assert.assertEquals(ownerEntityTag.getContents(), app.getId()); }