@Test public void removeJobAfterRemovedFromDB() throws Exception { String repoName = givenSchedulerWithOneRunningJob(); context .repoEntriesRepository() .delete(context.repoEntriesRepository().findFirstByName(repoName).getId()); RepoMetadataGeneratorJob existingJob = schedulerJob.getRepoJobs().get(repoName); assertThat(existingJob.isActive(), is(true)); schedulerJob.update(); assertThat(schedulerJob.getRepoJobs().get(repoName), nullValue()); assertThat(existingJob.isActive(), is(false)); }
private String givenSchedulerWithOneRunningJob() { String repoName = uniqueRepoName(); RepoEntry entry = new RepoEntry(); entry.setName(repoName); entry.setType(SCHEDULED); context.repoEntriesRepository().save(entry); schedulerJob.update(); return repoName; }
@Before @SuppressWarnings("unchecked") public void setUp() throws UnknownHostException { RepoMdGenerator repoMdGenerator = new RepoMdGenerator(context.gridFs()); MetadataService metadataService = context.metadataService(); MongoPrimaryDetector primaryDetector = new MongoPrimaryDetector(context.getMongo()); ScheduledFuture<Void> scheduledFuture = mock(ScheduledFuture.class); TaskScheduler taskScheduler = mock(TaskScheduler.class); when(taskScheduler.scheduleWithFixedDelay(any(Runnable.class), anyLong())) .thenReturn(scheduledFuture); schedulerJob = new RepoMetadataSchedulerJob( context.repoEntriesRepository(), metadataService, primaryDetector, taskScheduler, DELAY); }