Search in sources :

Example 36 with DistributionQueue

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

Example 37 with DistributionQueue

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

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

the class PriorityQueueDispatchingStrategyTest method testMatchingDispatching.

@Test
public void testMatchingDispatching() throws Exception {
    PriorityQueueDispatchingStrategy dispatchingStrategy = new PriorityQueueDispatchingStrategy(selectors, queueNames);
    DistributionPackage distributionPackage = mock(SharedDistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/content/news/a" });
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt", properties));
    DistributionQueue news1 = mock(DistributionQueue.class);
    when(news1.getName()).thenReturn("news-publish1");
    when(queueProvider.getQueue("news-publish1")).thenReturn(news1);
    DistributionQueue news2 = mock(DistributionQueue.class);
    when(news2.getName()).thenReturn("news-publish2");
    when(queueProvider.getQueue("news-publish2")).thenReturn(news2);
    dispatchingStrategy.add(distributionPackage, queueProvider);
    verify(queueProvider).getQueue("news-publish1");
    verify(queueProvider).getQueue("news-publish2");
    verifyNoMoreInteractions(queueProvider);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 39 with DistributionQueue

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

the class SimpleDistributionQueueTest method testPackageAdditionRetrievalAndRemoval.

@Test
public void testPackageAdditionRetrievalAndRemoval() throws Exception {
    DistributionQueue queue = new SimpleDistributionQueue("agentName", "default");
    DistributionQueueItem pkg = mock(DistributionQueueItem.class);
    when(pkg.getPackageId()).thenReturn("id");
    assertNotNull(queue.add(pkg));
    assertFalse(queue.getStatus().isEmpty());
    assertEquals(pkg, queue.getHead().getItem());
    assertFalse(queue.getStatus().isEmpty());
    DistributionQueueItemStatus status = queue.getItem(pkg.getPackageId()).getStatus();
    assertNotNull(queue.remove(pkg.getPackageId()));
    assertTrue(queue.getStatus().isEmpty());
    assertNotNull(status);
    assertEquals(1, status.getAttempts());
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 40 with DistributionQueue

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

the class DistributionQueueHealthCheckTest method testWithNotOkItemInTheQueue.

@Test
public void testWithNotOkItemInTheQueue() throws Exception {
    DistributionQueueHealthCheck distributionQueueHealthCheck = new DistributionQueueHealthCheck();
    distributionQueueHealthCheck.activate(Collections.<String, Object>emptyMap());
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem item = mock(DistributionQueueItem.class);
    DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
    when(status.getAttempts()).thenReturn(10);
    when(queue.getItem(any(String.class))).thenReturn(new DistributionQueueEntry(null, item, status));
    when(queue.getHead()).thenReturn(new DistributionQueueEntry(null, item, status));
    DistributionAgent distributionAgent = mock(DistributionAgent.class);
    List<String> queues = new ArrayList<String>();
    queues.add("queueName");
    when(distributionAgent.getQueueNames()).thenReturn(queues);
    when(distributionAgent.getQueue(anyString())).thenReturn(queue);
    distributionQueueHealthCheck.bindDistributionAgent(distributionAgent);
    Result result = distributionQueueHealthCheck.execute();
    assertNotNull(result);
    assertFalse(result.isOk());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Result(org.apache.sling.hc.api.Result) Test(org.junit.Test)

Aggregations

DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)40 Test (org.junit.Test)25 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)20 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)18 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)14 HashMap (java.util.HashMap)8 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)8 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)7 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)7 ArrayList (java.util.ArrayList)6 File (java.io.File)5 Map (java.util.Map)5 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DistributionException (org.apache.sling.distribution.common.DistributionException)4 SharedDistributionPackage (org.apache.sling.distribution.packaging.impl.SharedDistributionPackage)4 DistributionQueueStatus (org.apache.sling.distribution.queue.DistributionQueueStatus)4 Result (org.apache.sling.hc.api.Result)4 LinkedList (java.util.LinkedList)3 Scheduler (org.apache.sling.commons.scheduler.Scheduler)3