Search in sources :

Example 1 with Perl5FilenameFilter

use of org.apache.oro.io.Perl5FilenameFilter in project interlok by adaptris.

the class FsMessageConsumerTest method testConsumeImmediateEventPoller.

@Test
public void testConsumeImmediateEventPoller() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FsImmediateEventPoller());
    fs.setQuietInterval(new TimeInterval(500L, "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);
        Thread.sleep(1000);
        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) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 2 with Perl5FilenameFilter

use of org.apache.oro.io.Perl5FilenameFilter in project interlok by adaptris.

the class FsMessageConsumerTest method testBug1675ConsumeWithSpacesInDir.

@Test
public void testBug1675ConsumeWithSpacesInDir() throws Exception {
    String uniqueName = new GuidGenerator().safeUUID();
    String subDir = uniqueName + "Directory WithSpaces";
    String subDirEncoded = uniqueName + "Directory%20WithSpaces";
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDirEncoded);
    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")));
    } catch (Exception e) {
        log.debug(e.getMessage(), e);
    } 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) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) FsException(com.adaptris.fs.FsException) Test(org.junit.Test)

Example 3 with Perl5FilenameFilter

use of org.apache.oro.io.Perl5FilenameFilter in project interlok by adaptris.

the class FsMessageConsumerTest method testBug2100_OriginalNameContainsWip.

@Test
public void testBug2100_OriginalNameContainsWip() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    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")));
        for (AdaptrisMessage msg : stub.getMessages()) {
            assertFalse("original name should not contain '.wip'", msg.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY).endsWith(".wip"));
        }
    } 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) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) 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 4 with Perl5FilenameFilter

use of org.apache.oro.io.Perl5FilenameFilter in project interlok by adaptris.

the class FsMessageConsumerTest method testConsumeIgnoresWip.

@Test
public void testConsumeIgnoresWip() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener();
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);
    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", count);
        createFiles(baseDir, ".xml.wip", count);
        start(sc);
        waitForMessages(stub, count);
        Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.wip");
        assertEquals(count, baseDir.listFiles((FilenameFilter) wip).length);
        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 5 with Perl5FilenameFilter

use of org.apache.oro.io.Perl5FilenameFilter in project interlok by adaptris.

the class NonDeletingFsConsumerTest method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithFilter");
    fs.setFilterExpression(".*\\.xml");
    fs.setFileFilterImp(Perl5FilenameFilter.class.getName());
    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);
        createFiles(baseDir, ".tmp", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.tmp");
        assertEquals("TMP Files remain", count, baseDir.listFiles((FilenameFilter) wip).length);
        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) 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

StandaloneConsumer (com.adaptris.core.StandaloneConsumer)21 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)21 TimeInterval (com.adaptris.util.TimeInterval)21 File (java.io.File)21 FilenameFilter (java.io.FilenameFilter)21 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)21 Test (org.junit.Test)21 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)20 GuidGenerator (com.adaptris.util.GuidGenerator)18 RandomAccessFile (java.io.RandomAccessFile)17 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)11 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 IOException (java.io.IOException)5 FsConsumer (com.adaptris.core.fs.FsConsumer)3 FsMessageConsumerTest (com.adaptris.core.fs.FsMessageConsumerTest)3 CoreConstants (com.adaptris.core.CoreConstants)1 CoreException (com.adaptris.core.CoreException)1 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)1 MimeEncoder (com.adaptris.core.MimeEncoder)1 PollerImp (com.adaptris.core.PollerImp)1