Search in sources :

Example 1 with LargeFsConsumer

use of com.adaptris.core.lms.LargeFsConsumer in project interlok by adaptris.

the class FsMessageConsumerTest method testConsumeBug3304OversizedFiles.

@Test
public void testConsumeBug3304OversizedFiles() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    if (fs instanceof LargeFsConsumer) {
        // The large FS consumer should (by definition) handle large files
        return;
    }
    fs.setReacquireLockBetweenMessages(true);
    AtomicBoolean pollFired = new AtomicBoolean(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
        pollFired.set(true);
    }));
    fs.fsWorker = new SizeLimitedWorker();
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 1;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        File largeFile = File.createTempFile("3304", null, baseDir);
        RandomAccessFile raf = new RandomAccessFile(largeFile, "rw");
        // Set the size to be 10Mb.
        raf.setLength(0x00100000 * 10);
        LifecycleHelper.prepare(sc);
        LifecycleHelper.start(sc);
        waitForPollCallback(pollFired);
        assertTrue(stub.getMessages().size() == 0);
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
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) TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RandomAccessFile(java.io.RandomAccessFile) 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) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 CoreConstants (com.adaptris.core.CoreConstants)1 CoreException (com.adaptris.core.CoreException)1 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)1 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)1 AlphabeticAscending (com.adaptris.core.fs.enhanced.AlphabeticAscending)1 LastModifiedAscending (com.adaptris.core.fs.enhanced.LastModifiedAscending)1 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)1 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)1 LifecycleHelper (com.adaptris.core.util.LifecycleHelper)1 FsException (com.adaptris.fs.FsException)1 StandardWorker (com.adaptris.fs.StandardWorker)1 GuidGenerator (com.adaptris.util.GuidGenerator)1 TimeInterval (com.adaptris.util.TimeInterval)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1