Search in sources :

Example 1 with LastModifiedAscending

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) {
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) CoreException(com.adaptris.core.CoreException) LastModifiedAscending(com.adaptris.core.fs.enhanced.LastModifiedAscending) Test(org.junit.Test)

Example 2 with LastModifiedAscending

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));
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LastModifiedAscending(com.adaptris.core.fs.enhanced.LastModifiedAscending) Test(org.junit.Test)

Aggregations

LastModifiedAscending (com.adaptris.core.fs.enhanced.LastModifiedAscending)2 GuidGenerator (com.adaptris.util.GuidGenerator)2 Test (org.junit.Test)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 CoreException (com.adaptris.core.CoreException)1 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)1 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)1 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)1 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)1 TimeInterval (com.adaptris.util.TimeInterval)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 RandomAccessFile (java.io.RandomAccessFile)1 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)1