Search in sources :

Example 16 with Scheduler

use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.

the class RemoteEventDistributionTriggerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    String endpoint = "";
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Scheduler scheduler = mock(Scheduler.class);
    RemoteEventDistributionTrigger remoteEventdistributionTrigger = new RemoteEventDistributionTrigger(endpoint, distributionTransportSecretProvider, scheduler);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    remoteEventdistributionTrigger.unregister(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) Scheduler(org.apache.sling.commons.scheduler.Scheduler) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) Test(org.junit.Test)

Example 17 with Scheduler

use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.

the class RemoteEventDistributionTriggerTest method testRegister.

@Test
public void testRegister() throws Exception {
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    String endpoint = "";
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(options.name(handler.toString())).thenReturn(options);
    when(scheduler.NOW()).thenReturn(options);
    RemoteEventDistributionTrigger remoteEventdistributionTrigger = new RemoteEventDistributionTrigger(endpoint, distributionTransportSecretProvider, scheduler);
    remoteEventdistributionTrigger.register(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Scheduler(org.apache.sling.commons.scheduler.Scheduler) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) Test(org.junit.Test)

Example 18 with Scheduler

use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.

the class SimpleDistributionQueueProviderTest method testEnableQueueProcessingWithCheckpointRecovery.

@Test
public void testEnableQueueProcessingWithCheckpointRecovery() throws Exception {
    File checkpointDirectory = new File("dummy-agent-simple-queues-checkpoints");
    File file = new File(getClass().getResource("/dummy-agent-checkpoint").getFile());
    FileUtils.copyFileToDirectory(file, checkpointDirectory);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 1)).thenReturn(options);
    when(scheduler.NOW(-1, 15)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    String name = "dummy-agent";
    try {
        SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, name, true);
        DistributionQueueProcessor processor = mock(DistributionQueueProcessor.class);
        simpledistributionQueueProvider.enableQueueProcessing(processor, name);
        DistributionQueue queue = simpledistributionQueueProvider.getQueue(name);
        assertNotNull(queue);
        assertEquals(1, queue.getStatus().getItemsCount());
        DistributionQueueEntry head = queue.getHead();
        assertNotNull(head);
        DistributionQueueItem item = head.getItem();
        assertNotNull(item);
        String packageId = item.getPackageId();
        assertNotNull(packageId);
        assertEquals("DSTRQ1", item.get("internal.request.id"));
        assertArrayEquals(new String[] { "/foo", "bar" }, (String[]) item.get("request.paths"));
        assertArrayEquals(new String[] { "/foo" }, (String[]) item.get("request.deepPaths"));
        assertEquals("admin", item.get("internal.request.user"));
        assertEquals("ADD", item.get("request.type"));
        assertEquals("default", item.get("package.type"));
        assertEquals("1464090250095", item.get("internal.request.startTime"));
    } finally {
        FileUtils.deleteDirectory(new File(name + "-simple-queues-checkpoints"));
    }
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) Scheduler(org.apache.sling.commons.scheduler.Scheduler) File(java.io.File) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 19 with Scheduler

use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.

the class SimpleDistributionQueueProviderTest method testDisableQueueProcessing.

@Test
public void testDisableQueueProcessing() throws Exception {
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 10)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, "dummy-agent", false);
    simpledistributionQueueProvider.disableQueueProcessing();
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Example 20 with Scheduler

use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.

the class PersistingJcrEventDistributionTriggerTest method testProcessEventWithPrivileges.

@Test
public void testProcessEventWithPrivileges() throws Exception {
    String nuggetsPath = "/var/nuggets";
    String serviceName = "serviceId";
    Session session = mock(Session.class);
    when(session.nodeExists("/var/nuggets")).thenReturn(true);
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)).thenReturn(true);
    SlingRepository repository = mock(SlingRepository.class);
    Scheduler scheduler = mock(Scheduler.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(repository.loginService(serviceName, null)).thenReturn(session);
    String path = "/some/path";
    PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new PersistedJcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, serviceName, nuggetsPath);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    persistingJcrEventdistributionTrigger.register(handler);
    Node nuggetsNode = mock(Node.class);
    Node eventNode = mock(Node.class);
    when(nuggetsNode.addNode(any(String.class), any(String.class))).thenReturn(eventNode);
    when(session.getNode(nuggetsPath)).thenReturn(nuggetsNode);
    Event event = mock(Event.class);
    when(event.getPath()).thenReturn("/some/path/generating/event");
    DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
    assertNotNull(distributionRequest);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Aggregations

Scheduler (org.apache.sling.commons.scheduler.Scheduler)29 Test (org.junit.Test)25 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)10 Event (javax.jcr.observation.Event)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)9 SlingRepository (org.apache.sling.jcr.api.SlingRepository)9 ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)8 DistributionRequestHandler (org.apache.sling.distribution.trigger.DistributionRequestHandler)6 Session (javax.jcr.Session)4 File (java.io.File)3 Node (javax.jcr.Node)3 DistributionQueueProcessor (org.apache.sling.distribution.queue.DistributionQueueProcessor)3 Date (java.util.Date)2 Workspace (javax.jcr.Workspace)2 ObservationManager (javax.jcr.observation.ObservationManager)2 DistributionTransportSecretProvider (org.apache.sling.distribution.transport.DistributionTransportSecretProvider)2 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1