Search in sources :

Example 6 with DistributionQueueProcessor

use of org.apache.sling.distribution.queue.DistributionQueueProcessor in project sling by apache.

the class SimpleDistributionQueueProviderTest method testEnableQueueProcessingWithCheckpointRecovery.

@Test
public void testEnableQueueProcessingWithCheckpointRecovery() throws Exception {
    File checkpointDirectory = new File("dummy-agent-simple-queues-checkpoints");
    File file = new File(getClass().getResource("/dummy-agent-checkpoint").getFile());
    FileUtils.copyFileToDirectory(file, checkpointDirectory);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 1)).thenReturn(options);
    when(scheduler.NOW(-1, 15)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    String name = "dummy-agent";
    try {
        SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, name, true);
        DistributionQueueProcessor processor = mock(DistributionQueueProcessor.class);
        simpledistributionQueueProvider.enableQueueProcessing(processor, name);
        DistributionQueue queue = simpledistributionQueueProvider.getQueue(name);
        assertNotNull(queue);
        assertEquals(1, queue.getStatus().getItemsCount());
        DistributionQueueEntry head = queue.getHead();
        assertNotNull(head);
        DistributionQueueItem item = head.getItem();
        assertNotNull(item);
        String packageId = item.getPackageId();
        assertNotNull(packageId);
        assertEquals("DSTRQ1", item.get("internal.request.id"));
        assertArrayEquals(new String[] { "/foo", "bar" }, (String[]) item.get("request.paths"));
        assertArrayEquals(new String[] { "/foo" }, (String[]) item.get("request.deepPaths"));
        assertEquals("admin", item.get("internal.request.user"));
        assertEquals("ADD", item.get("request.type"));
        assertEquals("default", item.get("package.type"));
        assertEquals("1464090250095", item.get("internal.request.startTime"));
    } finally {
        FileUtils.deleteDirectory(new File(name + "-simple-queues-checkpoints"));
    }
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) Scheduler(org.apache.sling.commons.scheduler.Scheduler) File(java.io.File) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 7 with DistributionQueueProcessor

use of org.apache.sling.distribution.queue.DistributionQueueProcessor in project sling by apache.

the class DistributionAgentJobConsumerTest method testJobWithSuccessfulAgent.

@Test
public void testJobWithSuccessfulAgent() throws Exception {
    DistributionQueueProcessor queueProcessor = mock(DistributionQueueProcessor.class);
    when(queueProcessor.process(anyString(), any(DistributionQueueEntry.class))).thenReturn(true);
    DistributionAgentJobConsumer distributionAgentJobConsumer = new DistributionAgentJobConsumer(queueProcessor);
    Job job = mock(Job.class);
    JobConsumer.JobResult jobResult = distributionAgentJobConsumer.process(job);
    assertEquals(JobConsumer.JobResult.OK, jobResult);
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) JobConsumer(org.apache.sling.event.jobs.consumer.JobConsumer) Job(org.apache.sling.event.jobs.Job) Test(org.junit.Test)

Example 8 with DistributionQueueProcessor

use of org.apache.sling.distribution.queue.DistributionQueueProcessor in project sling by apache.

the class DistributionAgentJobConsumerTest method testJobWithUnsuccessfulAgent.

@Test
public void testJobWithUnsuccessfulAgent() throws Exception {
    DistributionQueueProcessor queueProcessor = mock(DistributionQueueProcessor.class);
    when(queueProcessor.process(anyString(), any(DistributionQueueEntry.class))).thenReturn(false);
    DistributionAgentJobConsumer distributionAgentJobConsumer = new DistributionAgentJobConsumer(queueProcessor);
    Job job = mock(Job.class);
    JobConsumer.JobResult jobResult = distributionAgentJobConsumer.process(job);
    assertEquals(JobConsumer.JobResult.FAILED, jobResult);
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) JobConsumer(org.apache.sling.event.jobs.consumer.JobConsumer) Job(org.apache.sling.event.jobs.Job) Test(org.junit.Test)

Example 9 with DistributionQueueProcessor

use of org.apache.sling.distribution.queue.DistributionQueueProcessor 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

DistributionQueueProcessor (org.apache.sling.distribution.queue.DistributionQueueProcessor)9 Test (org.junit.Test)9 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)4 ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)3 Scheduler (org.apache.sling.commons.scheduler.Scheduler)3 File (java.io.File)2 LinkedList (java.util.LinkedList)2 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)2 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)2 Job (org.apache.sling.event.jobs.Job)2 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)2 JobManager (org.apache.sling.event.jobs.JobManager)1 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)1 BundleContext (org.osgi.framework.BundleContext)1 Configuration (org.osgi.service.cm.Configuration)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1