Search in sources :

Example 21 with DistributionQueueItem

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

the class DistributionAgentQueueServlet method deleteItem.

private void deleteItem(ResourceResolver resourceResolver, DistributionQueue queue, DistributionQueueEntry entry) {
    DistributionQueueItem item = entry.getItem();
    String id = entry.getId();
    queue.remove(id);
    DistributionPackage distributionPackage = getPackage(resourceResolver, item);
    DistributionPackageUtils.releaseOrDelete(distributionPackage, queue.getName());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem)

Example 22 with DistributionQueueItem

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

the class AsyncDeliveryDispatchingStrategyTest method testAddWithOneItemInRunningQueues.

@Test
public void testAddWithOneItemInRunningQueues() throws Exception {
    Map<String, String> deliveryMappings = new HashMap<String, String>();
    String queue1 = "queue1";
    deliveryMappings.put(queue1, "delivery1");
    String queue2 = "queue2";
    deliveryMappings.put(queue2, "delivery2");
    AsyncDeliveryDispatchingStrategy asyncDeliveryDispatchingStrategy = new AsyncDeliveryDispatchingStrategy(deliveryMappings);
    // setup package
    SharedDistributionPackage distributionPackage = mock(SharedDistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("1221312");
    DistributionPackageInfo info = new DistributionPackageInfo("dummy", new HashMap<String, Object>());
    when(distributionPackage.getInfo()).thenReturn(info);
    // setup queues
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue dq1 = mock(DistributionQueue.class);
    DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
    DistributionQueueEntry entry = new DistributionQueueEntry("1242112", new DistributionQueueItem(distributionPackage.getId(), new HashMap<String, Object>()), status);
    when(dq1.add(any(DistributionQueueItem.class))).thenReturn(entry);
    DistributionQueueStatus status1 = new DistributionQueueStatus(1, DistributionQueueState.RUNNING);
    when(dq1.getStatus()).thenReturn(status1);
    when(queueProvider.getQueue(queue1)).thenReturn(dq1);
    DistributionQueue dq2 = mock(DistributionQueue.class);
    when(dq2.add(any(DistributionQueueItem.class))).thenReturn(entry);
    DistributionQueueStatus status2 = new DistributionQueueStatus(1, DistributionQueueState.RUNNING);
    when(dq2.getStatus()).thenReturn(status2);
    when(queueProvider.getQueue(queue2)).thenReturn(dq2);
    Iterable<DistributionQueueItemStatus> statuses = asyncDeliveryDispatchingStrategy.add(distributionPackage, queueProvider);
    assertNotNull(statuses);
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 23 with DistributionQueueItem

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

the class JobHandlingUtilsTest method testFullPropertiesFromPackageCreation.

@Test
public void testFullPropertiesFromPackageCreation() throws Exception {
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("vlt");
    packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/foo" });
    packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD);
    packageInfo.put(DistributionPackageInfo.PROPERTY_PACKAGE_TYPE, "vlt");
    DistributionQueueItem queueItem = new DistributionQueueItem("an-id", packageInfo);
    Map<String, Object> fullPropertiesFromPackage = JobHandlingUtils.createFullProperties(queueItem);
    assertNotNull(fullPropertiesFromPackage);
    assertEquals(5, fullPropertiesFromPackage.size());
    assertNotNull(fullPropertiesFromPackage.get("distribution.request.paths"));
    assertNotNull(fullPropertiesFromPackage.get("distribution.item.id"));
    assertNotNull(fullPropertiesFromPackage.get("distribution.package.size"));
    assertNotNull(fullPropertiesFromPackage.get("distribution.package.type"));
    assertNotNull(fullPropertiesFromPackage.get("distribution.request.type"));
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 24 with DistributionQueueItem

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

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

the class SimpleDistributionQueueCheckpointTest method testRunWithOneItemInTheQueue.

@Test
public void testRunWithOneItemInTheQueue() throws Exception {
    DistributionQueue queue = mock(DistributionQueue.class);
    String queueName = "sample-queue";
    when(queue.getName()).thenReturn(queueName);
    LinkedList<DistributionQueueEntry> entries = new LinkedList<DistributionQueueEntry>();
    Map<String, Object> base = new HashMap<String, Object>();
    base.put("here", "there");
    base.put("foo", "bar");
    base.put("multi", new String[] { "1", "2" });
    entries.add(new DistributionQueueEntry("123", new DistributionQueueItem("pid123", base), new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, queueName)));
    when(queue.getItems(0, -1)).thenReturn(entries);
    File checkpointDirectory = FileUtils.getTempDirectory();
    SimpleDistributionQueueCheckpoint simpleDistributionQueueCheckpoint = new SimpleDistributionQueueCheckpoint(queue, checkpointDirectory);
    simpleDistributionQueueCheckpoint.run();
    File checkpointFile = new File(checkpointDirectory, "sample-queue-checkpoint");
    assertTrue(checkpointFile.exists());
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) HashMap(java.util.HashMap) File(java.io.File) LinkedList(java.util.LinkedList) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Aggregations

DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)30 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)18 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)18 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)18 Test (org.junit.Test)15 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)7 HashMap (java.util.HashMap)5 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 DistributionException (org.apache.sling.distribution.common.DistributionException)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SharedDistributionPackage (org.apache.sling.distribution.packaging.impl.SharedDistributionPackage)3 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)3 CheckForNull (javax.annotation.CheckForNull)2 Nonnull (javax.annotation.Nonnull)2 ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)2 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)2