use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class JobHandlingDistributionQueue method remove.
public DistributionQueueEntry remove(@Nonnull String id) {
boolean removed = false;
Job job = getJob(id);
DistributionQueueEntry entry = null;
if (job != null) {
entry = JobHandlingUtils.getEntry(job);
removed = jobManager.removeJobById(job.getId());
}
log.debug("item with id {} removed from the queue: {}", id, removed);
return entry;
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class DistributionAgentQueueServlet method deleteItems.
private void deleteItems(ResourceResolver resourceResolver, DistributionQueue queue, String[] ids) {
for (String id : ids) {
DistributionQueueEntry entry = queue.getItem(id);
deleteItem(resourceResolver, queue, entry);
}
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry 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);
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class SimpleDistributionQueueCheckpointTest method testRunWithNothingInQueue.
@Test
public void testRunWithNothingInQueue() throws Exception {
DistributionQueue queue = mock(DistributionQueue.class);
Iterable<DistributionQueueEntry> items = new LinkedList<DistributionQueueEntry>();
when(queue.getItems(0, -1)).thenReturn(items);
File checkpointDirectory = FileUtils.getTempDirectory();
SimpleDistributionQueueCheckpoint simpleDistributionQueueCheckpoint = new SimpleDistributionQueueCheckpoint(queue, checkpointDirectory);
simpleDistributionQueueCheckpoint.run();
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry 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());
}
Aggregations