use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class UniqueByEntityJobTest method skipIfExistsTest.
/*
* if a UniqueByEntityJob's skipIfExists is true, don't schedule another job
*/
@Test
public void skipIfExistsTest() throws JobExecutionException, SchedulerException {
JobDataMap map = new JobDataMap();
map.put(JobStatus.TARGET_ID, "TaylorSwift");
JobKey jobKey = new JobKey("name", "group");
JobDetail detail = newJob(TestUniqueByEntityJob.class).withIdentity(jobKey).requestRecovery(true).usingJobData(map).storeDurably(true).build();
JobStatus preExistingJobStatus = new JobStatus();
preExistingJobStatus.setState(JobState.WAITING);
TestUniqueByEntityJob job = new TestUniqueByEntityJob();
when(jobCurator.getByClassAndTarget(eq("TaylorSwift"), any(Class.class))).thenReturn(preExistingJobStatus);
JobStatus resultStatus = job.scheduleJob(jobCurator, null, detail, null);
assertEquals(preExistingJobStatus, resultStatus);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListenerTest method ensureProperLengthOfResult.
@Test
public void ensureProperLengthOfResult() {
JobExecutionException e = mock(JobExecutionException.class);
JobDetail detail = mock(JobDetail.class);
JobStatus status = mock(JobStatus.class);
when(detail.getKey()).thenReturn(jobKey("foo"));
when(ctx.getJobDetail()).thenReturn(detail);
when(jcurator.find(eq("foo"))).thenReturn(status);
String longstr = RandomStringUtils.randomAlphanumeric(JobStatus.RESULT_COL_LENGTH);
when(e.getMessage()).thenReturn(longstr);
listener.jobWasExecuted(ctx, e);
verify(status).setState(eq(JobState.FAILED));
verify(status).setResult(eq(longstr));
verify(status, never()).update(eq(ctx));
verify(jcurator).merge(eq(status));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListenerTest method tobeExecuted.
@Test
public void tobeExecuted() {
Principal principal = mock(Principal.class);
JobDataMap map = new JobDataMap();
JobDetail detail = mock(JobDetail.class);
JobStatus status = mock(JobStatus.class);
map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
when(ctx.getMergedJobDataMap()).thenReturn(map);
when(detail.getKey()).thenReturn(jobKey("foo"));
when(ctx.getJobDetail()).thenReturn(detail);
when(jcurator.find(eq("foo"))).thenReturn(status);
listener.jobToBeExecuted(ctx);
verify(status).update(eq(ctx));
verify(jcurator).merge(eq(status));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListenerTest method handleNullException.
@Test
public void handleNullException() {
JobStatus status = mock(JobStatus.class);
JobDetail detail = mock(JobDetail.class);
when(detail.getKey()).thenReturn(jobKey("foo"));
when(ctx.getJobDetail()).thenReturn(detail);
when(jcurator.find(eq("foo"))).thenReturn(status);
listener.jobWasExecuted(ctx, null);
verify(status).update(eq(ctx));
verify(jcurator).merge(eq(status));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListenerTest method tobeExecutedNull.
@Test
public void tobeExecutedNull() {
Principal principal = mock(Principal.class);
JobDataMap map = new JobDataMap();
JobDetail detail = mock(JobDetail.class);
JobStatus status = mock(JobStatus.class);
map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
when(ctx.getMergedJobDataMap()).thenReturn(map);
when(detail.getKey()).thenReturn(jobKey("foo"));
when(ctx.getJobDetail()).thenReturn(detail);
when(jcurator.find(eq("foo"))).thenReturn(null);
listener.jobToBeExecuted(ctx);
verifyZeroInteractions(status);
verify(jcurator, never()).merge(eq(status));
}
Aggregations