Search in sources :

Example 21 with DistributionQueueProvider

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

the class SimpleDistributionAgentTest method testDistributionWithFailingDistributionStrategy.

@Test
public void testDistributionWithFailingDistributionStrategy() 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 distributionHandler = mock(DistributionQueueDispatchingStrategy.class);
    Iterable<DistributionQueueItemStatus> states = Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME));
    when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, distributionHandler, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    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);
    assertNotNull(response);
    assertEquals("[ERROR]", response.getMessage());
    assertEquals(DistributionRequestState.DROPPED, response.getState());
}
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)

Example 22 with DistributionQueueProvider

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

the class SimpleDistributionAgentTest method testDistributionWithWorkingDistributionStrategy.

@Test
public void testDistributionWithWorkingDistributionStrategy() 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 distributionHandler = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "subServiceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, distributionHandler, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    Iterable<DistributionQueueItemStatus> states = Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME));
    when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states);
    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);
    assertNotNull(response);
    assertEquals("[QUEUED]", response.getMessage());
    assertEquals(DistributionRequestState.ACCEPTED, response.getState());
}
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)

Example 23 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider 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);
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 24 with DistributionQueueProvider

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

the class AsyncDeliveryDispatchingStrategyTest method testAddWithNotSharedPackage.

@Test(expected = DistributionException.class)
public void testAddWithNotSharedPackage() throws Exception {
    Map<String, String> deliveryMappings = new HashMap<String, String>();
    deliveryMappings.put("queue1", "delivery1");
    deliveryMappings.put("queue2", "delivery2");
    AsyncDeliveryDispatchingStrategy asyncDeliveryDispatchingStrategy = new AsyncDeliveryDispatchingStrategy(deliveryMappings);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    asyncDeliveryDispatchingStrategy.add(distributionPackage, queueProvider);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) HashMap(java.util.HashMap) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 25 with DistributionQueueProvider

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

Aggregations

DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)25 Test (org.junit.Test)20 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)17 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)13 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)13 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)13 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)13 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)12 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)12 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)9 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)8 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)8 SlingRepository (org.apache.sling.jcr.api.SlingRepository)8 SimpleDistributionQueue (org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue)7 HashMap (java.util.HashMap)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 DistributionRequest (org.apache.sling.distribution.DistributionRequest)5 DistributionResponse (org.apache.sling.distribution.DistributionResponse)5 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)5 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)5