Код: Выделить всё
@Test
void lifecycleRegistryIntegratesWithDedicatedSpringLifecycleBeans() {
testContext.run(context -> {
// We expect beans to be registered for lifecycle handlers.
Map startHandlers = BeanFactoryUtils.beansOfTypeIncludingAncestors(
context, SpringLifecycleStartHandler.class
);
Map shutdownHandlers = BeanFactoryUtils.beansOfTypeIncludingAncestors(
context, SpringLifecycleShutdownHandler.class
);
for (SpringLifecycleStartHandler startHandler : startHandlers.values()) {
assertTrue(startHandler.isRunning());
}
for (SpringLifecycleShutdownHandler shutdownHandler : shutdownHandlers.values()) {
assertTrue(shutdownHandler.isRunning());
}
AtomicBoolean startHandlerInvoked = context.getBean("startHandlerInvoked", AtomicBoolean.class);
assertTrue(startHandlerInvoked.get());
AtomicBoolean shutdownHandlerInvoked = context.getBean("shutdownHandlerInvoked", AtomicBoolean.class);
assertFalse(shutdownHandlerInvoked.get());
// I hope that this would invoke the shutdown handler, but it does not
context.stop();
// Validate the shutdown handler is invoked...
await().atMost(Duration.ofSeconds(5))
.pollDelay(Duration.ofMillis(25))
.until(shutdownHandlerInvoked::get);
});
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... invocation