Search in sources :

Example 21 with FixedIntervalPoller

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

Example 22 with FixedIntervalPoller

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

the class FsMessageConsumerTest method testBug2233_ResetWipFilesOnInvalidDirectory.

@Test
public void testBug2233_ResetWipFilesOnInvalidDirectory() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    File dir = FsHelper.createFileReference(FsHelper.createUrlFromString(fs.getBaseDirectoryUrl(), true));
    // attempting to fix the timing issues.
    dir.getParentFile().mkdirs();
    // makes it a file, so it should be invalid now.
    dir.createNewFile();
    fs.setCreateDirs(false);
    fs.setResetWipFiles(true);
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    try {
        LifecycleHelper.init(sc);
    } catch (CoreException e) {
        log.warn(e.getMessage(), e);
        assertNull(e.getCause());
        assertTrue(e.getMessage().matches("^Failed to list files in.*Cannot reset WIP files"));
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 23 with FixedIntervalPoller

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

the class FsMessageConsumerTest method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    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) 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 24 with FixedIntervalPoller

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

the class FsMessageConsumerTest method testRedmine481_SubDirInConsumeDirectory.

@Test
public void testRedmine481_SubDirInConsumeDirectory() throws Exception {
    String consumeDir = new GuidGenerator().safeUUID();
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    String subDir = parentDir.getCanonicalPath() + "/" + consumeDir + "/" + new GuidGenerator().safeUUID();
    File subDirectory = new File(subDir);
    subDirectory.mkdirs();
    FsConsumer fs = createConsumer(consumeDir);
    fs.setReacquireLockBetweenMessages(true);
    AtomicBoolean pollFired = new AtomicBoolean(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
        pollFired.set(true);
    }));
    File wipDirectory = new File(subDir + fs.getWipSuffix());
    MockMessageListener stub = new MockMessageListener(0);
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    try {
        start(sc);
        waitForPollCallback(pollFired);
        assertEquals(true, subDirectory.exists());
        assertEquals(true, subDirectory.isDirectory());
        assertEquals(false, wipDirectory.exists());
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), consumeDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) RandomAccessFile(java.io.RandomAccessFile) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) LastModifiedAscending(com.adaptris.core.fs.enhanced.LastModifiedAscending) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) Assert.fail(org.junit.Assert.fail) GuidGenerator(com.adaptris.util.GuidGenerator) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) AlphabeticAscending(com.adaptris.core.fs.enhanced.AlphabeticAscending) LifecycleHelper(com.adaptris.core.util.LifecycleHelper) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CoreException(com.adaptris.core.CoreException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) CoreConstants(com.adaptris.core.CoreConstants) TimeInterval(com.adaptris.util.TimeInterval) FsException(com.adaptris.fs.FsException) StandardWorker(com.adaptris.fs.StandardWorker) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimeInterval(com.adaptris.util.TimeInterval) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 25 with FixedIntervalPoller

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

the class FsMessageConsumerTest method testConsumeFailInitialRename.

@Test
public void testConsumeFailInitialRename() 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);
        List<File> createdFiles = createFiles(baseDir, ".xml", count);
        for (File file : createdFiles) {
            File wip = new File(file.getAbsolutePath() + ".wip");
            wip.createNewFile();
        }
        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)

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