Search in sources :

Example 26 with Scheduler

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

the class VirtualInstanceBuilder method getSingletonScheduler.

public static Scheduler getSingletonScheduler() throws Exception {
    if (singletonScheduler != null) {
        return singletonScheduler;
    }
    final Scheduler newscheduler = new QuartzScheduler();
    final ThreadPoolManager tpm = new DefaultThreadPoolManager(null, null);
    try {
        PrivateAccessor.invoke(newscheduler, "bindThreadPoolManager", new Class[] { ThreadPoolManager.class }, new Object[] { tpm });
    } catch (Throwable e1) {
        org.junit.Assert.fail(e1.toString());
    }
    OSGiMock.activate(newscheduler);
    singletonScheduler = newscheduler;
    return singletonScheduler;
}
Also used : DefaultThreadPoolManager(org.apache.sling.commons.threads.impl.DefaultThreadPoolManager) FailingScheduler(org.apache.sling.discovery.base.its.setup.mock.FailingScheduler) QuartzScheduler(org.apache.sling.commons.scheduler.impl.QuartzScheduler) Scheduler(org.apache.sling.commons.scheduler.Scheduler) QuartzScheduler(org.apache.sling.commons.scheduler.impl.QuartzScheduler) ThreadPoolManager(org.apache.sling.commons.threads.ThreadPoolManager) DefaultThreadPoolManager(org.apache.sling.commons.threads.impl.DefaultThreadPoolManager)

Example 27 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testDisposing.

@Test
public void testDisposing() throws Exception {
    final TestListener delegate = new TestListener();
    final Scheduler scheduler = createScheduler();
    InitDelayingTopologyEventListener listener = new InitDelayingTopologyEventListener(1, delegate, scheduler, logger);
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_INIT));
    delegate.waitForEventCnt(1, 5000);
    // test framework testing :)
    delegate.assureEventCnt(1, 500);
    listener = new InitDelayingTopologyEventListener(1, delegate, scheduler, logger);
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_INIT));
    listener.dispose();
    delegate.assureEventCnt(1, 1000);
    delegate.assureEventCnt(1, 500);
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Example 28 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testChanging1.

@Test
public void testChanging1() throws Exception {
    final TestListener delegate = new TestListener();
    final Scheduler scheduler = createScheduler();
    InitDelayingTopologyEventListener listener = new InitDelayingTopologyEventListener(1, delegate, scheduler, logger);
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_INIT));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGING));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGED));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGING));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGED));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGING));
    delegate.assureEventCnt(0, 1000);
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGED));
    delegate.waitForEventCnt(1, 5000);
    assertEquals(delegate.getEvents().get(0).getType(), Type.TOPOLOGY_INIT);
    doTestAdditionalEventsAfterInit(delegate, listener);
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Example 29 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testChanged.

@Test
public void testChanged() throws Exception {
    final TestListener delegate = new TestListener();
    final Scheduler scheduler = createScheduler();
    InitDelayingTopologyEventListener listener = new InitDelayingTopologyEventListener(1, delegate, scheduler, logger);
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_INIT));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGING));
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_CHANGED));
    delegate.waitForEventCnt(1, 5000);
    assertEquals(delegate.getEvents().get(0).getType(), Type.TOPOLOGY_INIT);
    doTestAdditionalEventsAfterInit(delegate, listener);
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler) 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