use of org.springframework.integration.scheduling.SimplePollSkipStrategy in project spring-integration by spring-projects.
the class PollerAdviceTests method testSkipSimple.
@Test
public void testSkipSimple() throws Exception {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
class LocalSource implements MessageSource<Object> {
private final CountDownLatch latch;
private LocalSource(CountDownLatch latch) {
this.latch = latch;
}
@Override
public Message<Object> receive() {
latch.countDown();
return null;
}
}
CountDownLatch latch = new CountDownLatch(1);
adapter.setSource(new LocalSource(latch));
class OneAndDone10msTrigger implements Trigger {
private boolean done;
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
Date date = done ? null : new Date(System.currentTimeMillis() + 10);
done = true;
return date;
}
}
adapter.setTrigger(new OneAndDone10msTrigger());
configure(adapter);
List<Advice> adviceChain = new ArrayList<>();
SimplePollSkipStrategy skipper = new SimplePollSkipStrategy();
skipper.skipPolls();
PollSkipAdvice advice = new PollSkipAdvice(skipper);
adviceChain.add(advice);
adapter.setAdviceChain(adviceChain);
adapter.afterPropertiesSet();
adapter.start();
assertFalse(latch.await(1, TimeUnit.SECONDS));
adapter.stop();
skipper.reset();
latch = new CountDownLatch(1);
adapter.setSource(new LocalSource(latch));
adapter.setTrigger(new OneAndDone10msTrigger());
adapter.start();
assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.stop();
}
Aggregations