@Test void testExecutionResilience() { Cleaner cleaner1 = Mockito.mock(Cleaner.class); Cleaner cleaner2 = Mockito.mock(Cleaner.class); Mockito.doThrow(new SLException("Will it work?")) .when(cleaner2) .execute(Mockito.any()); Cleaner cleaner3 = Mockito.mock(Cleaner.class); List<Cleaner> cleaners = List.of(cleaner1, cleaner2, cleaner3); CleanUpJob cleanUpJob = createCleanUpJob(new ApplicationConfiguration(), cleaners); cleanUpJob.execute(null); Mockito.verify(cleaner1) .execute(Mockito.any()); Mockito.verify(cleaner2) .execute(Mockito.any()); Mockito.verify(cleaner3) .execute(Mockito.any()); }
@Override public void execute(JobExecutionContext context) { LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_STARTED_BY_APPLICATION_INSTANCE_0_AT_1, configuration.getApplicationInstanceIndex(), Instant.now())); Date expirationTime = computeExpirationTime(); LOGGER.info(LOG_MARKER, format(Messages.WILL_CLEAN_UP_DATA_STORED_BEFORE_0, expirationTime)); LOGGER.info(LOG_MARKER, format(Messages.REGISTERED_CLEANERS_IN_CLEAN_UP_JOB_0, cleaners)); for (Cleaner cleaner : cleaners) { safeExecutor.execute(() -> cleaner.execute(expirationTime)); } LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_FINISHED_AT_0, Instant.now())); }
CleanUpJob implements Job { @Override public void execute(JobExecutionContext context) { LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_STARTED_BY_APPLICATION_INSTANCE_0_AT_1, configuration.getApplicationInstanceIndex(), Instant.now())); Date expirationTime = computeExpirationTime(); LOGGER.info(LOG_MARKER, format(Messages.WILL_CLEAN_UP_DATA_STORED_BEFORE_0, expirationTime)); LOGGER.info(LOG_MARKER, format(Messages.REGISTERED_CLEANERS_IN_CLEAN_UP_JOB_0, cleaners)); for (Cleaner cleaner : cleaners) { safeExecutor.execute(() -> cleaner.execute(expirationTime)); } LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_FINISHED_AT_0, Instant.now())); } }
CleanUpJob implements Job { @Override public void execute(JobExecutionContext context) { LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_STARTED_BY_APPLICATION_INSTANCE_0_AT_1, configuration.getApplicationInstanceIndex(), Instant.now())); Date expirationTime = computeExpirationTime(); LOGGER.info(LOG_MARKER, format(Messages.WILL_CLEAN_UP_DATA_STORED_BEFORE_0, expirationTime)); LOGGER.info(LOG_MARKER, format(Messages.REGISTERED_CLEANERS_IN_CLEAN_UP_JOB_0, cleaners)); for (Cleaner cleaner : cleaners) { safeExecutor.execute(() -> cleaner.execute(expirationTime)); } LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_FINISHED_AT_0, Instant.now())); }  }
CleanUpJob implements Job { @Override public void execute(JobExecutionContext context) { LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_STARTED_BY_APPLICATION_INSTANCE_0_AT_1, configuration.getApplicationInstanceIndex(), Instant.now())); Date expirationTime = computeExpirationTime(); LOGGER.info(LOG_MARKER, format(Messages.WILL_CLEAN_UP_DATA_STORED_BEFORE_0, expirationTime)); LOGGER.info(LOG_MARKER, format(Messages.REGISTERED_CLEANERS_IN_CLEAN_UP_JOB_0, cleaners)); for (Cleaner cleaner : cleaners) { safeExecutor.execute(() -> cleaner.execute(expirationTime)); } LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_FINISHED_AT_0, Instant.now())); }  @Override void execute(JobExecutionContext context); }
CleanUpJob implements Job { @Override public void execute(JobExecutionContext context) { LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_STARTED_BY_APPLICATION_INSTANCE_0_AT_1, configuration.getApplicationInstanceIndex(), Instant.now())); Date expirationTime = computeExpirationTime(); LOGGER.info(LOG_MARKER, format(Messages.WILL_CLEAN_UP_DATA_STORED_BEFORE_0, expirationTime)); LOGGER.info(LOG_MARKER, format(Messages.REGISTERED_CLEANERS_IN_CLEAN_UP_JOB_0, cleaners)); for (Cleaner cleaner : cleaners) { safeExecutor.execute(() -> cleaner.execute(expirationTime)); } LOGGER.info(LOG_MARKER, format(Messages.CLEAN_UP_JOB_FINISHED_AT_0, Instant.now())); }  @Override void execute(JobExecutionContext context); static final Marker LOG_MARKER; }