Search in sources :

Example 46 with JobStatus

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

the class JobResourceTest method emptyStringIsAlsoValid.

@Test
public void emptyStringIsAlsoValid() {
    List<JobStatus> statuses = new ArrayList<>();
    JobStatus status = new JobStatus();
    statuses.add(status);
    CandlepinQuery query = mock(CandlepinQuery.class);
    when(query.list()).thenReturn(statuses);
    when(jobCurator.findByPrincipalName(eq("foo"))).thenReturn(query);
    when(query.transform(any(ElementTransformer.class))).thenReturn(query);
    jobResource.getStatuses(null, "", "foo");
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ElementTransformer(org.candlepin.util.ElementTransformer) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) Test(org.junit.Test)

Example 47 with JobStatus

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

the class HypervisorUpdateJobTest method monogamousJobTest.

/*
     * Make sure only one test is running at a time.
     */
@Test
public void monogamousJobTest() throws JobExecutionException, SchedulerException {
    JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
    JobStatus newJob = new JobStatus(detail);
    JobCurator jobCurator = mock(JobCurator.class);
    when(jobCurator.findNumRunningByClassAndTarget(owner.getKey(), HypervisorUpdateJob.class)).thenReturn(1L);
    assertFalse(HypervisorUpdateJob.isSchedulable(jobCurator, newJob));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobCurator(org.candlepin.model.JobCurator) Test(org.junit.Test)

Example 48 with JobStatus

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

the class HypervisorUpdateJobTest method dontSkipIfExistsTest.

/*
     * Schedule the job to be executed later even if a similar job exists.
     */
@Test
public void dontSkipIfExistsTest() throws JobExecutionException, SchedulerException {
    JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
    JobStatus preExistingJobStatus = new JobStatus();
    preExistingJobStatus.setState(JobState.WAITING);
    HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
    JobStatus newlyScheduledJobStatus = new JobStatus();
    JobCurator jobCurator = mock(JobCurator.class);
    Scheduler scheduler = mock(Scheduler.class);
    ListenerManager lm = mock(ListenerManager.class);
    when(jobCurator.getByClassAndTarget(anyString(), any(Class.class))).thenReturn(preExistingJobStatus);
    when(scheduler.getListenerManager()).thenReturn(lm);
    when(jobCurator.create(any(JobStatus.class))).thenReturn(newlyScheduledJobStatus);
    JobStatus resultStatus = job.scheduleJob(jobCurator, scheduler, detail, null);
    assertEquals(newlyScheduledJobStatus, resultStatus);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) Scheduler(org.quartz.Scheduler) JobCurator(org.candlepin.model.JobCurator) ListenerManager(org.quartz.ListenerManager) Test(org.junit.Test)

Example 49 with JobStatus

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

the class PinsetterKernelTest method unpauseScheduler.

@Test
public void unpauseScheduler() throws Exception {
    JobStatus mockStatus1 = mock(JobStatus.class);
    JobStatus mockStatus2 = mock(JobStatus.class);
    Set<JobStatus> statuses = Util.asSet(mockStatus1, mockStatus2);
    when(mockStatus1.getId()).thenReturn("group1");
    when(mockStatus1.getGroup()).thenReturn("group1");
    when(mockStatus2.getId()).thenReturn("group2");
    when(mockStatus2.getGroup()).thenReturn("group2");
    when(jcurator.findCanceledJobs(any(Collection.class))).thenReturn(statuses);
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    Set<JobKey> mockJK = new HashSet<>();
    JobKey jk = new JobKey("test key");
    mockJK.add(jk);
    when(pk.getSingleJobKeys()).thenReturn(mockJK);
    pk.unpauseScheduler();
    verify(jcurator).findCanceledJobs(any(Set.class));
    verify(sched).start();
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobKey(org.quartz.JobKey) HashSet(java.util.HashSet) Set(java.util.Set) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with JobStatus

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

the class CancelJobJobTest method cancelTest.

@Test
public void cancelTest() throws JobExecutionException, PinsetterException, SchedulerException {
    JobDetail jd1 = newJob(Job.class).withIdentity("Job1", "G1").build();
    JobDetail jd2 = newJob(Job.class).withIdentity("Job2", "G1").build();
    JobDetail jd3 = newJob(Job.class).withIdentity("Job1", "G2").build();
    List<JobDetail> jobDetailList = Arrays.asList(jd1, jd2, jd3);
    Set<JobStatus> jl = new HashSet<>();
    for (JobDetail jd : jobDetailList) {
        jl.add(new JobStatus(jd1));
    }
    Set<JobKey> jobKeys = new HashSet<>();
    jobKeys.add(new JobKey("G1"));
    jobKeys.add(new JobKey("G2"));
    when(pk.getSingleJobKeys()).thenReturn(jobKeys);
    when(j.findCanceledJobs(any(Collection.class))).thenReturn(jl);
    cancelJobJob.execute(ctx);
    verify(pk, atMost(1)).cancelJobs(eq(jl));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) Collection(java.util.Collection) HashSet(java.util.HashSet) 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