Search in sources :

Example 16 with MapConfiguration

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

the class ProductExporterTest method testProductExport.

@Test
public void testProductExport() throws IOException {
    ObjectMapper mapper = TestSyncUtils.getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() {

        {
            put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false");
        }
    }));
    ProductExporter exporter = new ProductExporter(new StandardTranslator(new ConsumerTypeCurator(), new EnvironmentCurator(), new OwnerCurator()));
    StringWriter writer = new StringWriter();
    Owner owner = TestUtil.createOwner("Example-Corporation");
    Product product = TestUtil.createProduct("my-id", "product name");
    exporter.export(mapper, writer, product);
    String s = writer.toString();
    assertTrue(s.contains("\"name\":\"product name\""));
    assertTrue(s.contains("\"id\":\"my-id\""));
    assertTrue(s.contains("\"productContent\":[]"));
    assertTrue(s.contains("\"attributes\":[]"));
    assertTrue(s.contains("\"multiplier\":1"));
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MapConfiguration(org.candlepin.common.config.MapConfiguration) Product(org.candlepin.model.Product) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) StandardTranslator(org.candlepin.dto.StandardTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with MapConfiguration

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

the class ProductResourceTest method testRefreshPoolsByProduct.

@Test
public void testRefreshPoolsByProduct() {
    Configuration config = new MapConfiguration(this.config);
    config.setProperty(ConfigProperties.STANDALONE, "false");
    ProductResource productResource = new ProductResource(this.productCurator, this.ownerCurator, this.productCertificateCurator, config, this.i18n, this.modelTranslator);
    List<Owner> owners = this.setupDBForOwnerProdTests();
    Owner owner1 = owners.get(0);
    Owner owner2 = owners.get(1);
    Owner owner3 = owners.get(2);
    JobDetail[] jobs;
    jobs = productResource.refreshPoolsForProduct(Arrays.asList("p1"), true);
    assertNotNull(jobs);
    assertEquals(2, jobs.length);
    this.verifyRefreshPoolsJobs(jobs, Arrays.asList(owner1, owner2), true);
    jobs = productResource.refreshPoolsForProduct(Arrays.asList("p1", "p2"), false);
    assertNotNull(jobs);
    assertEquals(3, jobs.length);
    this.verifyRefreshPoolsJobs(jobs, Arrays.asList(owner1, owner2, owner3), false);
    jobs = productResource.refreshPoolsForProduct(Arrays.asList("p3"), false);
    assertNotNull(jobs);
    assertEquals(1, jobs.length);
    this.verifyRefreshPoolsJobs(jobs, Arrays.asList(owner3), false);
    jobs = productResource.refreshPoolsForProduct(Arrays.asList("nope"), false);
    assertNotNull(jobs);
    assertEquals(0, jobs.length);
}
Also used : Owner(org.candlepin.model.Owner) JobDetail(org.quartz.JobDetail) MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) MapConfiguration(org.candlepin.common.config.MapConfiguration) Test(org.junit.Test)

Example 18 with MapConfiguration

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

the class PinsetterKernelTest method updateMultipleSchedules.

@Test
public void updateMultipleSchedules() 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);
    // Hack multiple job schedules for same job:
    String crongrp = "cron group";
    Set<JobKey> jobs = new HashSet<>();
    JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
    jobs.add(key);
    JobKey key2 = jobKey("org.candlepin.pinsetter.tasks.JobCleaner2");
    jobs.add(key2);
    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, times(2)).deleteJob(any(JobKey.class));
    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 19 with MapConfiguration

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

the class PinsetterKernelTest method clusteredStartupWithJobs.

@Test
public void clusteredStartupWithJobs() 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(JobCleaner.class.getName()));
    jobs.add(jobKey(ImportRecordJob.class.getName()));
    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 20 with MapConfiguration

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

the class PinsetterKernelTest method init.

@Before
public void init() throws SchedulerException {
    sched = mock(Scheduler.class);
    jfactory = mock(JobFactory.class);
    jcurator = mock(JobCurator.class);
    jlistener = mock(JobListener.class);
    sfactory = mock(StdSchedulerFactory.class);
    lm = mock(ListenerManager.class);
    modeManager = mock(ModeManager.class);
    triggerListener = mock(PinsetterTriggerListener.class);
    config = new MapConfiguration(new HashMap<String, String>() {

        {
            put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
            put("org.quartz.threadPool.threadCount", "25");
            put("org.quartz.threadPool.threadPriority", "5");
            put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
            put(ConfigProperties.TASKS, ImportRecordJob.class.getName());
        }
    });
    when(sfactory.getScheduler()).thenReturn(sched);
    when(sched.getListenerManager()).thenReturn(lm);
    when(modeManager.getLastCandlepinModeChange()).thenReturn(new CandlepinModeChange(new Date(System.currentTimeMillis()), CandlepinModeChange.Mode.NORMAL, CandlepinModeChange.Reason.STARTUP));
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) HashMap(java.util.HashMap) ImportRecordJob(org.candlepin.pinsetter.tasks.ImportRecordJob) Scheduler(org.quartz.Scheduler) MapConfiguration(org.candlepin.common.config.MapConfiguration) JobListener(org.quartz.JobListener) Date(java.util.Date) JobCurator(org.candlepin.model.JobCurator) JobFactory(org.quartz.spi.JobFactory) JobCleaner(org.candlepin.pinsetter.tasks.JobCleaner) CandlepinModeChange(org.candlepin.model.CandlepinModeChange) ListenerManager(org.quartz.ListenerManager) ModeManager(org.candlepin.controller.ModeManager) Before(org.junit.Before)

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