Search in sources :

Example 61 with StandaloneConsumer

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

the class NonDeletingFsConsumerTest 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);
    NonDeletingFsConsumer fs = createConsumer(subDirEncoded, "testBug1675ConsumeWithSpacesInDir");
    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);
        throw 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) 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) Test(org.junit.Test)

Example 62 with StandaloneConsumer

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

the class NonDeletingFsConsumerTest 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));
    File subDirectory = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY) + "/" + consumeDir + "/" + new GuidGenerator().safeUUID(), true));
    subDirectory.mkdirs();
    NonDeletingFsConsumer fs = createConsumer(consumeDir, "testRedmine481_SubDirInConsumeDirectory");
    fs.setReacquireLockBetweenMessages(true);
    AtomicBoolean pollFired = new AtomicBoolean(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
        pollFired.set(true);
    }));
    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());
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, consumeDir));
    }
}
Also used : StandaloneConsumer(com.adaptris.core.StandaloneConsumer) FilenameFilter(java.io.FilenameFilter) RandomAccessFile(java.io.RandomAccessFile) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PollerImp(com.adaptris.core.PollerImp) ArrayList(java.util.ArrayList) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) GuidGenerator(com.adaptris.util.GuidGenerator) PrintStream(java.io.PrintStream) LifecycleHelper(com.adaptris.core.util.LifecycleHelper) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TempFileUtils(com.adaptris.core.stubs.TempFileUtils) List(java.util.List) CoreConstants(com.adaptris.core.CoreConstants) Assert.assertFalse(org.junit.Assert.assertFalse) TimeInterval(com.adaptris.util.TimeInterval) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimeInterval(com.adaptris.util.TimeInterval) 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 63 with StandaloneConsumer

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

the class NonDeletingFsConsumerTest method testConsumeWithQuietPeriod.

@Test
public void testConsumeWithQuietPeriod() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithQuietPeriod");
    fs.setQuietInterval(new TimeInterval(300L, TimeUnit.MILLISECONDS));
    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) 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 64 with StandaloneConsumer

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

the class NonDeletingFsConsumerTest method testHasChanged_LastModified.

@Test
public void testHasChanged_LastModified() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
    File f = createFile(TempFileUtils.createTrackedFile(getName(), "", fs), PANGRAM_1);
    ProcessedItem item = new ProcessedItem(f.getAbsolutePath(), 0, f.length());
    ProcessedItemCache cache = new InlineItemCache();
    fs.setPoller(new Never());
    fs.setProcessedItemCache(cache);
    StandaloneConsumer consumer = new StandaloneConsumer(fs);
    try {
        start(consumer);
        cache.update(item);
        ProcessedItem changed = new ProcessedItem(f.getAbsolutePath(), f.lastModified(), f.length());
        assertTrue(fs.hasChanged(changed));
        cache.update(changed);
        assertFalse(fs.hasChanged(changed));
    } finally {
        stop(consumer);
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 65 with StandaloneConsumer

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

the class MovingDeletingFsConsumerTest method testConsume.

@Test
public void testConsume() throws Exception {
    final File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    final String subDir = new GuidGenerator().safeUUID();
    final File baseDir = new File(parentDir, subDir);
    final File procDir = new File(parentDir, "proc");
    final MockMessageListener stub = new MockMessageListener(10);
    final MovingNonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    fs.setProcessedPath(procDir.getAbsolutePath());
    final StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    final int count = 10;
    List<File> files = null;
    try {
        LifecycleHelper.init(sc);
        files = createFiles(baseDir, ".xml", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } catch (final Exception e) {
        log.warn(e.getMessage(), e);
        fail();
    } finally {
        stop(sc);
        if (files != null) {
            for (final File f : files) {
                boolean found = false;
                for (final String n : procDir.list()) {
                    if (f.getName().equals(n)) {
                        found = true;
                    }
                }
                if (!found) {
                    fail("Couldn't find file " + f.getName() + " in processed directory");
                }
            }
        }
        FileUtils.deleteQuietly(baseDir);
        FileUtils.deleteQuietly(procDir);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) IOException(java.io.IOException) FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Aggregations

StandaloneConsumer (com.adaptris.core.StandaloneConsumer)188 Test (org.junit.Test)164 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)160 StandaloneProducer (com.adaptris.core.StandaloneProducer)91 TimeInterval (com.adaptris.util.TimeInterval)49 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)37 File (java.io.File)31 GuidGenerator (com.adaptris.util.GuidGenerator)30 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)30 PtpConsumer (com.adaptris.core.jms.PtpConsumer)24 FilenameFilter (java.io.FilenameFilter)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 PtpProducer (com.adaptris.core.jms.PtpProducer)23 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)22 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)17 CoreException (com.adaptris.core.CoreException)16 PasProducer (com.adaptris.core.jms.PasProducer)15 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 PasConsumer (com.adaptris.core.jms.PasConsumer)14