use of com.adaptris.core.fs.enhanced.LastModifiedAscending in project interlok by adaptris.
the class FsConsumerCase method testFileSorter.
@Test
public void testFileSorter() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsConsumerImpl consumer = createConsumer(subdir);
assertEquals(NoSorting.class, consumer.getFileSorter().getClass());
consumer.setFileSorter(new LastModifiedAscending());
assertEquals(LastModifiedAscending.class, consumer.getFileSorter().getClass());
try {
consumer.setFileSorter(null);
fail();
} catch (Exception expected) {
}
}
use of com.adaptris.core.fs.enhanced.LastModifiedAscending in project interlok by adaptris.
the class FsMessageConsumerTest method testConsumeWithLastModifiedSort.
@Test
public void testConsumeWithLastModifiedSort() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
FsConsumer fs = createConsumer(subDir);
fs.setFileSorter(new LastModifiedAscending());
fs.setReacquireLockBetweenMessages(true);
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
int count = 5;
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File baseDir = new File(parentDir, subDir);
createFiles(baseDir, ".xml", count, 100);
start(sc);
waitForMessages(stub, count);
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
AdaptrisMessage first = stub.getMessages().get(0);
AdaptrisMessage last = stub.getMessages().get(count - 1);
String firstLastModified = first.getMetadataValue(CoreConstants.FILE_LAST_MODIFIED_KEY);
String lastLastModified = last.getMetadataValue(CoreConstants.FILE_LAST_MODIFIED_KEY);
assertTrue(Long.valueOf(firstLastModified).longValue() <= Long.valueOf(lastLastModified).longValue());
} finally {
stop(sc);
FileUtils.deleteQuietly(new File(parentDir, subDir));
}
}
Aggregations