Search in sources :

Example 16 with JobManager

use of org.apache.sling.event.jobs.JobManager in project sling by apache.

the class JobHandlingDistributionQueueTest method testPackageAddition.

@SuppressWarnings("unchecked")
@Test
public void testPackageAddition() throws Exception {
    JobManager jobManager = mock(JobManager.class);
    JobBuilder builder = mock(JobBuilder.class);
    when(builder.properties(any(Map.class))).thenReturn(builder);
    Job job = mock(Job.class);
    when(job.getId()).thenReturn("id-123");
    when(builder.add()).thenReturn(job);
    String topic = JobHandlingDistributionQueue.DISTRIBUTION_QUEUE_TOPIC + "/aname";
    when(jobManager.createJob(topic)).thenReturn(builder);
    when(jobManager.findJobs(JobManager.QueryType.ALL, topic, -1)).thenReturn(Collections.<Job>emptySet());
    when(builder.properties(any(Map.class))).thenReturn(builder);
    DistributionQueue queue = new JobHandlingDistributionQueue("aname", topic, jobManager, true, DistributionQueueType.ORDERED);
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
    packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/foo" });
    packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD);
    DistributionQueueItem distributionQueueItem = new DistributionQueueItem("an-id", packageInfo);
    assertNotNull(queue.add(distributionQueueItem));
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) JobBuilder(org.apache.sling.event.jobs.JobBuilder) JobManager(org.apache.sling.event.jobs.JobManager) Matchers.anyString(org.mockito.Matchers.anyString) Job(org.apache.sling.event.jobs.Job) Map(java.util.Map) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 17 with JobManager

use of org.apache.sling.event.jobs.JobManager in project sling by apache.

the class JobHandlingDistributionQueueProviderTest method testEnableQueueProcessing.

@Test
public void testEnableQueueProcessing() throws Exception {
    JobManager jobManager = mock(JobManager.class);
    ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
    Configuration config = mock(Configuration.class);
    when(configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null)).thenReturn(config);
    BundleContext context = mock(BundleContext.class);
    JobHandlingDistributionQueueProvider jobHandlingdistributionQueueProvider = new JobHandlingDistributionQueueProvider("dummy-agent", jobManager, context);
    DistributionQueueProcessor queueProcessor = mock(DistributionQueueProcessor.class);
    jobHandlingdistributionQueueProvider.enableQueueProcessing(queueProcessor);
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) Configuration(org.osgi.service.cm.Configuration) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) JobManager(org.apache.sling.event.jobs.JobManager) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

JobManager (org.apache.sling.event.jobs.JobManager)17 Test (org.junit.Test)16 Job (org.apache.sling.event.jobs.Job)12 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Event (org.osgi.service.event.Event)7 EventHandler (org.osgi.service.event.EventHandler)7 HashMap (java.util.HashMap)6 Barrier (org.apache.sling.event.impl.Barrier)6 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)3 Queue (org.apache.sling.event.jobs.Queue)3 BundleContext (org.osgi.framework.BundleContext)3 IOException (java.io.IOException)2 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)2 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)2 JobBuilder (org.apache.sling.event.jobs.JobBuilder)2 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)2