@SuppressWarnings("unchecked") @Test void testExecuteScheduledJob() { String scheduledJobId = "MyScheduledJobId"; EntityType jobExecutionType = mock(EntityType.class); ScheduledJobType scheduledJobType = mock(ScheduledJobType.class); when(scheduledJobType.getJobExecutionType()).thenReturn(jobExecutionType); ScheduledJob scheduledJob = mock(ScheduledJob.class); when(scheduledJob.getType()).thenReturn(scheduledJobType); when(dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class)) .thenReturn(scheduledJob); String jobExecutionEntityTypeId = "MyJobExecutionId"; EntityType jobExecutionEntityType = mock(EntityType.class); when(jobExecutionEntityType.getId()).thenReturn(jobExecutionEntityTypeId); JobExecution jobExecution = mock(JobExecution.class); when(jobExecution.getEntityType()).thenReturn(jobExecutionEntityType); when(entityManager.create(jobExecutionType, POPULATE)).thenReturn(jobExecution); Job job = mock(Job.class); JobFactory jobFactory = mock(JobFactory.class); when(jobFactoryRegistry.getJobFactory(jobExecution)).thenReturn(jobFactory); when(jobFactory.createJob(jobExecution)).thenReturn(job); JobExecutionContext jobExecutionContext = mock(JobExecutionContext.class); when(jobExecutionContextFactory.createJobExecutionContext(jobExecution)) .thenReturn(jobExecutionContext); Progress progress = mock(Progress.class); when(jobExecutionRegistry.registerJobExecution(jobExecution)).thenReturn(progress); jobExecutor.executeScheduledJob(scheduledJobId); verify(dataService).add(jobExecutionEntityTypeId, jobExecution); verify(jobExecutionTemplate).call(job, progress, jobExecutionContext); verify(jobExecutionRegistry).unregisterJobExecution(jobExecution); }
@RunAsSystem public void executeScheduledJob(String scheduledJobId) { ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class); if (scheduledJob == null) { throw new UnknownEntityException(SCHEDULED_JOB, scheduledJobId); } JobExecution jobExecution = createJobExecution(scheduledJob); Job molgenisJob = saveExecutionAndCreateJob(jobExecution); Progress progress = jobExecutionRegistry.registerJobExecution(jobExecution); try { long callingThreadId = Thread.currentThread().getId(); runJob(jobExecution, molgenisJob, progress, callingThreadId); } catch (Exception ex) { handleJobException(jobExecution, ex); } finally { jobExecutionRegistry.unregisterJobExecution(jobExecution); } }
JobExecutor { @RunAsSystem public void executeScheduledJob(String scheduledJobId) { ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class); if (scheduledJob == null) { throw new UnknownEntityException(SCHEDULED_JOB, scheduledJobId); } JobExecution jobExecution = createJobExecution(scheduledJob); Job molgenisJob = saveExecutionAndCreateJob(jobExecution); Progress progress = jobExecutionRegistry.registerJobExecution(jobExecution); try { long callingThreadId = Thread.currentThread().getId(); runJob(jobExecution, molgenisJob, progress, callingThreadId); } catch (Exception ex) { handleJobException(jobExecution, ex); } finally { jobExecutionRegistry.unregisterJobExecution(jobExecution); } } }
JobExecutor { @RunAsSystem public void executeScheduledJob(String scheduledJobId) { ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class); if (scheduledJob == null) { throw new UnknownEntityException(SCHEDULED_JOB, scheduledJobId); } JobExecution jobExecution = createJobExecution(scheduledJob); Job molgenisJob = saveExecutionAndCreateJob(jobExecution); Progress progress = jobExecutionRegistry.registerJobExecution(jobExecution); try { long callingThreadId = Thread.currentThread().getId(); runJob(jobExecution, molgenisJob, progress, callingThreadId); } catch (Exception ex) { handleJobException(jobExecution, ex); } finally { jobExecutionRegistry.unregisterJobExecution(jobExecution); } } JobExecutor(
      DataService dataService,
      EntityManager entityManager,
      ExecutorService executorService,
      JobFactoryRegistry jobFactoryRegistry,
      JobExecutionContextFactory jobExecutionContextFactory,
      JobExecutionRegistry jobExecutionRegistry); }
JobExecutor { @RunAsSystem public void executeScheduledJob(String scheduledJobId) { ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class); if (scheduledJob == null) { throw new UnknownEntityException(SCHEDULED_JOB, scheduledJobId); } JobExecution jobExecution = createJobExecution(scheduledJob); Job molgenisJob = saveExecutionAndCreateJob(jobExecution); Progress progress = jobExecutionRegistry.registerJobExecution(jobExecution); try { long callingThreadId = Thread.currentThread().getId(); runJob(jobExecution, molgenisJob, progress, callingThreadId); } catch (Exception ex) { handleJobException(jobExecution, ex); } finally { jobExecutionRegistry.unregisterJobExecution(jobExecution); } } JobExecutor(
      DataService dataService,
      EntityManager entityManager,
      ExecutorService executorService,
      JobFactoryRegistry jobFactoryRegistry,
      JobExecutionContextFactory jobExecutionContextFactory,
      JobExecutionRegistry jobExecutionRegistry); @RunAsSystem void executeScheduledJob(String scheduledJobId); CompletableFuture<Void> submit(JobExecution jobExecution); CompletableFuture<Void> submit(
      JobExecution jobExecution, ExecutorService executorService); void cancel(JobExecution jobExecution); }
JobExecutor { @RunAsSystem public void executeScheduledJob(String scheduledJobId) { ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class); if (scheduledJob == null) { throw new UnknownEntityException(SCHEDULED_JOB, scheduledJobId); } JobExecution jobExecution = createJobExecution(scheduledJob); Job molgenisJob = saveExecutionAndCreateJob(jobExecution); Progress progress = jobExecutionRegistry.registerJobExecution(jobExecution); try { long callingThreadId = Thread.currentThread().getId(); runJob(jobExecution, molgenisJob, progress, callingThreadId); } catch (Exception ex) { handleJobException(jobExecution, ex); } finally { jobExecutionRegistry.unregisterJobExecution(jobExecution); } } JobExecutor(
      DataService dataService,
      EntityManager entityManager,
      ExecutorService executorService,
      JobFactoryRegistry jobFactoryRegistry,
      JobExecutionContextFactory jobExecutionContextFactory,
      JobExecutionRegistry jobExecutionRegistry); @RunAsSystem void executeScheduledJob(String scheduledJobId); CompletableFuture<Void> submit(JobExecution jobExecution); CompletableFuture<Void> submit(
      JobExecution jobExecution, ExecutorService executorService); void cancel(JobExecution jobExecution);  }