use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterKernelTest method disablePinsetter.
@Test
public void disablePinsetter() throws Exception {
config = new MapConfiguration(new HashMap<String, String>() {
{
put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
put(ConfigProperties.TASKS, ImportRecordJob.class.getName());
put(ConfigProperties.ENABLE_PINSETTER, "false");
}
});
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
pk.startup();
verify(sched).start();
ArgumentCaptor<JobStatus> arg = ArgumentCaptor.forClass(JobStatus.class);
verify(jcurator, atMost(1)).create(arg.capture());
JobStatus stat = arg.getValue();
assertTrue(stat.getId().startsWith(Util.getClassName(CancelJobJob.class)));
verify(sched, atMost(1)).scheduleJob(any(JobDetail.class), any(Trigger.class));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class UniqueByEntityJobTest method failsCreationGracefullyTest.
/*
* if a job creation fails, ensure we update status and re-throw the runtime exception
*/
@Test
public void failsCreationGracefullyTest() 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.create(any(JobStatus.class))).thenReturn(status);
when(scheduler.getListenerManager()).thenReturn(lm);
when(scheduler.scheduleJob(any(JobDetail.class), any(Trigger.class))).thenThrow(new RuntimeException("covfefe"));
try {
job.scheduleJob(jobCurator, scheduler, detail, t);
fail();
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "covfefe");
}
verify(status, times(1)).setState(JobState.FAILED);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListenerTest method executed.
@Test
public void executed() {
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);
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 executedNullStatus.
@Test
public void executedNullStatus() {
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(null);
listener.jobWasExecuted(ctx, e);
verifyZeroInteractions(status);
verify(jcurator, never()).merge(eq(status));
verifyZeroInteractions(e);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterJobListenerTest method handleResultTooLong.
@Test
public void handleResultTooLong() {
JobExecutionException e = mock(JobExecutionException.class);
JobDetail detail = mock(JobDetail.class);
JobDataMap map = new JobDataMap();
map.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
when(detail.getKey()).thenReturn(jobKey("name", "group"));
when(detail.getJobDataMap()).thenReturn(map);
when(ctx.getJobDetail()).thenReturn(detail);
JobStatus status = new JobStatus(detail);
when(jcurator.find(eq("name"))).thenReturn(status);
String longstr = RandomStringUtils.randomAlphanumeric(300);
when(e.getMessage()).thenReturn(longstr);
listener.jobWasExecuted(ctx, e);
assertEquals(longstr.substring(0, JobStatus.RESULT_COL_LENGTH), status.getResult());
assertEquals(JobState.FAILED, status.getState());
verify(jcurator).merge(eq(status));
}
Aggregations