public void testUnmanagedEntityCanBeGcedEvenIfPreviouslyTagged() throws Exception { TestEntity e = app.createAndManageChild(EntitySpec.create(TestEntity.class)); String eId = e.getId(); e.invoke(TestEntity.MY_EFFECTOR, ImmutableMap.<String,Object>of()).get(); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(), e); Task<?> task = Iterables.get(tasks, 0); assertTrue(task.getTags().contains(BrooklynTaskTags.tagForContextEntity(e))); Set<Object> tags = app.getManagementContext().getExecutionManager().getTaskTags(); assertTrue(tags.contains(BrooklynTaskTags.tagForContextEntity(e)), "tags="+tags); Entities.destroy(e); forceGc(); Set<Object> tags2 = app.getManagementContext().getExecutionManager().getTaskTags(); for (Object tag : tags2) { if (tag instanceof Entity && ((Entity)tag).getId().equals(eId)) { fail("tags contains unmanaged entity "+tag); } if ((tag instanceof WrappedEntity) && ((WrappedEntity)tag).entity.getId().equals(eId) && ((WrappedEntity)tag).wrappingType.equals(BrooklynTaskTags.CONTEXT_ENTITY)) { fail("tags contains unmanaged entity (wrapped) "+tag); } } return; }