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();
}
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);
}
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));
}
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));
}
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));
}
Aggregations