Search in sources :

Example 11 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class PinsetterJobListenerTest method handleException.

@Test
public void handleException() {
    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);
    when(e.getMessage()).thenReturn("job errored");
    listener.jobWasExecuted(ctx, e);
    verify(status).setState(eq(JobState.FAILED));
    verify(status).setResult(eq("job errored"));
    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 12 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class PinsetterTriggerListenerTest method triggerMisfireDontRunAgain.

@Test
public void triggerMisfireDontRunAgain() {
    PinsetterTriggerListener ptl = new PinsetterTriggerListener(modeManager, jobCurator);
    Trigger trigger = mock(Trigger.class);
    JobStatus jobStatus = new JobStatus();
    JobKey jobKey = new JobKey("mockName");
    when(trigger.mayFireAgain()).thenReturn(false);
    when(trigger.getJobKey()).thenReturn(jobKey);
    when(jobCurator.find(Matchers.anyString())).thenReturn(jobStatus);
    ptl.triggerMisfired(trigger);
    assert (jobStatus.getResult().startsWith("Failed run. Will not attempt again."));
    assert (jobStatus.getState().equals(JobStatus.JobState.FAILED));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 13 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class JobCuratorTest method correlationIdOnStatus.

@Test
public void correlationIdOnStatus() {
    JobStatus job = newJobStatus().principalName("donald").owner("ducks").create();
    assertEquals("test-csid", job.getCorrelationId());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 14 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class JobCuratorTest method findByConsumerUuidRestrictsByOwnerWhenRequestedByBasicUser.

@Test
public void findByConsumerUuidRestrictsByOwnerWhenRequestedByBasicUser() {
    newJobStatus().principalName("p1").consumer("c1", "owner1").create();
    newJobStatus().principalName("p4").owner("owner2").create();
    JobStatus job = newJobStatus().principalName("p3").consumer("c2", "owner1").create();
    // Technically this case should not happen since a consumer
    // can belong to one org, but adding just to make sure that
    // it gets filtered.
    newJobStatus().principalName("p2").consumer("c2", "owner2").create();
    setupPrincipal("goofy", new Owner("owner1"), Access.READ_ONLY);
    List<JobStatus> found = curator.findByConsumerUuid("c2").list();
    assertEquals(1, found.size());
    assertEquals(job, found.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 15 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class JobCuratorTest method findByUserFiltersByOwnerAccessAndUUIDWhenRequestedByConsumer.

@Test
public void findByUserFiltersByOwnerAccessAndUUIDWhenRequestedByConsumer() {
    Owner owner = new Owner("testowner");
    owner.setId(TestUtil.randomString());
    Consumer consumer = TestUtil.createConsumer(owner);
    JobStatus job = newJobStatus().principalName(consumer.getUuid()).owner(owner.getKey()).create();
    newJobStatus().principalName("p1").owner("owner1").create();
    newJobStatus().principalName("p2").owner("owner1").create();
    newJobStatus().principalName("p3").owner("owner2").create();
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    assertTrue(this.curator.findByOwnerKey("owner1").list().isEmpty());
    assertTrue(this.curator.findByOwnerKey("owner2").list().isEmpty());
    List<JobStatus> found = this.curator.findByOwnerKey("testowner").list();
    assertEquals(1, found.size());
    assertEquals(job, found.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) 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