@Test
  public void testInvokeTerminateManagementContextOnShutdown() throws Exception {
    BrooklynShutdownHooks.invokeTerminateOnShutdown(managementContext);
    BrooklynShutdownHooks.BrooklynShutdownHookJob job =
        BrooklynShutdownHookJob.newInstanceForTesting();
    job.run();

    assertFalse(managementContext.isRunning());
  }
  // Should first stop entities, then terminate management contexts
  @Test
  public void testInvokeStopEntityAndTerminateManagementContextOnShutdown() throws Exception {
    BrooklynShutdownHooks.invokeTerminateOnShutdown(managementContext);
    BrooklynShutdownHooks.invokeStopOnShutdown(entity);
    BrooklynShutdownHooks.BrooklynShutdownHookJob job =
        BrooklynShutdownHookJob.newInstanceForTesting();
    job.run();

    assertTrue(entity.getCallHistory().contains("stop"));
    assertFalse(managementContext.isRunning());
  }
 public void onManagementStopped() {
   this.managed = false;
   if (managementContext.isRunning()) {
     BrooklynStorage storage = ((ManagementContextInternal) managementContext).getStorage();
     storage.remove(id + "-parent");
     storage.remove(id + "-children");
     storage.remove(id + "-creationTime");
     storage.remove(id + "-hostGeoInfo");
     storage.remove(id + "-displayName");
     storage.remove(id + "-config");
   }
 }