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