Search in sources :

Example 21 with Scheduler

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

the class JcrEventDistributionTriggerTest method testProcessEventOnIgnoredPattern.

@Test
public void testProcessEventOnIgnoredPattern() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    Scheduler scheduler = mock(Scheduler.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    String path = "/home/users";
    String serviceName = "serviceId";
    String[] ignoredPaths = new String[] { "/home/users/\\w" };
    JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, ignoredPaths);
    Event event = mock(Event.class);
    when(event.getPath()).thenReturn("/home/users/a");
    DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
    assertNull(distributionRequest);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Event(javax.jcr.observation.Event) Test(org.junit.Test)

Example 22 with Scheduler

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

the class PersistingJcrEventDistributionTriggerTest method testProcessEventWithoutPrivilegesAndNuggetsPath.

@Test
public void testProcessEventWithoutPrivilegesAndNuggetsPath() throws Exception {
    String serviceName = "serviceId";
    Session session = mock(Session.class);
    when(session.hasPermission(eq("var"), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
    when(session.hasPermission(eq("nuggets"), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
    // first time it doesn't exist and should be created
    when(session.nodeExists("/var/nuggets")).thenReturn(false);
    // second time it should exist
    when(session.nodeExists("/var/nuggets")).thenReturn(true);
    Node rootNode = mock(Node.class);
    Node varNode = mock(Node.class);
    Node nuggetsNode = mock(Node.class);
    when(varNode.addNode("nuggets", "sling:Folder")).thenReturn(nuggetsNode);
    when(rootNode.addNode("var", "sling:Folder")).thenReturn(varNode);
    when(session.getRootNode()).thenReturn(rootNode);
    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";
    String nuggetsPath = "/var/nuggets";
    PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new PersistedJcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, serviceName, nuggetsPath);
    Event event = mock(Event.class);
    DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
    assertNull(distributionRequest);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) 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) Session(javax.jcr.Session) Test(org.junit.Test)

Example 23 with Scheduler

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

the class ScheduledDistributionTriggerTest method testRegister.

@Test
public void testRegister() throws Exception {
    String path = "/path/to/somewhere";
    int interval = 10;
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, interval)).thenReturn(options);
    when(options.name(handler.toString())).thenReturn(options);
    ScheduledDistributionTrigger scheduleddistributionTrigger = new ScheduledDistributionTrigger(action.name(), path, interval, null, scheduler, mock(ResourceResolverFactory.class));
    scheduleddistributionTrigger.register(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Example 24 with Scheduler

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

the class ScheduledDistributionTriggerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    String path = "/path/to/somewhere";
    int interval = 10;
    Scheduler scheduler = mock(Scheduler.class);
    ScheduledDistributionTrigger scheduleddistributionTrigger = new ScheduledDistributionTrigger(action.name(), path, interval, null, scheduler, mock(ResourceResolverFactory.class));
    DistributionRequestHandler handlerId = mock(DistributionRequestHandler.class);
    scheduleddistributionTrigger.unregister(handlerId);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Example 25 with Scheduler

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

the class JobSchedulerImpl method stopScheduledJob.

/**
     * Stop a scheduled job
     * @param info The scheduling info
     */
private void stopScheduledJob(final ScheduledJobInfoImpl info) {
    final Scheduler localScheduler = this.scheduler;
    if (localScheduler != null) {
        this.configuration.getAuditLogger().debug("SCHEDULED STOP name={}, topic={}, properties={} : {}", new Object[] { info.getName(), info.getJobTopic(), info.getJobProperties(), info.getSchedules() });
        for (int index = 0; index < info.getSchedules().size(); index++) {
            final String name = info.getSchedulerJobId() + "-" + String.valueOf(index);
            localScheduler.unschedule(name);
        }
    }
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler)

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