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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations