use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.
the class MinEventDelayHandler method runAfter.
/**
* run the runnable after the indicated number of seconds, once.
* @return true if the scheduling of the runnable worked, false otherwise
*/
private boolean runAfter(long seconds, final Runnable runnable) {
final Scheduler theScheduler = scheduler;
if (theScheduler == null) {
logger.info("runAfter: no scheduler set");
return false;
}
logger.trace("runAfter: trying with scheduler.fireJob");
final Date date = new Date(System.currentTimeMillis() + seconds * 1000);
try {
theScheduler.fireJobAt(null, runnable, null, date);
return true;
} catch (Exception e) {
logger.info("runAfter: could not schedule a job: " + e);
return false;
}
}
use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.
the class AbstractJcrEventTriggerTest method addToListTest.
//"SLING-6054"
@Test
public void addToListTest() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
String path = "/";
String serviceUser = "service-user";
AbstractJcrEventTrigger trigger = new AbstractJcrEventTrigger(repository, scheduler, rrf, path, serviceUser) {
@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
return null;
}
};
String descendant = "/a/b/c/d/e/f/h";
String ancestor = "/a/b/c/d";
List<DistributionRequest> requests = new LinkedList<DistributionRequest>();
requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, descendant));
DistributionRequest newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor);
trigger.addToList(newRequest, requests);
assertEquals(1, requests.size());
assertEquals(3, requests.get(0).getPaths().length);
String[] paths = requests.get(0).getPaths();
assertEquals(ancestor, paths[0]);
// the missing path is added
assertEquals("/a/b/c/d/e/f/g", paths[1]);
assertEquals(descendant, paths[2]);
// invert order of requests
requests = new LinkedList<DistributionRequest>();
requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor));
newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, descendant);
trigger.addToList(newRequest, requests);
assertEquals(1, requests.size());
assertEquals(3, requests.get(0).getPaths().length);
paths = requests.get(0).getPaths();
assertEquals(ancestor, paths[0]);
// the missing path is added
assertEquals("/a/b/c/d/e/f/g", paths[1]);
assertEquals(descendant, paths[2]);
}
use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.
the class JcrEventDistributionTriggerTest method testProcessEventOnMultipleIgnoredPattern.
@Test
public void testProcessEventOnMultipleIgnoredPattern() 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[] { ".*/.tokens.*", ".*/.rep:cache.*" };
JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, ignoredPaths);
Event event = mock(Event.class);
when(event.getPath()).thenReturn("/home/users/3/3U3HxUUzJJ60BdN4lEDJ/.tokens/2017-01-10T15.52.37.842+01.00");
DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
assertNull(distributionRequest);
}
use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.
the class SimpleDistributionQueueProviderTest method testDisableQueueProcessingWithCheckpointing.
@Test
public void testDisableQueueProcessingWithCheckpointing() throws Exception {
String name = "dummy-agent";
try {
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, name, true);
simpledistributionQueueProvider.disableQueueProcessing();
} finally {
new File(name + "-simple-queues-checkpoints").deleteOnExit();
}
}
use of org.apache.sling.commons.scheduler.Scheduler in project sling by apache.
the class SimpleDistributionQueueProviderTest method testEnableQueueProcessing.
@Test
public void testEnableQueueProcessing() throws Exception {
Scheduler scheduler = mock(Scheduler.class);
ScheduleOptions options = mock(ScheduleOptions.class);
when(scheduler.NOW(-1, 1)).thenReturn(options);
when(options.canRunConcurrently(false)).thenReturn(options);
when(options.name(any(String.class))).thenReturn(options);
String name = "dummy-agent";
SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, name, false);
DistributionQueueProcessor processor = mock(DistributionQueueProcessor.class);
simpledistributionQueueProvider.enableQueueProcessing(processor);
}
Aggregations