@Test public void typicalRunWithException() throws Exception { doThrow(new RuntimeException()) .doNothing() .when(schedulerApiary) .scheduleBeekeeperEvent(); runRunner(); await().atMost(Duration.FIVE_SECONDS) .untilAsserted(() -> verify(schedulerApiary, atLeast(2)).scheduleBeekeeperEvent()); destroy(); verify(schedulerApiary).close(); }
@PreDestroy public void destroy() { try { log.info("Shutting down runner"); running.set(false); if (!lock.tryLock(RUNNER_DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { throw new BeekeeperException("Runner taking too long to shut down"); } } catch (InterruptedException e) { throw new BeekeeperException("Runner taking too long to shut down", e); } finally { try { schedulerApiary.close(); } catch (IOException e) { throw new BeekeeperException("Problem closing resources", e); } } log.info("Runner is shutdown"); }
SchedulerApiaryRunner implements ApplicationRunner { @PreDestroy public void destroy() { try { log.info("Shutting down runner"); running.set(false); if (!lock.tryLock(RUNNER_DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { throw new BeekeeperException("Runner taking too long to shut down"); } } catch (InterruptedException e) { throw new BeekeeperException("Runner taking too long to shut down", e); } finally { try { schedulerApiary.close(); } catch (IOException e) { throw new BeekeeperException("Problem closing resources", e); } } log.info("Runner is shutdown"); } }
SchedulerApiaryRunner implements ApplicationRunner { @PreDestroy public void destroy() { try { log.info("Shutting down runner"); running.set(false); if (!lock.tryLock(RUNNER_DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { throw new BeekeeperException("Runner taking too long to shut down"); } } catch (InterruptedException e) { throw new BeekeeperException("Runner taking too long to shut down", e); } finally { try { schedulerApiary.close(); } catch (IOException e) { throw new BeekeeperException("Problem closing resources", e); } } log.info("Runner is shutdown"); } @Autowired  SchedulerApiaryRunner(SchedulerApiary schedulerApiary); }
SchedulerApiaryRunner implements ApplicationRunner { @PreDestroy public void destroy() { try { log.info("Shutting down runner"); running.set(false); if (!lock.tryLock(RUNNER_DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { throw new BeekeeperException("Runner taking too long to shut down"); } } catch (InterruptedException e) { throw new BeekeeperException("Runner taking too long to shut down", e); } finally { try { schedulerApiary.close(); } catch (IOException e) { throw new BeekeeperException("Problem closing resources", e); } } log.info("Runner is shutdown"); } @Autowired  SchedulerApiaryRunner(SchedulerApiary schedulerApiary); @Override void run(ApplicationArguments args); @PreDestroy void destroy(); }
SchedulerApiaryRunner implements ApplicationRunner { @PreDestroy public void destroy() { try { log.info("Shutting down runner"); running.set(false); if (!lock.tryLock(RUNNER_DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { throw new BeekeeperException("Runner taking too long to shut down"); } } catch (InterruptedException e) { throw new BeekeeperException("Runner taking too long to shut down", e); } finally { try { schedulerApiary.close(); } catch (IOException e) { throw new BeekeeperException("Problem closing resources", e); } } log.info("Runner is shutdown"); } @Autowired  SchedulerApiaryRunner(SchedulerApiary schedulerApiary); @Override void run(ApplicationArguments args); @PreDestroy void destroy();  }