Search in sources :

Example 16 with DistributionQueueProvider

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

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

the class PriorityQueueDispatchingStrategyTest method testNoMatchingDispatching.

@Test
public void testNoMatchingDispatching() 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/other" });
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt", properties));
    DistributionQueue other1 = mock(DistributionQueue.class);
    when(other1.getName()).thenReturn("publish1");
    when(queueProvider.getQueue("publish1")).thenReturn(other1);
    DistributionQueue other2 = mock(DistributionQueue.class);
    when(other2.getName()).thenReturn("publish2");
    when(queueProvider.getQueue("publish2")).thenReturn(other2);
    dispatchingStrategy.add(distributionPackage, queueProvider);
    verify(queueProvider).getQueue("publish1");
    verify(queueProvider).getQueue("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)

Example 18 with DistributionQueueProvider

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

Example 19 with DistributionQueueProvider

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

the class ReverseDistributionAgentFactory method createAgent.

@Override
protected SimpleDistributionAgent createAgent(String agentName, BundleContext context, Map<String, Object> config, DefaultDistributionLog distributionLog) {
    String serviceName = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(SERVICE_NAME), null));
    boolean queueProcessingEnabled = PropertiesUtil.toBoolean(config.get(QUEUE_PROCESSING_ENABLED), true);
    String[] exporterEndpoints = PropertiesUtil.toStringArray(config.get(EXPORTER_ENDPOINTS), new String[0]);
    exporterEndpoints = SettingsUtils.removeEmptyEntries(exporterEndpoints);
    int pullItems = PropertiesUtil.toInteger(config.get(PULL_ITEMS), Integer.MAX_VALUE);
    Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
    HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
    DistributionPackageExporter packageExporter = new RemoteDistributionPackageExporter(distributionLog, packageBuilder, transportSecretProvider, exporterEndpoints, pullItems, httpConfiguration);
    DistributionPackageImporter packageImporter = new LocalDistributionPackageImporter(agentName, distributionEventFactory, packageBuilder);
    DistributionQueueProvider queueProvider = new MonitoringDistributionQueueProvider(new JobHandlingDistributionQueueProvider(agentName, jobManager, context), context);
    DistributionQueueDispatchingStrategy exportQueueStrategy = new SingleQueueDispatchingStrategy();
    DistributionQueueDispatchingStrategy importQueueStrategy = null;
    DistributionRequestType[] allowedRequests = new DistributionRequestType[] { DistributionRequestType.PULL };
    Set<String> processingQueues = new HashSet<String>();
    processingQueues.addAll(exportQueueStrategy.getQueueNames());
    return new SimpleDistributionAgent(agentName, queueProcessingEnabled, processingQueues, serviceName, packageImporter, packageExporter, requestAuthorizationStrategy, queueProvider, exportQueueStrategy, importQueueStrategy, distributionEventFactory, resourceResolverFactory, slingRepository, distributionLog, allowedRequests, null, 0);
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) LocalDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.LocalDistributionPackageImporter) RemoteDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.RemoteDistributionPackageExporter) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) SingleQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.SingleQueueDispatchingStrategy) RemoteDistributionPackageExporter(org.apache.sling.distribution.packaging.impl.exporter.RemoteDistributionPackageExporter) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionRequestType(org.apache.sling.distribution.DistributionRequestType) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider) JobHandlingDistributionQueueProvider(org.apache.sling.distribution.queue.impl.jobhandling.JobHandlingDistributionQueueProvider) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) LocalDistributionPackageImporter(org.apache.sling.distribution.packaging.impl.importer.LocalDistributionPackageImporter) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) MonitoringDistributionQueueProvider(org.apache.sling.distribution.monitor.impl.MonitoringDistributionQueueProvider) HashSet(java.util.HashSet)

Example 20 with DistributionQueueProvider

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

the class SimpleDistributionAgentTest method testDistribution.

@Test
public void testDistribution() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy requestAuthorizationStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy dispatchingStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(dispatchingStrategy.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(new ArrayList<DistributionQueueItemStatus>());
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, requestAuthorizationStrategy, queueProvider, dispatchingStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
    when(distributionPackage.getInfo()).thenReturn(packageInfo);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    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"));
    agent.execute(resourceResolver, request);
}
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) 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