Search in sources :

Example 6 with JobStatus

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));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) HashMap(java.util.HashMap) ImportRecordJob(org.candlepin.pinsetter.tasks.ImportRecordJob) MapConfiguration(org.candlepin.common.config.MapConfiguration) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) Test(org.junit.Test)

Example 7 with JobStatus

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);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDataMap(org.quartz.JobDataMap) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 8 with JobStatus

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));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) Test(org.junit.Test)

Example 9 with JobStatus

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);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobExecutionException(org.quartz.JobExecutionException) Test(org.junit.Test)

Example 10 with JobStatus

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));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) Test(org.junit.Test)

Aggregations

JobStatus (org.candlepin.pinsetter.core.model.JobStatus)56 Test (org.junit.Test)43 JobDetail (org.quartz.JobDetail)22 JobKey (org.quartz.JobKey)10 ArrayList (java.util.ArrayList)7 CandlepinQuery (org.candlepin.model.CandlepinQuery)7 JobDataMap (org.quartz.JobDataMap)7 JobExecutionException (org.quartz.JobExecutionException)7 Trigger (org.quartz.Trigger)6 JobStatusDTO (org.candlepin.dto.api.v1.JobStatusDTO)5 TransformedCandlepinQuery (org.candlepin.model.TransformedCandlepinQuery)5 SchedulerException (org.quartz.SchedulerException)5 Principal (org.candlepin.auth.Principal)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)3 JobCurator (org.candlepin.model.JobCurator)3 MockResultIterator (org.candlepin.test.MockResultIterator)3 CronTrigger (org.quartz.CronTrigger)3 Transactional (com.google.inject.persist.Transactional)2