Search in sources :

Example 6 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)

Example 7 with DistributionQueueItemStatus

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

the class SimpleDistributionAgentTest method testDistributionEnable.

@Test
public void testDistributionEnable() 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);
    TestDistributionTrigger trigger = new TestDistributionTrigger();
    agent.enable();
    agent.enableTrigger(trigger);
    assertTrue(trigger.isRegistered());
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) Test(org.junit.Test)

Example 8 with DistributionQueueItemStatus

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

the class SimpleDistributionAgentTest method testDistributionWithAllowedRoot.

@Test
public void testDistributionWithAllowedRoot() 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, "/content");
    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);
    assertTrue(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)

Example 9 with DistributionQueueItemStatus

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

the class DistributionQueueHealthCheckTest method testWithOneOkItemInTheQueue.

@Test
public void testWithOneOkItemInTheQueue() throws Exception {
    DistributionQueueHealthCheck distributionQueueHealthCheck = new DistributionQueueHealthCheck();
    distributionQueueHealthCheck.activate(Collections.<String, Object>emptyMap());
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem item = mock(DistributionQueueItem.class);
    DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
    when(status.getAttempts()).thenReturn(1);
    when(queue.getItem(any(String.class))).thenReturn(new DistributionQueueEntry(null, item, status));
    when(queue.getHead()).thenReturn(new DistributionQueueEntry(null, item, status));
    DistributionAgent distributionAgent = mock(DistributionAgent.class);
    List<String> queues = new ArrayList<String>();
    queues.add("queueName");
    when(distributionAgent.getQueueNames()).thenReturn(queues);
    when(distributionAgent.getQueue(anyString())).thenReturn(queue);
    distributionQueueHealthCheck.bindDistributionAgent(distributionAgent);
    Result result = distributionQueueHealthCheck.execute();
    assertNotNull(result);
    assertTrue(result.isOk());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Result(org.apache.sling.hc.api.Result) Test(org.junit.Test)

Example 10 with DistributionQueueItemStatus

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

the class DistributionQueueMBeanTest method verifyMBeanExposedValuesWhenHeadIsNotNull.

@Test
public void verifyMBeanExposedValuesWhenHeadIsNotNull() {
    DistributionQueueStatus status = new DistributionQueueStatus(1, RUNNING);
    Calendar joined = Calendar.getInstance();
    DistributionQueueEntry entry = new DistributionQueueEntry("#entry", new DistributionQueueItem("#package", 1000L, new HashMap<String, Object>()), new DistributionQueueItemStatus(joined, QUEUED, 1, "#queue"));
    DistributionQueue distributionQueue = mock(DistributionQueue.class);
    when(distributionQueue.getName()).thenReturn("#distributionQueue");
    when(distributionQueue.getHead()).thenReturn(entry);
    when(distributionQueue.getType()).thenReturn(PARALLEL);
    when(distributionQueue.getStatus()).thenReturn(status);
    DistributionQueueMBean mBean = new DistributionQueueMBeanImpl(distributionQueue);
    assertEquals(distributionQueue.getName(), mBean.getName());
    assertEquals(distributionQueue.getType().name().toLowerCase(), mBean.getType());
    assertEquals(1, mBean.getSize());
    assertFalse(mBean.isEmpty());
    assertEquals("#entry", mBean.getHeadId());
    assertEquals(1, mBean.getHeadDequeuingAttempts());
    assertEquals(QUEUED.name().toLowerCase(), mBean.getHeadStatus());
    assertEquals(joined, mBean.getHeadEnqueuingDate());
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) Calendar(java.util.Calendar) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) 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