Search in sources :

Example 1 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testProperties.

@Test
public void testProperties() 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.PROPERTIES_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 2 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testConstructor.

@Test
public void testConstructor() throws Exception {
    final TopologyEventListener delegate = new TopologyEventListener() {

        @Override
        public void handleTopologyEvent(TopologyEvent event) {
        // nothing here atm
        }
    };
    final Scheduler scheduler = createScheduler();
    try {
        new InitDelayingTopologyEventListener(-1, delegate, scheduler);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(0, delegate, scheduler);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(1, null, scheduler);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(-1, delegate, scheduler, null);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(0, delegate, scheduler, null);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(1, null, scheduler, null);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(-1, delegate, scheduler, logger);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(0, delegate, scheduler, logger);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
    try {
        new InitDelayingTopologyEventListener(1, null, scheduler, logger);
        fail("should complain");
    } catch (IllegalArgumentException re) {
    // ok
    }
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler) TopologyEvent(org.apache.sling.discovery.TopologyEvent) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener) Test(org.junit.Test)

Example 3 with Scheduler

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

the class TestInitDelayingTopologyEventListener method createScheduler.

private Scheduler createScheduler() {
    return new Scheduler() {

        @Override
        public boolean unschedule(String jobName) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean schedule(final Object job, ScheduleOptions options) {
            if (job instanceof Runnable) {
                final Timer t = new Timer();
                t.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        ((Runnable) job).run();
                    }
                }, 300);
                return true;
            }
            return false;
        }

        @Override
        public void removeJob(String name) throws NoSuchElementException {
        // TODO Auto-generated method stub
        }

        @Override
        public boolean fireJobAt(String name, Object job, Map<String, Serializable> config, Date date, int times, long period) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void fireJobAt(String name, Object job, Map<String, Serializable> config, Date date) throws Exception {
        // TODO Auto-generated method stub
        }

        @Override
        public boolean fireJob(Object job, Map<String, Serializable> config, int times, long period) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void fireJob(Object job, Map<String, Serializable> config) throws Exception {
        // TODO Auto-generated method stub
        }

        @Override
        public void addPeriodicJob(String name, Object job, Map<String, Serializable> config, long period, boolean canRunConcurrently, boolean startImmediate) throws Exception {
        // TODO Auto-generated method stub
        }

        @Override
        public void addPeriodicJob(String name, Object job, Map<String, Serializable> config, long period, boolean canRunConcurrently) throws Exception {
        // TODO Auto-generated method stub
        }

        @Override
        public void addJob(String name, Object job, Map<String, Serializable> config, String schedulingExpression, boolean canRunConcurrently) throws Exception {
        // TODO Auto-generated method stub
        }

        @Override
        public ScheduleOptions NOW(int times, long period) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ScheduleOptions NOW() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ScheduleOptions EXPR(String expression) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ScheduleOptions AT(Date date, int times, long period) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ScheduleOptions AT(Date date) {
            // TODO Auto-generated method stub
            return null;
        }
    };
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Map(java.util.Map) Date(java.util.Date)

Example 4 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testNoEvents.

@Test
public void testNoEvents() throws Exception {
    final TestListener delegate = new TestListener();
    final Scheduler scheduler = createScheduler();
    InitDelayingTopologyEventListener listener = new InitDelayingTopologyEventListener(1, delegate, scheduler, logger);
    // no events:
    delegate.assureEventCnt(0, 1500);
    // then the first init is passed through
    listener.handleTopologyEvent(createEvent(Type.TOPOLOGY_INIT));
    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 5 with Scheduler

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

the class TestInitDelayingTopologyEventListener method testChanging0.

@Test
public void testChanging0() 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));
    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)

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