// 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());
  }
  @Test
  public void testInvokeStopEntityTimesOutOnShutdown() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    BlockingEntity blockingEntity =
        app.createAndManageChild(
            EntitySpec.create(BlockingEntity.class)
                .configure(BlockingEntity.SHUTDOWN_LATCH, latch));

    // It will timeout after shutdown-timeout
    BrooklynShutdownHooks.setShutdownTimeout(Duration.of(100, TimeUnit.MILLISECONDS));
    BrooklynShutdownHooks.invokeStopOnShutdown(blockingEntity);
    BrooklynShutdownHooks.BrooklynShutdownHookJob job =
        BrooklynShutdownHookJob.newInstanceForTesting();
    job.run();

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

    assertFalse(managementContext.isRunning());
  }
  @Test
  public void testInvokeStopEntityOnShutdown() throws Exception {
    BrooklynShutdownHooks.invokeStopOnShutdown(entity);
    BrooklynShutdownHooks.BrooklynShutdownHookJob job =
        BrooklynShutdownHookJob.newInstanceForTesting();
    job.run();

    assertTrue(entity.getCallHistory().contains("stop"));
  }