Search in sources :

Example 11 with DistributionQueueEntry

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

the class DistributionQueueHealthCheckTest method testWithOneOkItemInTheQueue.

@Test
public void testWithOneOkItemInTheQueue() 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(1);
    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);
    assertTrue(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)

Example 12 with DistributionQueueEntry

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

the class DistributionQueueMBeanTest method verifyMBeanExposedValuesWhenHeadIsNotNull.

@Test
public void verifyMBeanExposedValuesWhenHeadIsNotNull() {
    DistributionQueueStatus status = new DistributionQueueStatus(1, RUNNING);
    Calendar joined = Calendar.getInstance();
    DistributionQueueEntry entry = new DistributionQueueEntry("#entry", new DistributionQueueItem("#package", 1000L, new HashMap<String, Object>()), new DistributionQueueItemStatus(joined, QUEUED, 1, "#queue"));
    DistributionQueue distributionQueue = mock(DistributionQueue.class);
    when(distributionQueue.getName()).thenReturn("#distributionQueue");
    when(distributionQueue.getHead()).thenReturn(entry);
    when(distributionQueue.getType()).thenReturn(PARALLEL);
    when(distributionQueue.getStatus()).thenReturn(status);
    DistributionQueueMBean mBean = new DistributionQueueMBeanImpl(distributionQueue);
    assertEquals(distributionQueue.getName(), mBean.getName());
    assertEquals(distributionQueue.getType().name().toLowerCase(), mBean.getType());
    assertEquals(1, mBean.getSize());
    assertFalse(mBean.isEmpty());
    assertEquals("#entry", mBean.getHeadId());
    assertEquals(1, mBean.getHeadDequeuingAttempts());
    assertEquals(QUEUED.name().toLowerCase(), mBean.getHeadStatus());
    assertEquals(joined, mBean.getHeadEnqueuingDate());
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) Calendar(java.util.Calendar) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 13 with DistributionQueueEntry

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

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithFailingItemDelivery.

@Test
public void testPackageAdditionWithFailingItemDelivery() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem queueItem = mock(DistributionQueueItem.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(queueItem)).thenReturn(new DistributionQueueEntry(null, queueItem, state));
    Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
    assertNotNull(returnedStates);
    Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 14 with DistributionQueueEntry

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

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithSucceedingItemDelivery.

@Test
public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(any(DistributionQueueItem.class))).thenReturn(new DistributionQueueEntry(null, null, state));
    Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
    assertNotNull(returnedStates);
    Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 15 with DistributionQueueEntry

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

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithNotNullItemStateFromTheQueue.

@Test
public void testPackageAdditionWithNotNullItemStateFromTheQueue() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(any(DistributionQueueItem.class))).thenReturn(new DistributionQueueEntry(null, null, state));
    Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
    assertNotNull(returnedStates);
    Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Aggregations

DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)30 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)20 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)18 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)16 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)6 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)5 File (java.io.File)4 DistributionException (org.apache.sling.distribution.common.DistributionException)4 Map (java.util.Map)3 CheckForNull (javax.annotation.CheckForNull)3 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)3 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)3 SharedDistributionPackage (org.apache.sling.distribution.packaging.impl.SharedDistributionPackage)3 DistributionQueueStatus (org.apache.sling.distribution.queue.DistributionQueueStatus)3 Result (org.apache.sling.hc.api.Result)3 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)2