Search in sources :

Example 1 with DistributionQueueItemStatus

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

the class SimpleDistributionQueue method getState.

@Nonnull
private DistributionQueueState getState() {
    DistributionQueueItem firstItem = queue.peek();
    DistributionQueueItemStatus firstItemStatus = firstItem != null ? statusMap.get(firstItem) : null;
    return DistributionQueueUtils.calculateState(firstItem, firstItemStatus);
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Nonnull(javax.annotation.Nonnull)

Example 2 with DistributionQueueItemStatus

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

the class JobHandlingDistributionQueueTest method testPackageAdditionAndStatusCheck.

@SuppressWarnings("unchecked")
@Test
public void testPackageAdditionAndStatusCheck() 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.getJobById(anyString())).thenReturn(job);
    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));
    DistributionQueueItemStatus status = queue.getItem(job.getId()).getStatus();
    assertNotNull(status);
    assertEquals(DistributionQueueItemState.QUEUED, status.getItemState());
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) 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 3 with DistributionQueueItemStatus

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

the class QueueingDistributionPackageProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    String callingUser = "mr-who-cares";
    String requestId = "id231";
    long startTime = System.currentTimeMillis();
    DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueDispatchingStrategy scheduleQueueStrategy = mock(DistributionQueueDispatchingStrategy.class);
    // assume scheduling works
    List<DistributionQueueItemStatus> statuses = new LinkedList<DistributionQueueItemStatus>();
    DistributionQueueItemStatus qis = new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, "queue-1");
    statuses.add(qis);
    when(scheduleQueueStrategy.add(distributionPackage, queueProvider)).thenReturn(statuses);
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    String agentName = "dummy";
    QueueingDistributionPackageProcessor exporterProcessor = new QueueingDistributionPackageProcessor(callingUser, requestId, startTime, eventFactory, scheduleQueueStrategy, queueProvider, log, agentName);
    DistributionPackageInfo info = new DistributionPackageInfo("type-a", new HashMap<String, Object>());
    when(distributionPackage.getInfo()).thenReturn(info);
    exporterProcessor.process(distributionPackage);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) LinkedList(java.util.LinkedList) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 4 with DistributionQueueItemStatus

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

the class SimpleDistributionAgentQueueProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    int retryAttempts = 3;
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
    SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
    String agentName = "dummy-a";
    SimpleDistributionAgentQueueProcessor queueProcessor = new SimpleDistributionAgentQueueProcessor(packageExporter, packageImporter, retryAttempts, null, log, queueProvider, eventFactory, authenticationInfo, agentName);
    String id = "123-456";
    DistributionQueueItem item = new DistributionQueueItem("pckg-123", new HashMap<String, Object>());
    String queueName = "queue-1";
    DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, queueName);
    DistributionQueueEntry entry = new DistributionQueueEntry(id, item, status);
    queueProcessor.process(queueName, entry);
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) Test(org.junit.Test)

Example 5 with DistributionQueueItemStatus

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

the class SimpleDistributionAgentTest method testDistributionWithDisallowedRoot.

@Test
public void testDistributionWithDisallowedRoot() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy packageExporterStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy queueDistributionStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(queueDistributionStrategy.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, "default")));
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, queueDistributionStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, new String[] { "/content" }, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/home");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
    when(distributionPackage.getInfo()).thenReturn(packageInfo);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    queueDistributionStrategy.add(distributionPackage, queueProvider);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            ((DistributionPackageProcessor) args[2]).process(distributionPackage);
            return null;
        }
    }).when(packageExporter).exportPackages(any(ResourceResolver.class), any(DistributionRequest.class), any(DistributionPackageProcessor.class));
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(new SimpleDistributionQueue(name, "name"));
    DistributionResponse response = agent.execute(resourceResolver, request);
    assertFalse(response.isSuccessful());
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) SimpleDistributionQueue(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue) SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DistributionResponse(org.apache.sling.distribution.DistributionResponse) Test(org.junit.Test)

Aggregations

DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)30 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)20 Test (org.junit.Test)18 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)16 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)14 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)12 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)11 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)9 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)8 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)8 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)7 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)7 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)7 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)6 SlingRepository (org.apache.sling.jcr.api.SlingRepository)6 HashMap (java.util.HashMap)5 DistributionRequest (org.apache.sling.distribution.DistributionRequest)5 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)5 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)5