Search in sources :

Example 16 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class LargeFsConsumerTest method testConsume_WithUnsupportedEncoder.

@Test
public void testConsume_WithUnsupportedEncoder() throws Exception {
    String subDir = GUID.safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    fs.setEncoder(new MimeEncoder());
    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);
        baseDir.mkdirs();
        createMimeFiles(baseDir, ".xml", count);
        start(sc);
        waitForMessages(stub, count);
        assertEquals(count, stub.getMessages().size());
        assertIgnoreSize(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } finally {
        stop(sc);
    // FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) MimeEncoder(com.adaptris.core.MimeEncoder) FsConsumer(com.adaptris.core.fs.FsConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) File(java.io.File) FsMessageConsumerTest(com.adaptris.core.fs.FsMessageConsumerTest) Test(org.junit.Test)

Example 17 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class LargeFsConsumerTest method testConsume_WithEncoder.

@Test
public void testConsume_WithEncoder() throws Exception {
    String subDir = GUID.safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    fs.setEncoder(new FileBackedMimeEncoder());
    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);
        baseDir.mkdirs();
        createMimeFiles(baseDir, ".xml", count);
        start(sc);
        waitForMessages(stub, count);
        assertEquals(count, stub.getMessages().size());
        assertIgnoreSize(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } finally {
        stop(sc);
    // FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) FsConsumer(com.adaptris.core.fs.FsConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) File(java.io.File) FsMessageConsumerTest(com.adaptris.core.fs.FsMessageConsumerTest) Test(org.junit.Test)

Example 18 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller 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)

Example 19 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class FsMessageConsumerTest method testConsumeWithQuietPeriod.

@Test
public void testConsumeWithQuietPeriod() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setQuietInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    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")));
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 20 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class FsMessageConsumerTest method testConsumeWithResetWipFile.

@Test
public void testConsumeWithResetWipFile() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(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);
        baseDir.mkdirs();
        createFiles(baseDir, ".xml.wip", count);
        LifecycleHelper.init(sc);
        Perl5FilenameFilter p5 = new Perl5FilenameFilter(".*\\.xml");
        assertTrue("Files renamed in " + baseDir.getCanonicalPath(), baseDir.listFiles((FilenameFilter) p5).length > 0);
    } finally {
        // sc.stop();
        LifecycleHelper.close(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Aggregations

FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 TimeInterval (com.adaptris.util.TimeInterval)38 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)36 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)32 Test (org.junit.Test)31 File (java.io.File)26 GuidGenerator (com.adaptris.util.GuidGenerator)24 FilenameFilter (java.io.FilenameFilter)23 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)23 RandomAccessFile (java.io.RandomAccessFile)20 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)14 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 IOException (java.io.IOException)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 CoreConstants (com.adaptris.core.CoreConstants)4 CoreException (com.adaptris.core.CoreException)4 PollerImp (com.adaptris.core.PollerImp)4 LifecycleHelper (com.adaptris.core.util.LifecycleHelper)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4