@Test void testBootstrap() { when(systemEntityTypeRegistry.getSystemEntityTypes()) .thenReturn(Stream.of(fileIngestJobExecutionType)); when(fileIngestJobExecutionType.getExtends()).thenReturn(jobExecutionType); when(jobExecutionType.getId()).thenReturn(JOB_EXECUTION); when(fileIngestJobExecutionType.getId()).thenReturn("sys_FileIngestJobExecution"); when(dataService.query("sys_FileIngestJobExecution")).thenReturn(query); when(query.eq(STATUS, RUNNING)).thenReturn(query); when(query.eq(STATUS, PENDING)).thenReturn(query); when(query.eq(STATUS, CANCELING)).thenReturn(query); when(query.or()).thenReturn(query); when(query.findAll()).thenReturn(Stream.of(fileIngestJob1, fileIngestJob2, fileIngestJob3)); when(dataService.getRepository(SCHEDULED_JOB_TYPE, ScheduledJobType.class)) .thenReturn(jobTypeRepo); when(fileIngestJob1.get(LOG)).thenReturn("Current log"); when(fileIngestJob1.getEntityType()).thenReturn(fileIngestJobExecutionType); when(fileIngestJob2.get(LOG)).thenReturn(null); when(fileIngestJob2.getEntityType()).thenReturn(fileIngestJobExecutionType); String hugeLog = RandomStringUtils.random(JobExecution.MAX_LOG_LENGTH - 10); when(fileIngestJob3.get(LOG)).thenReturn(hugeLog); when(fileIngestJob3.getEntityType()).thenReturn(fileIngestJobExecutionType); jobBootstrapper.bootstrap(); verify(fileIngestJob1).set(STATUS, FAILED); verify(fileIngestJob1).set(PROGRESS_MESSAGE, "Application terminated unexpectedly"); verify(fileIngestJob1).set(LOG, "Current log\nFAILED - Application terminated unexpectedly"); verify(fileIngestJob2).set(STATUS, FAILED); verify(fileIngestJob2).set(PROGRESS_MESSAGE, "Application terminated unexpectedly"); verify(fileIngestJob2).set(LOG, "FAILED - Application terminated unexpectedly"); verify(fileIngestJob3).set(STATUS, FAILED); verify(fileIngestJob3).set(PROGRESS_MESSAGE, "Application terminated unexpectedly"); verify(fileIngestJob3).set(eq(LOG), stringCaptor.capture()); String log3 = stringCaptor.getValue(); assertEquals( log3.length(), JobExecution.MAX_LOG_LENGTH, "Updated log length mustn't exceed MAX_LOG_LENGTH"); assertTrue( log3.contains(JobExecution.TRUNCATION_BANNER), "Updated log should contain truncation banner"); assertTrue(log3.endsWith("\nFAILED - Application terminated unexpectedly")); verify(dataService).update("sys_FileIngestJobExecution", fileIngestJob1); verify(dataService).update("sys_FileIngestJobExecution", fileIngestJob2); verify(jobScheduler).scheduleJobs(); verify(jobTypeRepo).upsertBatch(Collections.singletonList(scheduledJobType)); }
public void bootstrap() { LOGGER.trace("Failing JobExecutions that were left running..."); systemEntityTypeRegistry .getSystemEntityTypes() .filter(this::isJobExecution) .forEach(this::bootstrap); LOGGER.debug("Failed JobExecutions that were left running."); LOGGER.trace("Scheduling ScheduledJobs..."); jobScheduler.scheduleJobs(); LOGGER.debug("Scheduled ScheduledJobs."); LOGGER.trace("Upserting ScheduledJobTypes..."); upsertScheduledJobTypes(); LOGGER.debug("Upserted ScheduledJobTypes."); }
JobBootstrapper { public void bootstrap() { LOGGER.trace("Failing JobExecutions that were left running..."); systemEntityTypeRegistry .getSystemEntityTypes() .filter(this::isJobExecution) .forEach(this::bootstrap); LOGGER.debug("Failed JobExecutions that were left running."); LOGGER.trace("Scheduling ScheduledJobs..."); jobScheduler.scheduleJobs(); LOGGER.debug("Scheduled ScheduledJobs."); LOGGER.trace("Upserting ScheduledJobTypes..."); upsertScheduledJobTypes(); LOGGER.debug("Upserted ScheduledJobTypes."); } }
JobBootstrapper { public void bootstrap() { LOGGER.trace("Failing JobExecutions that were left running..."); systemEntityTypeRegistry .getSystemEntityTypes() .filter(this::isJobExecution) .forEach(this::bootstrap); LOGGER.debug("Failed JobExecutions that were left running."); LOGGER.trace("Scheduling ScheduledJobs..."); jobScheduler.scheduleJobs(); LOGGER.debug("Scheduled ScheduledJobs."); LOGGER.trace("Upserting ScheduledJobTypes..."); upsertScheduledJobTypes(); LOGGER.debug("Upserted ScheduledJobTypes."); } @Lazy  JobBootstrapper(
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      DataService dataService,
      JobScheduler jobScheduler,
      List<ScheduledJobType> scheduledJobTypes); }
JobBootstrapper { public void bootstrap() { LOGGER.trace("Failing JobExecutions that were left running..."); systemEntityTypeRegistry .getSystemEntityTypes() .filter(this::isJobExecution) .forEach(this::bootstrap); LOGGER.debug("Failed JobExecutions that were left running."); LOGGER.trace("Scheduling ScheduledJobs..."); jobScheduler.scheduleJobs(); LOGGER.debug("Scheduled ScheduledJobs."); LOGGER.trace("Upserting ScheduledJobTypes..."); upsertScheduledJobTypes(); LOGGER.debug("Upserted ScheduledJobTypes."); } @Lazy  JobBootstrapper(
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      DataService dataService,
      JobScheduler jobScheduler,
      List<ScheduledJobType> scheduledJobTypes); void bootstrap(); }
JobBootstrapper { public void bootstrap() { LOGGER.trace("Failing JobExecutions that were left running..."); systemEntityTypeRegistry .getSystemEntityTypes() .filter(this::isJobExecution) .forEach(this::bootstrap); LOGGER.debug("Failed JobExecutions that were left running."); LOGGER.trace("Scheduling ScheduledJobs..."); jobScheduler.scheduleJobs(); LOGGER.debug("Scheduled ScheduledJobs."); LOGGER.trace("Upserting ScheduledJobTypes..."); upsertScheduledJobTypes(); LOGGER.debug("Upserted ScheduledJobTypes."); } @Lazy  JobBootstrapper(
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      DataService dataService,
      JobScheduler jobScheduler,
      List<ScheduledJobType> scheduledJobTypes); void bootstrap();  }