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