Search in sources :

Example 6 with MapConfiguration

use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.

the class PinsetterKernelTest method clusteredShutdown.

@Test
public void clusteredShutdown() throws Exception {
    config = new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
            put(ConfigProperties.TASKS, ImportRecordJob.class.getName());
            put("org.quartz.jobStore.isClustered", "true");
        }
    });
    Set<JobKey> jobs = new HashSet<>();
    jobs.add(jobKey("fakejob1"));
    jobs.add(jobKey("fakejob2"));
    String crongrp = "cron group";
    String singlegrp = "async group";
    when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
    when(sched.getJobKeys(eq(jobGroupEquals(singlegrp)))).thenReturn(jobs);
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    pk.shutdown();
    verify(sched, atMost(1)).standby();
    verify(sched, never()).deleteJob(eq(jobKey("fakejob1", crongrp)));
    verify(sched, never()).deleteJob(eq(jobKey("fakejob2", crongrp)));
    verify(sched, never()).deleteJob(eq(jobKey("fakejob1", singlegrp)));
    verify(sched, never()).deleteJob(eq(jobKey("fakejob2", singlegrp)));
    verify(sched, atMost(1)).shutdown();
}
Also used : JobKey(org.quartz.JobKey) HashMap(java.util.HashMap) ImportRecordJob(org.candlepin.pinsetter.tasks.ImportRecordJob) MapConfiguration(org.candlepin.common.config.MapConfiguration) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with MapConfiguration

use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.

the class PinsetterKernelTest method deletedCronTask.

@Test
public void deletedCronTask() throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
    props.put("org.quartz.jobStore.isClustered", "true");
    props.put("pinsetter.org.candlepin.pinsetter.tasks.JobCleaner.schedule", "*/1 * * * * ?");
    Configuration config = new MapConfiguration(props);
    JobDetail jobDetail = mock(JobDetail.class);
    String crongrp = "cron group";
    Set<JobKey> jobs = new HashSet<>();
    String deletedJobId = "StatisticHistoryTask-taylor-swift";
    JobKey deletedKey = jobKey(deletedJobId);
    jobs.add(deletedKey);
    JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
    jobs.add(key);
    CronTrigger cronTrigger = mock(CronTrigger.class);
    when(cronTrigger.getJobKey()).thenReturn(deletedKey);
    when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
    when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
    when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
    doReturn(JobCleaner.class).when(jobDetail).getJobClass();
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    pk.startup();
    verify(jcurator).deleteJobNoStatusReturn(eq(deletedJobId));
    verify(sched, atLeastOnce()).deleteJob(deletedKey);
}
Also used : CronTrigger(org.quartz.CronTrigger) MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with MapConfiguration

use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.

the class PinsetterKernelTest method updateSchedule.

@Test
public void updateSchedule() throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
    props.put("org.quartz.jobStore.isClustered", "true");
    props.put("pinsetter.org.candlepin.pinsetter.tasks." + "JobCleaner.schedule", "*/1 * * * * ?");
    Configuration config = new MapConfiguration(props);
    JobDetail jobDetail = mock(JobDetail.class);
    String crongrp = "cron group";
    Set<JobKey> jobs = new HashSet<>();
    JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
    jobs.add(key);
    CronTrigger cronTrigger = mock(CronTrigger.class);
    when(cronTrigger.getJobKey()).thenReturn(key);
    when(cronTrigger.getCronExpression()).thenReturn("*/7 * * * * ?");
    when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
    when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
    when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
    doReturn(JobCleaner.class).when(jobDetail).getJobClass();
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    pk.startup();
    verify(sched).deleteJob(key);
    verify(jcurator).create(any(JobStatus.class));
}
Also used : CronTrigger(org.quartz.CronTrigger) MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) TriggerKey(org.quartz.TriggerKey) JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with MapConfiguration

use of org.candlepin.common.config.MapConfiguration in project candlepin by candlepin.

the class PinsetterKernelTest method clusteredStartupWithoutJobs.

@Test
public void clusteredStartupWithoutJobs() throws Exception {
    config = new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
            put(ConfigProperties.TASKS, ImportRecordJob.class.getName());
            put("org.quartz.jobStore.isClustered", "true");
        }
    });
    Set<JobKey> jobs = new HashSet<>();
    when(sched.getJobKeys(eq(jobGroupEquals("cron group")))).thenReturn(jobs);
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    pk.startup();
    verify(sched).start();
    verify(jcurator, atMost(2)).create(any(JobStatus.class));
    verify(sched, atMost(2)).scheduleJob(any(JobDetail.class), any(Trigger.class));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobKey(org.quartz.JobKey) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with MapConfiguration

use of org.candlepin.common.config.MapConfiguration 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)

Aggregations

MapConfiguration (org.candlepin.common.config.MapConfiguration)20 Test (org.junit.Test)16 HashMap (java.util.HashMap)15 JobCleaner (org.candlepin.pinsetter.tasks.JobCleaner)8 Configuration (org.candlepin.common.config.Configuration)7 JobDetail (org.quartz.JobDetail)7 HashSet (java.util.HashSet)6 CronTrigger (org.quartz.CronTrigger)6 JobKey (org.quartz.JobKey)6 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)5 ImportRecordJob (org.candlepin.pinsetter.tasks.ImportRecordJob)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 StringWriter (java.io.StringWriter)4 StandardTranslator (org.candlepin.dto.StandardTranslator)4 Before (org.junit.Before)3 Trigger (org.quartz.Trigger)3 TriggerKey (org.quartz.TriggerKey)3 File (java.io.File)2 StringReader (java.io.StringReader)2 Date (java.util.Date)2