use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method emptyStringIsAlsoValid.
@Test
public void emptyStringIsAlsoValid() {
List<JobStatus> statuses = new ArrayList<>();
JobStatus status = new JobStatus();
statuses.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(statuses);
when(jobCurator.findByPrincipalName(eq("foo"))).thenReturn(query);
when(query.transform(any(ElementTransformer.class))).thenReturn(query);
jobResource.getStatuses(null, "", "foo");
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class HypervisorUpdateJobTest method monogamousJobTest.
/*
* Make sure only one test is running at a time.
*/
@Test
public void monogamousJobTest() throws JobExecutionException, SchedulerException {
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobStatus newJob = new JobStatus(detail);
JobCurator jobCurator = mock(JobCurator.class);
when(jobCurator.findNumRunningByClassAndTarget(owner.getKey(), HypervisorUpdateJob.class)).thenReturn(1L);
assertFalse(HypervisorUpdateJob.isSchedulable(jobCurator, newJob));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class HypervisorUpdateJobTest method dontSkipIfExistsTest.
/*
* Schedule the job to be executed later even if a similar job exists.
*/
@Test
public void dontSkipIfExistsTest() throws JobExecutionException, SchedulerException {
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobStatus preExistingJobStatus = new JobStatus();
preExistingJobStatus.setState(JobState.WAITING);
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
JobStatus newlyScheduledJobStatus = new JobStatus();
JobCurator jobCurator = mock(JobCurator.class);
Scheduler scheduler = mock(Scheduler.class);
ListenerManager lm = mock(ListenerManager.class);
when(jobCurator.getByClassAndTarget(anyString(), any(Class.class))).thenReturn(preExistingJobStatus);
when(scheduler.getListenerManager()).thenReturn(lm);
when(jobCurator.create(any(JobStatus.class))).thenReturn(newlyScheduledJobStatus);
JobStatus resultStatus = job.scheduleJob(jobCurator, scheduler, detail, null);
assertEquals(newlyScheduledJobStatus, resultStatus);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterKernelTest method unpauseScheduler.
@Test
public void unpauseScheduler() throws Exception {
JobStatus mockStatus1 = mock(JobStatus.class);
JobStatus mockStatus2 = mock(JobStatus.class);
Set<JobStatus> statuses = Util.asSet(mockStatus1, mockStatus2);
when(mockStatus1.getId()).thenReturn("group1");
when(mockStatus1.getGroup()).thenReturn("group1");
when(mockStatus2.getId()).thenReturn("group2");
when(mockStatus2.getGroup()).thenReturn("group2");
when(jcurator.findCanceledJobs(any(Collection.class))).thenReturn(statuses);
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
Set<JobKey> mockJK = new HashSet<>();
JobKey jk = new JobKey("test key");
mockJK.add(jk);
when(pk.getSingleJobKeys()).thenReturn(mockJK);
pk.unpauseScheduler();
verify(jcurator).findCanceledJobs(any(Set.class));
verify(sched).start();
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class CancelJobJobTest method cancelTest.
@Test
public void cancelTest() throws JobExecutionException, PinsetterException, SchedulerException {
JobDetail jd1 = newJob(Job.class).withIdentity("Job1", "G1").build();
JobDetail jd2 = newJob(Job.class).withIdentity("Job2", "G1").build();
JobDetail jd3 = newJob(Job.class).withIdentity("Job1", "G2").build();
List<JobDetail> jobDetailList = Arrays.asList(jd1, jd2, jd3);
Set<JobStatus> jl = new HashSet<>();
for (JobDetail jd : jobDetailList) {
jl.add(new JobStatus(jd1));
}
Set<JobKey> jobKeys = new HashSet<>();
jobKeys.add(new JobKey("G1"));
jobKeys.add(new JobKey("G2"));
when(pk.getSingleJobKeys()).thenReturn(jobKeys);
when(j.findCanceledJobs(any(Collection.class))).thenReturn(jl);
cancelJobJob.execute(ctx);
verify(pk, atMost(1)).cancelJobs(eq(jl));
}
Aggregations