Search in sources :

Example 51 with JobStatus

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

Example 52 with JobStatus

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

Example 53 with JobStatus

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

Example 54 with JobStatus

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

Example 55 with JobStatus

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