use of org.springframework.integration.file.tail.FileTailingMessageProducerSupport.FileTailingIdleEvent in project spring-integration by spring-projects.
the class FileTailingMessageProducerTests method testIdleEvent.
@Test
public void testIdleEvent() throws Exception {
ApacheCommonsFileTailingMessageProducer adapter = new ApacheCommonsFileTailingMessageProducer();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.afterPropertiesSet();
adapter.setTaskScheduler(taskScheduler);
CountDownLatch idleCountDownLatch = new CountDownLatch(1);
CountDownLatch fileExistCountDownLatch = new CountDownLatch(1);
adapter.setApplicationEventPublisher(event -> {
if (event instanceof FileTailingIdleEvent) {
idleCountDownLatch.countDown();
}
if (event instanceof FileTailingEvent) {
FileTailingEvent fileTailingEvent = (FileTailingEvent) event;
if (fileTailingEvent.getMessage().contains("File not found")) {
fileExistCountDownLatch.countDown();
}
}
});
File file = spy(new File(this.testDir, "foo"));
file.delete();
adapter.setFile(file);
adapter.setOutputChannel(new NullChannel());
adapter.setIdleEventInterval(10);
adapter.afterPropertiesSet();
adapter.start();
boolean noFile = fileExistCountDownLatch.await(10, TimeUnit.SECONDS);
assertTrue("file does not exist event did not emit ", noFile);
boolean noEvent = idleCountDownLatch.await(100, TimeUnit.MILLISECONDS);
assertFalse("event should not emit when no file exit", noEvent);
verify(file, atLeastOnce()).exists();
file.createNewFile();
boolean eventRaised = idleCountDownLatch.await(10, TimeUnit.SECONDS);
assertTrue("idle event did not emit", eventRaised);
adapter.stop();
file.delete();
}
Aggregations