Search in sources :

Example 1 with AlphabeticAscending

use of com.adaptris.core.fs.enhanced.AlphabeticAscending in project interlok by adaptris.

the class FsMessageConsumerTest method testConsumeWithAlphabeticSort.

@Test
public void testConsumeWithAlphabeticSort() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setFileSorter(new AlphabeticAscending());
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        createFiles(baseDir, ".xml", count);
        LifecycleHelper.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(9);
        String firstFilename = first.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY);
        String lastFilename = last.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY);
        assertTrue(firstFilename.compareTo(lastFilename) < 0);
    } 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) AlphabeticAscending(com.adaptris.core.fs.enhanced.AlphabeticAscending) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)1 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)1 AlphabeticAscending (com.adaptris.core.fs.enhanced.AlphabeticAscending)1 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)1 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)1 GuidGenerator (com.adaptris.util.GuidGenerator)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 Test (org.junit.Test)1