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